NotAny operator checks that the contents of an array or a slice (or
a pointer on array/slice) does not contain any of “notExpectedItems”.
td.Cmp(t,[]int{1},td.NotAny(1,2,3))// failstd.Cmp(t,[]int{5},td.NotAny(1,2,3))// succeeds// works with slices/arrays of any typetd.Cmp(t,personSlice,td.NotAny(Person{Name:"Bob",Age:32},Person{Name:"Alice",Age:26},))
To flatten a non-[]any slice/array, use Flatten function
and so avoid boring and inefficient copies:
Beware that NotAny(…) is not equivalent to Not(Any(…)) but is like
Not(SuperSet(…)).
TypeBehind method can return a non-nilreflect.Type if all items
known non-interface types are equal, or if only interface types
are found (mostly issued from Isa) and they are equal.
t:=&testing.T{}got:=[]int{4,5,9,42}ok:=td.Cmp(t,got,td.NotAny(3,6,8,41,43),"checks %v contains no item listed in NotAny()",got)fmt.Println(ok)ok=td.Cmp(t,got,td.NotAny(3,6,8,42,43),"checks %v contains no item listed in NotAny()",got)fmt.Println(ok)// When expected is already a non-[]any slice, it cannot be// flattened directly using notExpected... without copying it to a new// []any slice, then use td.Flatten!notExpected:=[]int{3,6,8,41,43}ok=td.Cmp(t,got,td.NotAny(td.Flatten(notExpected)),"checks %v contains no item listed in notExpected",got)fmt.Println(ok)// Output:// true// false// true
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1 and
the first item of args is a string and contains a ‘%’ rune then
fmt.Fprintf is used to compose the name, else args are passed to
fmt.Fprint. Do not forget it is the name of the test, not the
reason of a potential failure.
t:=&testing.T{}got:=[]int{4,5,9,42}ok:=td.CmpNotAny(t,got,[]any{3,6,8,41,43},"checks %v contains no item listed in NotAny()",got)fmt.Println(ok)ok=td.CmpNotAny(t,got,[]any{3,6,8,42,43},"checks %v contains no item listed in NotAny()",got)fmt.Println(ok)// When expected is already a non-[]any slice, it cannot be// flattened directly using notExpected... without copying it to a new// []any slice, then use td.Flatten!notExpected:=[]int{3,6,8,41,43}ok=td.CmpNotAny(t,got,[]any{td.Flatten(notExpected)},"checks %v contains no item listed in notExpected",got)fmt.Println(ok)// Output:// true// false// true
Returns true if the test is OK, false if it fails.
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1 and
the first item of args is a string and contains a ‘%’ rune then
fmt.Fprintf is used to compose the name, else args are passed to
fmt.Fprint. Do not forget it is the name of the test, not the
reason of a potential failure.
t:=td.NewT(&testing.T{})got:=[]int{4,5,9,42}ok:=t.NotAny(got,[]any{3,6,8,41,43},"checks %v contains no item listed in NotAny()",got)fmt.Println(ok)ok=t.NotAny(got,[]any{3,6,8,42,43},"checks %v contains no item listed in NotAny()",got)fmt.Println(ok)// When expected is already a non-[]any slice, it cannot be// flattened directly using notExpected... without copying it to a new// []any slice, then use td.Flatten!notExpected:=[]int{3,6,8,41,43}ok=t.NotAny(got,[]any{td.Flatten(notExpected)},"checks %v contains no item listed in notExpected",got)fmt.Println(ok)// Output:// true// false// true