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

Function TestObjectEachCallbackErrorPropagation

path_fuzz_test.go:728–770  ·  view source on GitHub ↗

============================================================================= ObjectEach callback-error propagation test (closes Dimension 2) ============================================================================= ObjectEach's documented contract: a callback-returned error aborts iteration an

(t *testing.T)

Source from the content-addressed store, hash-verified

726//
727// Verifies: SYS-REQ-007 (ObjectEach callback error propagation).
728func TestObjectEachCallbackErrorPropagation(t *testing.T) {
729 // Build a valid object with multiple keys so the callback fires >1 time.
730 data := []byte(`{"a":1,"b":2,"c":3,"d":4,"e":5}`)
731 sentinel := fmt.Errorf("sequence-callback-sentinel")
732 seen := 0
733 err := ObjectEach(data, func(key, value []byte, dt ValueType, off int) error {
734 seen++
735 if seen == 3 {
736 return sentinel
737 }
738 return nil
739 })
740 if err != sentinel {
741 t.Errorf("ObjectEach did not return the callback's sentinel error: got %v want %v (seen=%d)",
742 err, sentinel, seen)
743 }
744 if seen != 3 {
745 t.Errorf("ObjectEach did not abort on callback error: callback fired %d times, want 3", seen)
746 }
747
748 // Also exercise the path with empty / malformed input to ensure the
749 // error-abort path is panic-free on adversarial shapes.
750 for _, adversarial := range [][]byte{
751 []byte(`{`),
752 []byte(`{"a"`),
753 []byte(`{"a":`),
754 []byte(`{"a":1,`),
755 []byte(``),
756 []byte(`}`),
757 []byte(`{}`),
758 } {
759 func() {
760 defer func() {
761 if r := recover(); r != nil {
762 t.Errorf("PANIC in ObjectEach callback-error path on %q: %v", adversarial, r)
763 }
764 }()
765 _ = ObjectEach(adversarial, func(key, value []byte, dt ValueType, off int) error {
766 return sentinel
767 })
768 }()
769 }
770}
771
772// TestEachKeyMultiPathInvariants closes the EachKey multi-path blind spot
773// deterministically. EachKey's purpose is to resolve MULTIPLE key paths in

Callers

nothing calls this directly

Calls 1

ObjectEachFunction · 0.85

Tested by

no test coverage detected