MCPcopy Index your code
hub / github.com/gavv/httpexpect / Every

Method Every

array.go:394–422  ·  view source on GitHub ↗

Every runs the passed function on all the elements in the array. If assertion inside function fails, the original Array is marked failed. Every will execute the function for all values in the array irrespective of assertion failures for some values in the array. Example: array := NewArray(t, []

(fn func(index int, value *Value))

Source from the content-addressed store, hash-verified

392// value.String().NotEmpty()
393// })
394func (a *Array) Every(fn func(index int, value *Value)) *Array {
395 opChain := a.chain.enter("Every()")
396 defer opChain.leave()
397
398 if opChain.failed() {
399 return a
400 }
401
402 if fn == nil {
403 opChain.fail(AssertionFailure{
404 Type: AssertUsage,
405 Errors: []error{
406 errors.New("unexpected nil function argument"),
407 },
408 })
409 return a
410 }
411
412 for index, element := range a.value {
413 func() {
414 valueChain := opChain.replace("Every[%d]", index)
415 defer valueChain.leave()
416
417 fn(index, newValue(valueChain, element))
418 }()
419 }
420
421 return a
422}
423
424// Filter accepts a function that returns a boolean. The function is ran
425// over the array elements. If the function returns true, the element passes

Callers 4

TestArray_EveryFunction · 0.95
TestArray_FailedChainFunction · 0.45
TestObject_FailedChainFunction · 0.45
TestFruitsFunction · 0.45

Calls 6

newValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80
replaceMethod · 0.80

Tested by 4

TestArray_EveryFunction · 0.76
TestArray_FailedChainFunction · 0.36
TestObject_FailedChainFunction · 0.36
TestFruitsFunction · 0.36