Any

func Any(expectedValues ...any) TestDeep

Any operator compares data against several expected values. During a match, at least one of them has to match to succeed. Consider it as a “OR” logical operator.

td.Cmp(t, "foo", td.Any("bar", "foo", "zip")) // succeeds
td.Cmp(t, "foo", td.Any(
  td.Len(4),
  td.HasPrefix("f"),
  td.HasSuffix("z"),
)) // succeeds coz "f" prefix

Note Flatten function can be used to group or reuse some values or operators and so avoid boring and inefficient copies:

stringOps := td.Flatten([]td.TestDeep{td.HasPrefix("f"), td.HasSuffix("z")})
td.Cmp(t, "foobar", td.All(
  td.Len(4),
  stringOps,
)) // succeeds coz "f" prefix

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 All and None.

See also Any godoc.

Example

Base example

CmpAny shortcut

func CmpAny(t TestingT, got any, expectedValues []any, args ...any) bool

CmpAny is a shortcut for:

td.Cmp(t, got, td.Any(expectedValues...), 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 CmpAny godoc.

Example

Base example

T.Any shortcut

func (t *T) Any(got any, expectedValues []any, args ...any) bool

Any is a shortcut for:

t.Cmp(got, td.Any(expectedValues...), 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.Any godoc.

Example

Base example