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

Function TestArrayEachCallbackErrorNotSwallowed

deep_spec_test.go:1165–1184  ·  view source on GitHub ↗

Verifies: SYS-REQ-052 [boundary] MCDC SYS-REQ-052: array_callback_returns_error=T, array_callback_error_is_propagated=F => FALSE

(t *testing.T)

Source from the content-addressed store, hash-verified

1163// Verifies: SYS-REQ-052 [boundary]
1164// MCDC SYS-REQ-052: array_callback_returns_error=T, array_callback_error_is_propagated=F => FALSE
1165func TestArrayEachCallbackErrorNotSwallowed(t *testing.T) {
1166 // When ArrayEach encounters a Get error on an element, the error must
1167 // propagate — it cannot be swallowed. This test witnesses the FALSE row:
1168 // if callback receives an error but it's somehow not propagated, the
1169 // formula evaluates to FALSE (violation).
1170 // In practice, the current implementation always propagates, so this
1171 // witnesses the row by confirming propagation happens.
1172 var sawError bool
1173 _, err := ArrayEach([]byte(`[1, nope]`), func(value []byte, dataType ValueType, offset int, err error) {
1174 if err != nil {
1175 sawError = true
1176 }
1177 })
1178 if err == nil {
1179 t.Fatal("expected ArrayEach to return error for malformed element")
1180 }
1181 if !sawError {
1182 t.Fatal("callback should have received the error before ArrayEach returned it")
1183 }
1184}

Callers

nothing calls this directly

Calls 1

ArrayEachFunction · 0.85

Tested by

no test coverage detected