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

Function TestProperties

class_test.go:393–439  ·  view source on GitHub ↗

NEW: TestProperties tests data property functionality

(t *testing.T)

Source from the content-addressed store, hash-verified

391
392// NEW: TestProperties tests data property functionality
393func 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
442func TestStaticProperties(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
GetIdxMethod · 0.80
ToBoolMethod · 0.80

Tested by

no test coverage detected