TestStaticAccessors tests static accessor functionality
(t *testing.T)
| 358 | |
| 359 | // TestStaticAccessors tests static accessor functionality |
| 360 | func TestStaticAccessors(t *testing.T) { |
| 361 | rt := NewRuntime() |
| 362 | defer rt.Close() |
| 363 | |
| 364 | context := rt.NewContext() |
| 365 | defer context.Close() |
| 366 | |
| 367 | // Create and register Point class |
| 368 | pointConstructor, _ := createPointClass(context) |
| 369 | if pointConstructor.IsException() { |
| 370 | defer pointConstructor.Free() |
| 371 | err := context.Exception() |
| 372 | t.Fatalf("Failed to create Point class: %v", err) |
| 373 | } |
| 374 | |
| 375 | // Register Point class globally |
| 376 | // Note: Globals will manage the memory automatically |
| 377 | context.Globals().Set("Point", pointConstructor) |
| 378 | |
| 379 | // Test static read-only accessor |
| 380 | result := context.Eval(`Point.PI`) |
| 381 | defer result.Free() |
| 382 | if result.IsException() { |
| 383 | err := context.Exception() |
| 384 | t.Fatalf("Failed to evaluate static accessor: %v", err) |
| 385 | } |
| 386 | |
| 387 | if math.Abs(result.ToFloat64()-math.Pi) > 0.001 { // Updated: Use ToFloat64() |
| 388 | t.Errorf("Expected PI %f, got %f", math.Pi, result.ToFloat64()) |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | // NEW: TestProperties tests data property functionality |
| 393 | func TestProperties(t *testing.T) { |
nothing calls this directly
no test coverage detected