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

Method FindAll

array.go:601–636  ·  view source on GitHub ↗

FindAll accepts a function that returns a boolean, runs it over the array elements, and returns all the elements on which it returned true. If there are any failed assertions in the predicate function, the element is skipped without causing test failure. If no elements were found, empty slice is r

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

Source from the content-addressed store, hash-verified

599// foundValues[0].IsEqual(101)
600// foundValues[1].IsEqual(201)
601func (a *Array) FindAll(fn func(index int, value *Value) bool) []*Value {
602 opChain := a.chain.enter("FindAll()")
603 defer opChain.leave()
604
605 if opChain.failed() {
606 return []*Value{}
607 }
608
609 if fn == nil {
610 opChain.fail(AssertionFailure{
611 Type: AssertUsage,
612 Errors: []error{
613 errors.New("unexpected nil function argument"),
614 },
615 })
616 return []*Value{}
617 }
618
619 foundValues := make([]*Value, 0, len(a.value))
620
621 for index, element := range a.value {
622 func() {
623 valueChain := opChain.replace("FindAll[%d]", index)
624 defer valueChain.leave()
625
626 valueChain.setRoot()
627 valueChain.setSeverity(SeverityLog)
628
629 if fn(index, newValue(valueChain, element)) && !valueChain.treeFailed() {
630 foundValues = append(foundValues, newValue(opChain, element))
631 }
632 }()
633 }
634
635 return foundValues
636}
637
638// NotFind accepts a function that returns a boolean, runs it over the array
639// elelements, and checks that it does not return true for any of the elements.

Callers 3

TestArray_FindAllFunction · 0.95
TestArray_FailedChainFunction · 0.45
TestObject_FailedChainFunction · 0.45

Calls 9

newValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80
replaceMethod · 0.80
setRootMethod · 0.80
setSeverityMethod · 0.80
treeFailedMethod · 0.80

Tested by 3

TestArray_FindAllFunction · 0.76
TestArray_FailedChainFunction · 0.36
TestObject_FailedChainFunction · 0.36