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

Function TestArrayEachNonArrayRootNoCallback_SYS029

parser_test.go:2538–2562  ·  view source on GitHub ↗

Verifies: SYS-REQ-029 [malformed_input] SYS-REQ-029:malformed_input:negative SYS-REQ-029:non_array_root_no_callback:negative Negative witness: ArrayEach on a non-array root value (object, number, string, bool) must NOT invoke the callback at all and must return an error. Before this fix, ArrayEach e

(t *testing.T)

Source from the content-addressed store, hash-verified

2536// as a string element) before returning MalformedArrayError — a caller
2537// performing side effects in the callback observed a bogus invocation.
2538func TestArrayEachNonArrayRootNoCallback_SYS029(t *testing.T) {
2539 cases := []struct {
2540 name string
2541 data string
2542 }{
2543 {"object_root", `{"a":1,"b":2}`},
2544 {"number_root", `12345`},
2545 {"bool_root", `true`},
2546 {"null_root", `null`},
2547 }
2548 for _, c := range cases {
2549 t.Run(c.name, func(t *testing.T) {
2550 callbacks := 0
2551 _, err := ArrayEach([]byte(c.data), func(v []byte, vt ValueType, o int, e error) {
2552 callbacks++
2553 })
2554 if err == nil {
2555 t.Fatalf("ArrayEach(%s) expected error, got nil", c.data)
2556 }
2557 if callbacks != 0 {
2558 t.Fatalf("ArrayEach(%s) emitted %d callback(s) before erroring — non-array root must not invoke callback", c.data, callbacks)
2559 }
2560 })
2561 }
2562}

Callers

nothing calls this directly

Calls 1

ArrayEachFunction · 0.85

Tested by

no test coverage detected