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

Function TestValueInstanceof

value_test.go:1360–1401  ·  view source on GitHub ↗

TestValueInstanceof tests instanceof operations

(t *testing.T)

Source from the content-addressed store, hash-verified

1358
1359// TestValueInstanceof tests instanceof operations
1360func TestValueInstanceof(t *testing.T) {
1361 useStableOwnerHooksForLegacySubtests(t)
1362
1363 rt := NewRuntime()
1364 defer rt.Close()
1365 ctx := rt.NewContext()
1366 defer ctx.Close()
1367
1368 // Test valid instanceof cases - FIXED: removed error handling
1369 arr := ctx.Eval(`[1, 2, 3]`)
1370 defer arr.Free()
1371 require.False(t, arr.IsException()) // Check for exceptions instead of error
1372 require.True(t, arr.GlobalInstanceof("Array"))
1373 require.True(t, arr.GlobalInstanceof("Object"))
1374
1375 obj := ctx.Eval(`({})`)
1376 defer obj.Free()
1377 require.False(t, obj.IsException()) // Check for exceptions instead of error
1378 require.True(t, obj.GlobalInstanceof("Object"))
1379 require.False(t, obj.GlobalInstanceof("Array"))
1380
1381 // Test false cases to ensure coverage - Updated to use New* methods
1382 testVals := []struct {
1383 name string
1384 createVal func() *Value // Changed to return pointer
1385 }{
1386 {"String", func() *Value { return ctx.NewString("test") }},
1387 {"Number", func() *Value { return ctx.NewInt32(42) }},
1388 {"Null", func() *Value { return ctx.NewNull() }},
1389 {"Undefined", func() *Value { return ctx.NewUndefined() }},
1390 }
1391
1392 for _, tv := range testVals {
1393 t.Run(tv.name, func(t *testing.T) {
1394 val := tv.createVal()
1395 defer val.Free()
1396 require.False(t, val.GlobalInstanceof("Array"))
1397 require.False(t, val.GlobalInstanceof("NonExistent"))
1398 require.False(t, val.GlobalInstanceof(""))
1399 })
1400 }
1401}
1402
1403// TestValueSpecialTypes tests special types and edge cases
1404func TestValueSpecialTypes(t *testing.T) {

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
EvalMethod · 0.95
NewStringMethod · 0.95
NewInt32Method · 0.95
NewNullMethod · 0.95
NewUndefinedMethod · 0.95
NewRuntimeFunction · 0.85
IsExceptionMethod · 0.80
GlobalInstanceofMethod · 0.80

Tested by

no test coverage detected