NotAny

func NotAny(notExpectedItems ...any) 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-[]any 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 Set, SubSetOf and SuperSetOf.

See also NotAny godoc.

Example

Base example

CmpNotAny shortcut

func CmpNotAny(t TestingT, got any, notExpectedItems []any, args ...any) 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.

If t is a *T then its Config field is inherited.

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.

Example

Base example

T.NotAny shortcut

func (t *T) NotAny(got any, notExpectedItems []any, args ...any) 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.

Example

Base example