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

Function TestTruncatedAtValueBoundary

deep_spec_test.go:16–42  ·  view source on GitHub ↗

============================================================================= Truncated-input tests (SYS-REQ-041, SYS-REQ-042, SYS-REQ-043) ============================================================================= Verifies: SYS-REQ-041 [malformed] When JSON input is truncated at a value boundary

(t *testing.T)

Source from the content-addressed store, hash-verified

14// When JSON input is truncated at a value boundary (e.g. '{"a":1' no closing
15// brace), Get shall return an error or not-found and shall not panic.
16func TestTruncatedAtValueBoundary(t *testing.T) {
17 cases := []struct {
18 name string
19 data string
20 keys []string
21 }{
22 {name: "object no closing brace", data: `{"test":1`, keys: []string{"test"}},
23 {name: "value after colon missing", data: `{"test":`, keys: []string{"test"}},
24 {name: "nested object no close", data: `{"a":{"b":1}`, keys: []string{"a"}},
25 {name: "number at EOF", data: `{"x":12345`, keys: []string{"x"}},
26 }
27 for _, tc := range cases {
28 t.Run(tc.name, func(t *testing.T) {
29 func() {
30 defer func() {
31 if r := recover(); r != nil {
32 t.Fatalf("Get(%q, %v) panicked: %v", tc.data, tc.keys, r)
33 }
34 }()
35 _, _, _, err := Get([]byte(tc.data), tc.keys...)
36 // We accept any result as long as there's no panic.
37 // An error is expected for most, but a "best-effort" match is allowed per SYS-REQ-026.
38 _ = err
39 }()
40 })
41 }
42}
43
44// Verifies: SYS-REQ-042 [malformed]
45// When JSON input is truncated mid-structure (e.g. '{"a":[1,2'), Get shall

Callers

nothing calls this directly

Calls 1

GetFunction · 0.85

Tested by

no test coverage detected