TestValueBasics tests basic value creation and type checking
(t *testing.T)
| 15 | |
| 16 | // TestValueBasics tests basic value creation and type checking |
| 17 | func TestValueBasics(t *testing.T) { |
| 18 | useStableOwnerHooksForLegacySubtests(t) |
| 19 | |
| 20 | rt := NewRuntime() |
| 21 | defer rt.Close() |
| 22 | ctx := rt.NewContext() |
| 23 | defer ctx.Close() |
| 24 | |
| 25 | // Test basic type creation and checking - Updated to use New* methods |
| 26 | testCases := []struct { |
| 27 | name string |
| 28 | createVal func() *Value // Changed to return pointer |
| 29 | checkFunc func(*Value) bool // Changed parameter to pointer |
| 30 | }{ |
| 31 | {"Number", func() *Value { return ctx.NewInt32(42) }, func(v *Value) bool { return v.IsNumber() }}, |
| 32 | {"String", func() *Value { return ctx.NewString("test") }, func(v *Value) bool { return v.IsString() }}, |
| 33 | {"Boolean", func() *Value { return ctx.NewBool(true) }, func(v *Value) bool { return v.IsBool() }}, |
| 34 | {"Null", func() *Value { return ctx.NewNull() }, func(v *Value) bool { return v.IsNull() }}, |
| 35 | {"Undefined", func() *Value { return ctx.NewUndefined() }, func(v *Value) bool { return v.IsUndefined() }}, |
| 36 | {"Uninitialized", func() *Value { return ctx.NewUninitialized() }, func(v *Value) bool { return v.IsUninitialized() }}, |
| 37 | {"Object", func() *Value { return ctx.NewObject() }, func(v *Value) bool { return v.IsObject() }}, |
| 38 | {"BigInt", func() *Value { return ctx.NewBigInt64(123456789) }, func(v *Value) bool { return v.IsBigInt() }}, |
| 39 | } |
| 40 | |
| 41 | for _, tc := range testCases { |
| 42 | t.Run(tc.name, func(t *testing.T) { |
| 43 | val := tc.createVal() |
| 44 | defer val.Free() |
| 45 | require.True(t, tc.checkFunc(val)) |
| 46 | require.Equal(t, ctx, val.Context()) // Test Context() method |
| 47 | }) |
| 48 | } |
| 49 | |
| 50 | // Test JavaScript created values - FIXED: removed error handling |
| 51 | arr := ctx.Eval(`[1, 2, 3]`) |
| 52 | defer arr.Free() |
| 53 | require.False(t, arr.IsException()) // Check for exceptions instead of error |
| 54 | require.True(t, arr.IsArray()) |
| 55 | require.True(t, arr.IsObject()) // Arrays are objects |
| 56 | |
| 57 | sym := ctx.Eval(`Symbol('test')`) |
| 58 | defer sym.Free() |
| 59 | require.False(t, sym.IsException()) // Check for exceptions instead of error |
| 60 | require.True(t, sym.IsSymbol()) |
| 61 | } |
| 62 | |
| 63 | func TestValueComparisonAPIs(t *testing.T) { |
| 64 | useStableOwnerHooksForLegacySubtests(t) |
nothing calls this directly
no test coverage detected