MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestStaticMethods

Function TestStaticMethods

class_test.go:323–357  ·  view source on GitHub ↗

TestStaticMethods tests static method functionality

(t *testing.T)

Source from the content-addressed store, hash-verified

321
322// TestStaticMethods tests static method functionality
323func 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
360func TestStaticAccessors(t *testing.T) {

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
ExceptionMethod · 0.95
GlobalsMethod · 0.95
EvalMethod · 0.95
NewRuntimeFunction · 0.85
createPointClassFunction · 0.85
IsExceptionMethod · 0.80
SetMethod · 0.80
ToFloat64Method · 0.80
GetIdxMethod · 0.80

Tested by

no test coverage detected