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

Function TestArrayEachSupplementalErrors

mcdc_supplement_test.go:241–268  ·  view source on GitHub ↗

Verifies: SYS-REQ-006 [malformed] MCDC SYS-REQ-006: N/A

(t *testing.T)

Source from the content-addressed store, hash-verified

239// Verifies: SYS-REQ-006 [malformed]
240// MCDC SYS-REQ-006: N/A
241func TestArrayEachSupplementalErrors(t *testing.T) {
242 noop := func([]byte, ValueType, int, error) {}
243
244 cases := []struct {
245 name string
246 data string
247 keys []string
248 wantErr error
249 }{
250 {name: "empty input", data: ``, wantErr: MalformedObjectError},
251 {name: "missing path", data: `{"a":[1]}`, keys: []string{"missing"}, wantErr: KeyPathNotFoundError},
252 {name: "target is not an array", data: `{"a":1}`, keys: []string{"a"}, wantErr: MalformedArrayError},
253 {name: "missing value after key", data: `{"a":`, keys: []string{"a"}, wantErr: MalformedJsonError},
254 {name: "missing comma between array elements", data: `[1 2]`, wantErr: MalformedArrayError},
255 {name: "trailing comma in array", data: `[1,`, wantErr: MalformedJsonError},
256 {name: "unterminated array without closing bracket", data: `[1`, wantErr: MalformedArrayError},
257 {name: "malformed array element", data: `[1, nope]`, wantErr: UnknownValueTypeError},
258 }
259
260 for _, tc := range cases {
261 t.Run(tc.name, func(t *testing.T) {
262 _, err := ArrayEach([]byte(tc.data), noop, tc.keys...)
263 if !errors.Is(err, tc.wantErr) {
264 t.Fatalf("ArrayEach(%q, %v) error = %v, want %v", tc.data, tc.keys, err, tc.wantErr)
265 }
266 })
267 }
268}
269
270// Verifies: SYS-REQ-007 [malformed]
271// MCDC SYS-REQ-007: N/A

Callers

nothing calls this directly

Calls 1

ArrayEachFunction · 0.85

Tested by

no test coverage detected