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

Function TestStaticAccessors

class_test.go:360–390  ·  view source on GitHub ↗

TestStaticAccessors tests static accessor functionality

(t *testing.T)

Source from the content-addressed store, hash-verified

358
359// TestStaticAccessors tests static accessor functionality
360func 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
393func TestProperties(t *testing.T) {

Callers

nothing calls this directly

Calls 12

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
FreeMethod · 0.45

Tested by

no test coverage detected