============================================================================= ObjectEach callback-error propagation test (closes Dimension 2) ============================================================================= ObjectEach's documented contract: a callback-returned error aborts iteration an
(t *testing.T)
| 732 | // |
| 733 | // Verifies: SYS-REQ-007 (ObjectEach callback error propagation). |
| 734 | func 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 |
nothing calls this directly
no test coverage detected