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

Method NotFind

array.go:654–702  ·  view source on GitHub ↗

NotFind accepts a function that returns a boolean, runs it over the array elelements, and checks that it does not return true for any of the elements. If there are any failed assertions in the predicate function, the element is skipped without causing test failure. If the predicate function did no

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

Source from the content-addressed store, hash-verified

652// return num.Raw() > 100 // check element value
653// }) // succeeds
654func (a *Array) NotFind(fn func(index int, value *Value) bool) *Array {
655 opChain := a.chain.enter("NotFind()")
656 defer opChain.leave()
657
658 if opChain.failed() {
659 return a
660 }
661
662 if fn == nil {
663 opChain.fail(AssertionFailure{
664 Type: AssertUsage,
665 Errors: []error{
666 errors.New("unexpected nil function argument"),
667 },
668 })
669 return a
670 }
671
672 for index, element := range a.value {
673 found := false
674
675 func() {
676 valueChain := opChain.replace("NotFind[%d]", index)
677 defer valueChain.leave()
678
679 valueChain.setRoot()
680 valueChain.setSeverity(SeverityLog)
681
682 if fn(index, newValue(valueChain, element)) && !valueChain.treeFailed() {
683 found = true
684 }
685 }()
686
687 if found {
688 opChain.fail(AssertionFailure{
689 Type: AssertNotContainsElement,
690 Expected: &AssertionValue{element},
691 Actual: &AssertionValue{a.value},
692 Errors: []error{
693 errors.New("expected: none of the array elements match predicate"),
694 fmt.Errorf("element with index %d matches predicate", index),
695 },
696 })
697 return a
698 }
699 }
700
701 return a
702}
703
704// IsEmpty succeeds if array is empty.
705//

Callers 3

TestArray_NotFindFunction · 0.95
TestArray_FailedChainFunction · 0.45
TestObject_FailedChainFunction · 0.45

Calls 10

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
ErrorfMethod · 0.65

Tested by 3

TestArray_NotFindFunction · 0.76
TestArray_FailedChainFunction · 0.36
TestObject_FailedChainFunction · 0.36