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

Function TestObjectEachCallbackErrorPropagation

path_fuzz_test.go:734–776  ·  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

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