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

Function TestValueCallConstructorComprehensive

value_test.go:2178–2392  ·  view source on GitHub ↗

TestValueCallConstructorComprehensive tests comprehensive CallConstructor scenarios NEW TEST: Comprehensive coverage for CallConstructor API

(t *testing.T)

Source from the content-addressed store, hash-verified

2176// TestValueCallConstructorComprehensive tests comprehensive CallConstructor scenarios
2177// NEW TEST: Comprehensive coverage for CallConstructor API
2178func TestValueCallConstructorComprehensive(t *testing.T) {
2179 useStableOwnerHooksForLegacySubtests(t)
2180
2181 rt := NewRuntime()
2182 defer rt.Close()
2183 ctx := rt.NewContext()
2184 defer ctx.Close()
2185
2186 // Test Case 1: CallConstructor with different argument counts - FIXED: removed error handling
2187 t.Run("CallConstructor_ArgumentCounts", func(t *testing.T) {
2188 constructor := ctx.Eval(`
2189 function TestClass() {
2190 this.argCount = arguments.length;
2191 this.args = Array.from(arguments);
2192 }
2193 TestClass;
2194 `)
2195 defer constructor.Free()
2196 require.False(t, constructor.IsException()) // Check for exceptions instead of error
2197
2198 // Test with no arguments
2199 instance0 := constructor.CallConstructor()
2200 defer instance0.Free()
2201 require.False(t, instance0.IsException())
2202
2203 argCount0 := instance0.Get("argCount")
2204 defer argCount0.Free()
2205 require.Equal(t, int32(0), argCount0.ToInt32())
2206
2207 // Test with one argument
2208 instance1 := constructor.CallConstructor(ctx.NewString("arg1"))
2209 defer instance1.Free()
2210 require.False(t, instance1.IsException())
2211
2212 argCount1 := instance1.Get("argCount")
2213 defer argCount1.Free()
2214 require.Equal(t, int32(1), argCount1.ToInt32())
2215
2216 // Test with multiple arguments
2217 instance3 := constructor.CallConstructor(
2218 ctx.NewString("arg1"),
2219 ctx.NewInt32(42),
2220 ctx.NewBool(true),
2221 )
2222 defer instance3.Free()
2223 require.False(t, instance3.IsException())
2224
2225 argCount3 := instance3.Get("argCount")
2226 defer argCount3.Free()
2227 require.Equal(t, int32(3), argCount3.ToInt32())
2228 })
2229
2230 // Test Case 2: CallConstructor with inheritance chain - FIXED: removed error handling
2231 t.Run("CallConstructor_InheritanceChain", func(t *testing.T) {
2232 // Set up inheritance chain
2233 ret := ctx.Eval(`
2234 function Base(value) {
2235 this.baseValue = value;

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
EvalMethod · 0.95
NewStringMethod · 0.95
NewInt32Method · 0.95
NewBoolMethod · 0.95
NewRuntimeFunction · 0.85
IsExceptionMethod · 0.80
CallConstructorMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected