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

Function TestReflectionEdgeCases

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

Source from the content-addressed store, hash-verified

871}
872
873func TestReflectionEdgeCases(t *testing.T) {
874 newTestContext := func(t *testing.T) *Context {
875 rt := NewRuntime()
876 ctx := rt.NewContext()
877 require.NotNil(t, ctx)
878 t.Cleanup(func() {
879 ctx.Close()
880 rt.Close()
881 })
882 return ctx
883 }
884
885 // Test empty struct
886 t.Run("EmptyStruct", func(t *testing.T) {
887 ctx := newTestContext(t)
888 constructor, _ := ctx.BindClass(&EmptyStruct{})
889 require.False(t, constructor.IsException())
890
891 ctx.Globals().Set("EmptyStruct", constructor)
892
893 result := ctx.Eval(`
894 (function() {
895 let obj = new EmptyStruct();
896 return typeof obj;
897 })();
898 `)
899 defer result.Free()
900 require.False(t, result.IsException())
901 require.Equal(t, "object", result.ToString()) // Changed: String() → ToString()
902 })
903
904 // Test struct with only private fields
905 t.Run("OnlyPrivateFields", func(t *testing.T) {
906 ctx := newTestContext(t)
907 constructor, _ := ctx.BindClass(&PrivateStruct{})
908 require.False(t, constructor.IsException())
909
910 ctx.Globals().Set("PrivateStruct", constructor)
911
912 result := ctx.Eval(`
913 (function() {
914 let obj = new PrivateStruct();
915 return Object.keys(obj).length; // Should have no enumerable accessors
916 })();
917 `)
918 defer result.Free()
919 require.False(t, result.IsException())
920 require.Equal(t, int32(0), result.ToInt32()) // Changed: Int32() → ToInt32()
921 })
922
923 // Test method with zero return values
924 t.Run("VoidMethod", func(t *testing.T) {
925 ctx := newTestContext(t)
926 constructor, _ := ctx.BindClass(&VoidStruct{})
927 require.False(t, constructor.IsException())
928
929 ctx.Globals().Set("VoidStruct", constructor)
930

Callers

nothing calls this directly

Calls 13

NewContextMethod · 0.95
CloseMethod · 0.95
CloseMethod · 0.95
BindClassMethod · 0.95
GlobalsMethod · 0.95
EvalMethod · 0.95
NewRuntimeFunction · 0.85
IsExceptionMethod · 0.80
SetMethod · 0.80
EqualMethod · 0.80
ToInt32Method · 0.80
FreeMethod · 0.45

Tested by

no test coverage detected