NotInList succeeds if the whole value is not equal to any of the values from given list of values (e.g. map, slice, string, etc). Before comparison, all values are converted to canonical form. If at least one value has wrong type, failure is reported. Example: value := NewValue(t, "foo") value.
(values ...interface{})
| 887 | // value := NewValue(t, "foo") |
| 888 | // value.NotInList("bar", 123) |
| 889 | func (v *Value) NotInList(values ...interface{}) *Value { |
| 890 | opChain := v.chain.enter("NotInList()") |
| 891 | defer opChain.leave() |
| 892 | |
| 893 | if opChain.failed() { |
| 894 | return v |
| 895 | } |
| 896 | |
| 897 | if len(values) == 0 { |
| 898 | opChain.fail(AssertionFailure{ |
| 899 | Type: AssertUsage, |
| 900 | Errors: []error{ |
| 901 | errors.New("unexpected empty list argument"), |
| 902 | }, |
| 903 | }) |
| 904 | return v |
| 905 | } |
| 906 | |
| 907 | for _, val := range values { |
| 908 | expected, ok := canonValue(opChain, val) |
| 909 | if !ok { |
| 910 | return v |
| 911 | } |
| 912 | |
| 913 | if reflect.DeepEqual(expected, v.value) { |
| 914 | opChain.fail(AssertionFailure{ |
| 915 | Type: AssertNotBelongs, |
| 916 | Actual: &AssertionValue{v.value}, |
| 917 | Expected: &AssertionValue{AssertionList(values)}, |
| 918 | Errors: []error{ |
| 919 | errors.New("expected: value is not equal to any of the values"), |
| 920 | }, |
| 921 | }) |
| 922 | return v |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | return v |
| 927 | } |