TestValueJSON tests JSON operations
(t *testing.T)
| 729 | |
| 730 | // TestValueJSON tests JSON operations |
| 731 | func TestValueJSON(t *testing.T) { |
| 732 | useStableOwnerHooksForLegacySubtests(t) |
| 733 | |
| 734 | rt := NewRuntime() |
| 735 | defer rt.Close() |
| 736 | ctx := rt.NewContext() |
| 737 | defer ctx.Close() |
| 738 | |
| 739 | // Test object JSON stringify - Updated to use New* methods |
| 740 | obj := ctx.NewObject() |
| 741 | defer obj.Free() |
| 742 | obj.Set("name", ctx.NewString("test")) |
| 743 | obj.Set("value", ctx.NewInt32(42)) |
| 744 | |
| 745 | jsonStr := obj.JSONStringify() |
| 746 | require.Contains(t, jsonStr, "name") |
| 747 | require.Contains(t, jsonStr, "test") |
| 748 | require.Contains(t, jsonStr, "42") |
| 749 | |
| 750 | // Test various value types - Updated to use New* methods |
| 751 | testCases := []struct { |
| 752 | name string |
| 753 | createVal func() *Value // Changed to return pointer |
| 754 | expected string |
| 755 | }{ |
| 756 | {"String", func() *Value { return ctx.NewString("hello") }, `"hello"`}, |
| 757 | {"Null", func() *Value { return ctx.NewNull() }, "null"}, |
| 758 | {"True", func() *Value { return ctx.NewBool(true) }, "true"}, |
| 759 | {"False", func() *Value { return ctx.NewBool(false) }, "false"}, |
| 760 | {"Number", func() *Value { return ctx.NewInt32(42) }, "42"}, |
| 761 | } |
| 762 | |
| 763 | for _, tc := range testCases { |
| 764 | t.Run(tc.name, func(t *testing.T) { |
| 765 | val := tc.createVal() |
| 766 | defer val.Free() |
| 767 | require.Equal(t, tc.expected, val.JSONStringify()) |
| 768 | }) |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | // TestValueArrayBuffer tests ArrayBuffer operations |
| 773 | func TestValueArrayBuffer(t *testing.T) { |
nothing calls this directly
no test coverage detected