Description

Is compares two values (got & expect) and returns true if the comparison is true, false otherwise. In addition, if the comparison is false, Is will report the error in a manner similar to testing.T.Error(...). Is also takes an optional argument, a comparator, that changes how the comparison is made. The following comparators are available:

==      # got == expect (default)
!=      # got != expect

>       # got > expect (float32, uint, uint16, int, int64, ...)
>=      # got >= expect
<       # got < expect
<=      # got <= expect

=~      # regexp.MustCompile(expect).Match{String}(got)
!~      # !regexp.MustCompile(expect).Match{String}(got)

Basic usage with the default comparator (==):

Is(<got>, <expect>)

Specifying a different comparator:

Is(<got>, <comparator>, <expect>)

A simple comparison:

Is(2 + 2, 4)

A bit trickier:

Is(1, ">", 0)
Is(2 + 2, "!=", 5)
Is("Nothing happens.", "=~", `ing(\s+)happens\.$`)

Is should only be called under a Terst(t, ...) call. For a standalone version, use IsErr. If no scope is found and the comparison is false, then Is will panic the error.

Is is referenced in 0 repositories