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

Function TestStaticProperties

class_test.go:442–487  ·  view source on GitHub ↗

NEW: TestStaticProperties tests static data property functionality

(t *testing.T)

Source from the content-addressed store, hash-verified

440
441// NEW: TestStaticProperties tests static data property functionality
442func 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
490func TestPropertyFlags(t *testing.T) {

Callers

nothing calls this directly

Calls 14

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