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

Function TestReflectionWithIgnoredFields

class_reflect_test.go:335–364  ·  view source on GitHub ↗

============================================================================= REFLECTION OPTIONS TESTS =============================================================================

(t *testing.T)

Source from the content-addressed store, hash-verified

333// =============================================================================
334
335func TestReflectionWithIgnoredFields(t *testing.T) {
336 rt := NewRuntime()
337 defer rt.Close()
338 ctx := rt.NewContext()
339 defer ctx.Close()
340
341 // Test WithIgnoredFields option
342 constructor, _ := ctx.BindClass(&ReflectionTestStruct{}, WithIgnoredFields("IgnoredOne", "IgnoredTwo"))
343 require.False(t, constructor.IsException())
344
345 ctx.Globals().Set("ReflectionTestStruct", constructor)
346
347 result := ctx.Eval(`
348 let obj = new ReflectionTestStruct();
349 [
350 typeof obj.field1, // Should exist
351 typeof obj.field2, // Should exist
352 typeof obj.ignoredOne, // Should be undefined (ignored)
353 typeof obj.ignoredTwo // Should be undefined (ignored)
354 ];
355 `)
356 defer result.Free()
357
358 require.False(t, result.IsException())
359
360 require.Equal(t, "string", result.GetIdx(0).ToString()) // Changed: String() → ToString()
361 require.Equal(t, "string", result.GetIdx(1).ToString()) // Changed: String() → ToString()
362 require.Equal(t, "undefined", result.GetIdx(2).ToString()) // Changed: String() → ToString()
363 require.Equal(t, "undefined", result.GetIdx(3).ToString()) // Changed: String() → ToString()
364}
365
366func TestReflectionWithMethodPrefix(t *testing.T) {
367 rt := NewRuntime()

Callers

nothing calls this directly

Calls 14

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
BindClassMethod · 0.95
GlobalsMethod · 0.95
EvalMethod · 0.95
NewRuntimeFunction · 0.85
WithIgnoredFieldsFunction · 0.85
IsExceptionMethod · 0.80
SetMethod · 0.80
EqualMethod · 0.80
GetIdxMethod · 0.80

Tested by

no test coverage detected