func NotAny(notExpectedItems ...interface{}) TestDeep
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)) // fails
td.Cmp(t, []int{5}, td.NotAny(1, 2, 3)) // succeeds
// works with slices/arrays of any type
td.Cmp(t, personSlice, td.NotAny(
Person{Name: "Bob", Age: 32},
Person{Name: "Alice", Age: 26},
))
To flatten a non-[]interface{}
slice/array, use Flatten
function
and so avoid boring and inefficient copies:
notExpected := []int{2, 1}
td.Cmp(t, []int{4, 4, 3, 8}, td.NotAny(td.Flatten(notExpected))) // succeeds
// = td.Cmp(t, []int{4, 4, 3, 8}, td.NotAny(2, 1))
notExp1 := []int{2, 1}
notExp2 := []int{5, 8}
td.Cmp(t, []int{4, 4, 42, 8},
td.NotAny(td.Flatten(notExp1), 3, td.Flatten(notExp2))) // succeeds
// = td.Cmp(t, []int{4, 4, 42, 8}, td.NotAny(2, 1, 3, 5, 8))
Beware that NotAny(…)
is not equivalent to Not(Any(…)
) but is like
Not(SuperSet(…)
).
TypeBehind
method can return a non-nil
reflect.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.
See also NotAny godoc.
func CmpNotAny(t TestingT, got interface{}, notExpectedItems []interface{}, args ...interface{}) bool
CmpNotAny is a shortcut for:
td.Cmp(t, got, td.NotAny(notExpectedItems...), args...)
See above for details.
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.
See also CmpNotAny godoc.
func (t *T) NotAny(got interface{}, notExpectedItems []interface{}, args ...interface{}) bool
NotAny
is a shortcut for:
t.Cmp(got, td.NotAny(notExpectedItems...), args...)
See above for details.
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.
See also T.NotAny godoc.