func Lax(expectedValue any) TestDeep
Lax is a smuggler operator, it temporarily enables the BeLax
config flag before letting the comparison process continue its course.
It is more commonly used as CmpLax
function than as an operator. It
could be used when, for example, an operator is constructed once
but applied to different, but compatible types as in:
bw := td.Between(20, 30)
intValue := 21
floatValue := 21.89
td.Cmp(t, intValue, bw) // no need to be lax here: same int types
td.Cmp(t, floatValue, td.Lax(bw)) // be lax please, as float64 ≠ int
Note that in the latter case, CmpLax
could be used as well:
td.CmpLax(t, floatValue, bw)
TypeBehind
method returns the greatest convertible or more common
reflect.Type
of expectedValue if it is a base type (bool
, int*
,
uint*
, float*
, complex*
, string
), the reflect.Type
of
expectedValue otherwise, except if expectedValue is a TestDeep
operator. In this case, it delegates TypeBehind()
to the operator.
See also Lax godoc.
func CmpLax(t TestingT, got, expectedValue any, args ...any) bool
CmpLax is a shortcut for:
td.Cmp(t, got, td.Lax(expectedValue), 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 CmpLax godoc.
func (t *T) CmpLax(got, expectedValue any, args ...any) bool
CmpLax is a shortcut for:
t.Cmp(got, td.Lax(expectedValue), 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.CmpLax godoc.