NEW: TestStaticProperties tests static data property functionality
(t *testing.T)
| 440 | |
| 441 | // NEW: TestStaticProperties tests static data property functionality |
| 442 | func TestStaticProperties(t *testing.T) { |
| 443 | rt := NewRuntime() |
| 444 | defer rt.Close() |
| 445 | |
| 446 | context := rt.NewContext() |
| 447 | defer context.Close() |
| 448 | |
| 449 | // Create and register Point class |
| 450 | pointConstructor, _ := createPointClass(context) |
| 451 | if pointConstructor.IsException() { |
| 452 | defer pointConstructor.Free() |
| 453 | err := context.Exception() |
| 454 | t.Fatalf("Failed to create Point class: %v", err) |
| 455 | } |
| 456 | |
| 457 | // Register Point class globally |
| 458 | context.Globals().Set("Point", pointConstructor) |
| 459 | |
| 460 | // Test static properties |
| 461 | result := context.Eval(` |
| 462 | [ |
| 463 | Point.PI_CONST, // Static property (default flags) |
| 464 | Point.AUTHOR, // Enumerable-only static property |
| 465 | typeof Point.PI_CONST, |
| 466 | typeof Point.AUTHOR |
| 467 | ]; |
| 468 | `) |
| 469 | defer result.Free() |
| 470 | if result.IsException() { |
| 471 | err := context.Exception() |
| 472 | t.Fatalf("Failed to evaluate static properties: %v", err) |
| 473 | } |
| 474 | |
| 475 | if math.Abs(result.GetIdx(0).ToFloat64()-math.Pi) > 0.001 { // Updated: Use ToFloat64() |
| 476 | t.Errorf("Expected PI_CONST %f, got %f", math.Pi, result.GetIdx(0).ToFloat64()) |
| 477 | } |
| 478 | if result.GetIdx(1).ToString() != "QuickJS-Go" { // Updated: Use ToString() |
| 479 | t.Errorf("Expected AUTHOR 'QuickJS-Go', got '%s'", result.GetIdx(1).ToString()) |
| 480 | } |
| 481 | if result.GetIdx(2).ToString() != "number" { // Updated: Use ToString() |
| 482 | t.Errorf("Expected PI_CONST type 'number', got '%s'", result.GetIdx(2).ToString()) |
| 483 | } |
| 484 | if result.GetIdx(3).ToString() != "string" { // Updated: Use ToString() |
| 485 | t.Errorf("Expected AUTHOR type 'string', got '%s'", result.GetIdx(3).ToString()) |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | // NEW: TestPropertyFlags tests property descriptor flags |
| 490 | func TestPropertyFlags(t *testing.T) { |
nothing calls this directly
no test coverage detected