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.
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:="foo/bar"// Checks got string against:// "zip" regexp *OR* "bar" suffixok:=td.Cmp(t,got,td.Any(td.Re("zip"),td.HasSuffix("bar")),"checks value %s",got)fmt.Println(ok)// Checks got string against:// "zip" regexp *OR* "foo" suffixok=td.Cmp(t,got,td.Any(td.Re("zip"),td.HasSuffix("foo")),"checks value %s",got)fmt.Println(ok)// When some operators or values have to be reused and mixed between// several calls, Flatten can be used to avoid boring and// inefficient []any copies:regOps:=td.Flatten([]td.TestDeep{td.Re("a/c"),td.Re(`^xx`),td.Re(`ar$`)})ok=td.Cmp(t,got,td.Any(td.HasPrefix("xxx"),regOps,td.HasSuffix("zip")),"check at least one operator matches value %s",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:="foo/bar"// Checks got string against:// "zip" regexp *OR* "bar" suffixok:=td.CmpAny(t,got,[]any{td.Re("zip"),td.HasSuffix("bar")},"checks value %s",got)fmt.Println(ok)// Checks got string against:// "zip" regexp *OR* "foo" suffixok=td.CmpAny(t,got,[]any{td.Re("zip"),td.HasSuffix("foo")},"checks value %s",got)fmt.Println(ok)// When some operators or values have to be reused and mixed between// several calls, Flatten can be used to avoid boring and// inefficient []any copies:regOps:=td.Flatten([]td.TestDeep{td.Re("a/c"),td.Re(`^xx`),td.Re(`ar$`)})ok=td.CmpAny(t,got,[]any{td.HasPrefix("xxx"),regOps,td.HasSuffix("zip")},"check at least one operator matches value %s",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:="foo/bar"// Checks got string against:// "zip" regexp *OR* "bar" suffixok:=t.Any(got,[]any{td.Re("zip"),td.HasSuffix("bar")},"checks value %s",got)fmt.Println(ok)// Checks got string against:// "zip" regexp *OR* "foo" suffixok=t.Any(got,[]any{td.Re("zip"),td.HasSuffix("foo")},"checks value %s",got)fmt.Println(ok)// When some operators or values have to be reused and mixed between// several calls, Flatten can be used to avoid boring and// inefficient []any copies:regOps:=td.Flatten([]td.TestDeep{td.Re("a/c"),td.Re(`^xx`),td.Re(`ar$`)})ok=t.Any(got,[]any{td.HasPrefix("xxx"),regOps,td.HasSuffix("zip")},"check at least one operator matches value %s",got)fmt.Println(ok)// Output:// true// false// true