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

Function TestReflectionWithMethodPrefix

class_reflect_test.go:366–398  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

364}
365
366func TestReflectionWithMethodPrefix(t *testing.T) {
367 rt := NewRuntime()
368 defer rt.Close()
369 ctx := rt.NewContext()
370 defer ctx.Close()
371
372 // Test method prefix filtering
373 builder, err := ctx.BindClassBuilder(&FilteredMethods{}, WithMethodPrefix("Get"))
374 require.NoError(t, err)
375
376 constructor, _ := builder.Build(ctx)
377 require.False(t, constructor.IsException())
378
379 ctx.Globals().Set("Filtered", constructor)
380
381 result := ctx.Eval(`
382 let obj = new Filtered();
383 [
384 typeof obj.GetData, // Should exist
385 typeof obj.GetInfo, // Should exist
386 typeof obj.SetData, // Should be undefined (no Get prefix)
387 typeof obj.ProcessData // Should be undefined (no Get prefix)
388 ];
389 `)
390 defer result.Free()
391
392 require.False(t, result.IsException())
393
394 require.Equal(t, "function", result.GetIdx(0).ToString()) // Changed: String() → ToString()
395 require.Equal(t, "function", result.GetIdx(1).ToString()) // Changed: String() → ToString()
396 require.Equal(t, "undefined", result.GetIdx(2).ToString()) // Changed: String() → ToString()
397 require.Equal(t, "undefined", result.GetIdx(3).ToString()) // Changed: String() → ToString()
398}
399
400func TestReflectionWithIgnoredMethods(t *testing.T) {
401 rt := NewRuntime()

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
BindClassBuilderMethod · 0.95
GlobalsMethod · 0.95
EvalMethod · 0.95
NewRuntimeFunction · 0.85
WithMethodPrefixFunction · 0.85
IsExceptionMethod · 0.80
SetMethod · 0.80
EqualMethod · 0.80
GetIdxMethod · 0.80

Tested by

no test coverage detected