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

Function TestValueJSON

value_test.go:731–770  ·  view source on GitHub ↗

TestValueJSON tests JSON operations

(t *testing.T)

Source from the content-addressed store, hash-verified

729
730// TestValueJSON tests JSON operations
731func 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
773func TestValueArrayBuffer(t *testing.T) {

Callers

nothing calls this directly

Calls 14

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
NewObjectMethod · 0.95
NewStringMethod · 0.95
NewInt32Method · 0.95
NewNullMethod · 0.95
NewBoolMethod · 0.95
NewRuntimeFunction · 0.85
SetMethod · 0.80
JSONStringifyMethod · 0.80

Tested by

no test coverage detected