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

Function TestReflectionMethodCalls

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

Source from the content-addressed store, hash-verified

187}
188
189func TestReflectionMethodCalls(t *testing.T) {
190 rt := NewRuntime()
191 defer rt.Close()
192 ctx := rt.NewContext()
193 defer ctx.Close()
194
195 constructor, _ := ctx.BindClass(&Person{})
196 require.False(t, constructor.IsException())
197
198 ctx.Globals().Set("Person", constructor)
199
200 // Test method calls and private method accessibility
201 result := ctx.Eval(`
202 let person = new Person();
203 person.firstName = "Alice";
204 person.lastName = "Johnson";
205 person.age = 25;
206 person.isActive = true;
207
208 [
209 person.GetFullName(),
210 person.IncrementAge(5),
211 person.age,
212 typeof person.getSecret // Should be undefined (private method)
213 ];
214 `)
215 defer result.Free()
216
217 require.False(t, result.IsException())
218
219 require.Equal(t, "Alice Johnson", result.GetIdx(0).ToString()) // Changed: String() → ToString()
220 require.Equal(t, int32(30), result.GetIdx(1).ToInt32()) // Changed: Int32() → ToInt32()
221 require.Equal(t, int32(30), result.GetIdx(2).ToInt32()) // Changed: Int32() → ToInt32()
222 require.Equal(t, "undefined", result.GetIdx(3).ToString()) // Changed: String() → ToString()
223}
224
225func TestReflectionMultipleReturnValues(t *testing.T) {
226 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
IsExceptionMethod · 0.80
SetMethod · 0.80
EqualMethod · 0.80
GetIdxMethod · 0.80
ToInt32Method · 0.80

Tested by

no test coverage detected