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

Function TestArrayEachCallbackReceivesElementError

deep_spec_test.go:1136–1161  ·  view source on GitHub ↗

Verifies: SYS-REQ-052 [malformed] MCDC SYS-REQ-052: array_callback_returns_error=T, array_callback_error_is_propagated=T => TRUE

(t *testing.T)

Source from the content-addressed store, hash-verified

1134// Verifies: SYS-REQ-052 [malformed]
1135// MCDC SYS-REQ-052: array_callback_returns_error=T, array_callback_error_is_propagated=T => TRUE
1136func TestArrayEachCallbackReceivesElementError(t *testing.T) {
1137 // Array where the second element is malformed — callback should receive the
1138 // error for the malformed element instead of ArrayEach silently stopping.
1139 var callbackErrors []error
1140 var callbackValues []string
1141 _, err := ArrayEach([]byte(`[1, nope, 3]`), func(value []byte, dataType ValueType, offset int, err error) {
1142 callbackValues = append(callbackValues, string(value))
1143 callbackErrors = append(callbackErrors, err)
1144 })
1145 if err == nil {
1146 t.Fatal("expected ArrayEach to return an error for malformed element")
1147 }
1148 // The callback should have been called for element "1" (success) and then
1149 // for the malformed "nope" element (with error).
1150 if len(callbackErrors) < 2 {
1151 t.Fatalf("expected callback to be called at least 2 times (including error element), got %d", len(callbackErrors))
1152 }
1153 // First element should have no error
1154 if callbackErrors[0] != nil {
1155 t.Fatalf("first callback should have nil error, got %v", callbackErrors[0])
1156 }
1157 // Second element should have a non-nil error
1158 if callbackErrors[1] == nil {
1159 t.Fatal("second callback should have received the parse error for malformed element")
1160 }
1161}
1162
1163// Verifies: SYS-REQ-052 [boundary]
1164// MCDC SYS-REQ-052: array_callback_returns_error=T, array_callback_error_is_propagated=F => FALSE

Callers

nothing calls this directly

Calls 1

ArrayEachFunction · 0.85

Tested by

no test coverage detected