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

Method NotFind

object.go:693–741  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

691// return num.Raw() > 100 // check element value
692// }) // succeeds
693func (o *Object) NotFind(fn func(key string, value *Value) bool) *Object {
694 opChain := o.chain.enter("NotFind()")
695 defer opChain.leave()
696
697 if opChain.failed() {
698 return o
699 }
700
701 if fn == nil {
702 opChain.fail(AssertionFailure{
703 Type: AssertUsage,
704 Errors: []error{
705 errors.New("unexpected nil function argument"),
706 },
707 })
708 return o
709 }
710
711 for _, kv := range o.sortedKV() {
712 found := false
713
714 func() {
715 valueChain := opChain.replace("NotFind[%q]", kv.key)
716 defer valueChain.leave()
717
718 valueChain.setRoot()
719 valueChain.setSeverity(SeverityLog)
720
721 if fn(kv.key, newValue(valueChain, kv.val)) && !valueChain.treeFailed() {
722 found = true
723 }
724 }()
725
726 if found {
727 opChain.fail(AssertionFailure{
728 Type: AssertNotContainsElement,
729 Expected: &AssertionValue{kv.val},
730 Actual: &AssertionValue{o.value},
731 Errors: []error{
732 errors.New("expected: none of the object elements match predicate"),
733 fmt.Errorf("element with key %q matches predicate", kv.key),
734 },
735 })
736 return o
737 }
738 }
739
740 return o
741}
742
743// IsEmpty succeeds if object is empty.
744//

Callers 1

TestObject_NotFindFunction · 0.95

Calls 11

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

Tested by 1

TestObject_NotFindFunction · 0.76