NEW: TestProperties tests data property functionality
(t *testing.T)
| 391 | |
| 392 | // NEW: TestProperties tests data property functionality |
| 393 | func TestProperties(t *testing.T) { |
| 394 | rt := NewRuntime() |
| 395 | defer rt.Close() |
| 396 | |
| 397 | context := rt.NewContext() |
| 398 | defer context.Close() |
| 399 | |
| 400 | // Create and register Point class |
| 401 | pointConstructor, _ := createPointClass(context) |
| 402 | if pointConstructor.IsException() { |
| 403 | defer pointConstructor.Free() |
| 404 | err := context.Exception() |
| 405 | t.Fatalf("Failed to create Point class: %v", err) |
| 406 | } |
| 407 | |
| 408 | // Register Point class globally |
| 409 | context.Globals().Set("Point", pointConstructor) |
| 410 | |
| 411 | // Test instance properties |
| 412 | result := context.Eval(` |
| 413 | let p = new Point(1, 2); |
| 414 | [ |
| 415 | p.version, // Instance property |
| 416 | p.readOnlyFlag, // Read-only instance property |
| 417 | typeof p.version, // Should be string |
| 418 | typeof p.readOnlyFlag // Should be boolean |
| 419 | ]; |
| 420 | `) |
| 421 | defer result.Free() |
| 422 | if result.IsException() { |
| 423 | err := context.Exception() |
| 424 | t.Fatalf("Failed to evaluate instance properties: %v", err) |
| 425 | } |
| 426 | |
| 427 | if result.GetIdx(0).ToString() != "1.0.0" { // Updated: Use ToString() |
| 428 | t.Errorf("Expected version '1.0.0', got '%s'", result.GetIdx(0).ToString()) |
| 429 | } |
| 430 | if !result.GetIdx(1).ToBool() { // Updated: Use ToBool() |
| 431 | t.Errorf("Expected readOnlyFlag true, got %t", result.GetIdx(1).ToBool()) |
| 432 | } |
| 433 | if result.GetIdx(2).ToString() != "string" { // Updated: Use ToString() |
| 434 | t.Errorf("Expected version type 'string', got '%s'", result.GetIdx(2).ToString()) |
| 435 | } |
| 436 | if result.GetIdx(3).ToString() != "boolean" { // Updated: Use ToString() |
| 437 | t.Errorf("Expected readOnlyFlag type 'boolean', got '%s'", result.GetIdx(3).ToString()) |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | // NEW: TestStaticProperties tests static data property functionality |
| 442 | func TestStaticProperties(t *testing.T) { |
nothing calls this directly
no test coverage detected