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)
| 652 | // return num.Raw() > 100 // check element value |
| 653 | // }) // succeeds |
| 654 | func (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 | // |