TestStaticMethods tests static method functionality
(t *testing.T)
| 321 | |
| 322 | // TestStaticMethods tests static method functionality |
| 323 | func TestStaticMethods(t *testing.T) { |
| 324 | rt := NewRuntime() |
| 325 | defer rt.Close() |
| 326 | |
| 327 | context := rt.NewContext() |
| 328 | defer context.Close() |
| 329 | |
| 330 | // Create and register Point class |
| 331 | pointConstructor, _ := createPointClass(context) |
| 332 | if pointConstructor.IsException() { |
| 333 | defer pointConstructor.Free() |
| 334 | err := context.Exception() |
| 335 | t.Fatalf("Failed to create Point class: %v", err) |
| 336 | } |
| 337 | |
| 338 | // Register Point class globally |
| 339 | // Note: Globals will manage the memory automatically |
| 340 | context.Globals().Set("Point", pointConstructor) |
| 341 | |
| 342 | // Test static method |
| 343 | result := context.Eval(` |
| 344 | let p1 = Point.zero(); |
| 345 | [p1.x, p1.y]; |
| 346 | `) |
| 347 | defer result.Free() |
| 348 | if result.IsException() { |
| 349 | err := context.Exception() |
| 350 | t.Fatalf("Failed to evaluate static method: %v", err) |
| 351 | } |
| 352 | |
| 353 | if result.GetIdx(0).ToFloat64() != 0.0 || result.GetIdx(1).ToFloat64() != 0.0 { // Updated: Use ToFloat64() |
| 354 | t.Errorf("Expected [0, 0], got [%f, %f]", |
| 355 | result.GetIdx(0).ToFloat64(), result.GetIdx(1).ToFloat64()) |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // TestStaticAccessors tests static accessor functionality |
| 360 | func TestStaticAccessors(t *testing.T) { |
nothing calls this directly
no test coverage detected