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

Function TestSetSupplementalArrayInsertionCoverage

mcdc_supplement_test.go:339–364  ·  view source on GitHub ↗

Verifies: SYS-REQ-009 [boundary] MCDC SYS-REQ-009: N/A

(t *testing.T)

Source from the content-addressed store, hash-verified

337// Verifies: SYS-REQ-009 [boundary]
338// MCDC SYS-REQ-009: N/A
339func TestSetSupplementalArrayInsertionCoverage(t *testing.T) {
340 t.Run("append into existing top level array path", func(t *testing.T) {
341 // SYS-REQ-110: setting an index beyond the current array length
342 // must append at the end, preserving existing elements. The
343 // previous behavior (overwrite with [value]) was a silent data
344 // loss bug for scalar arrays — fixed by correcting the
345 // `data[subObjOff] == '{'` guard to `!= ']'` in parser.go:Set.
346 got, err := Set([]byte(`{"top":[1]}`), []byte(`2`), "top", "[1]")
347 if err != nil {
348 t.Fatalf("Set array append returned error: %v", err)
349 }
350 if string(got) != `{"top":[1,2]}` {
351 t.Fatalf("Set array append result = %s, want %s (SYS-REQ-110: append-at-end preserves existing scalar elements)", string(got), `{"top":[1,2]}`)
352 }
353 })
354
355 t.Run("append object into nested existing array", func(t *testing.T) {
356 got, err := Set([]byte(`{"top":[{"middle":[{"present":true}]}]}`), []byte(`{"bottom":"value"}`), "top", "[0]", "middle", "[1]")
357 if err != nil {
358 t.Fatalf("Set nested array append returned error: %v", err)
359 }
360 if string(got) != `{"top":[{"middle":[{"present":true},{"bottom":"value"}]}]}` {
361 t.Fatalf("Set nested array append result = %s", string(got))
362 }
363 })
364}
365
366// Verifies: SYS-REQ-014 [malformed]
367// MCDC SYS-REQ-014: N/A

Callers

nothing calls this directly

Calls 1

SetFunction · 0.85

Tested by

no test coverage detected