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

Function TestArrayEachNonArrayRootNoCallback_SYS029

parser_test.go:2532–2556  ·  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

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

Callers

nothing calls this directly

Calls 1

ArrayEachFunction · 0.85

Tested by

no test coverage detected