MCPcopy Create free account
hub / github.com/gavv/httpexpect / FindAll

Method FindAll

object.go:633–668  ·  view source on GitHub ↗

FindAll accepts a function that returns a boolean, runs it over the object 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

(fn func(key string, value *Value) bool)

Source from the content-addressed store, hash-verified

631// foundValues[0].IsEqual(101)
632// foundValues[1].IsEqual(201)
633func (o *Object) FindAll(fn func(key string, value *Value) bool) []*Value {
634 opChain := o.chain.enter("FindAll()")
635 defer opChain.leave()
636
637 if opChain.failed() {
638 return []*Value{}
639 }
640
641 if fn == nil {
642 opChain.fail(AssertionFailure{
643 Type: AssertUsage,
644 Errors: []error{
645 errors.New("unexpected nil function argument"),
646 },
647 })
648 return []*Value{}
649 }
650
651 foundValues := make([]*Value, 0, len(o.value))
652
653 for _, kv := range o.sortedKV() {
654 func() {
655 valueChain := opChain.replace("FindAll[%q]", kv.key)
656 defer valueChain.leave()
657
658 valueChain.setRoot()
659 valueChain.setSeverity(SeverityLog)
660
661 if fn(kv.key, newValue(valueChain, kv.val)) && !valueChain.treeFailed() {
662 foundValues = append(foundValues, newValue(opChain, kv.val))
663 }
664 }()
665 }
666
667 return foundValues
668}
669
670// NotFind accepts a function that returns a boolean, runs it over the object
671// elelements, and checks that it does not return true for any of the elements.

Callers 1

TestObject_FindAllFunction · 0.95

Calls 10

sortedKVMethod · 0.95
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 1

TestObject_FindAllFunction · 0.76