MCPcopy Create free account
hub / github.com/buger/jsonparser / TestObjectEachTruncatedMidStructure

Function TestObjectEachTruncatedMidStructure

deep_spec_test.go:873–899  ·  view source on GitHub ↗

============================================================================= ObjectEach truncated mid-structure (SYS-REQ-084) ============================================================================= Verifies: SYS-REQ-084 [malformed] ObjectEach on truncated mid-structure input shall return erro

(t *testing.T)

Source from the content-addressed store, hash-verified

871// Verifies: SYS-REQ-084 [malformed]
872// ObjectEach on truncated mid-structure input shall return error, not panic.
873func TestObjectEachTruncatedMidStructure(t *testing.T) {
874 cases := []struct {
875 name string
876 data string
877 }{
878 {name: "unclosed object", data: `{"a":1, "b":2`},
879 {name: "unclosed nested", data: `{"a":{"b":1`},
880 {name: "value truncated", data: `{"a":"hello`},
881 }
882 for _, tc := range cases {
883 t.Run(tc.name, func(t *testing.T) {
884 func() {
885 defer func() {
886 if r := recover(); r != nil {
887 t.Fatalf("ObjectEach(%q) panicked: %v", tc.data, r)
888 }
889 }()
890 err := ObjectEach([]byte(tc.data), func(key []byte, value []byte, dataType ValueType, offset int) error {
891 return nil
892 })
893 if err == nil {
894 t.Logf("ObjectEach(%q) returned no error (partial parse may succeed)", tc.data)
895 }
896 }()
897 })
898 }
899}
900
901// =============================================================================
902// EachKey sentinel handling (SYS-REQ-085)

Callers

nothing calls this directly

Calls 1

ObjectEachFunction · 0.85

Tested by

no test coverage detected