Operators

All operators

All
all expected values have to match
Any
at least one expected value have to match
Array
compares the contents of an array or a pointer on an array
ArrayEach
compares each array or slice item
Bag
compares the contents of an array or a slice without taking care of the order of items
Between
checks that a number, string or time.Time is between two bounds
Cap
checks an array, slice or channel capacity
Catch
catches data on the fly before comparing it
Code
checks using a custom function
Contains
checks that a string, []byte, error or fmt.Stringer interfaces contain a rune, byte or a sub-string; or a slice contains a single value or a sub-slice; or an array or map contain a single value
ContainsKey
checks that a map contains a key
Delay
delays the operator construction till first use
Empty
checks that an array, a channel, a map, a slice or a string is empty
ErrorIs
checks the data is an error and matches a wrapped error
First
find the first matching item of a slice or an array then compare its content
Grep
reduces a slice or an array before comparing its content
Gt
checks that a number, string or time.Time is greater than a value
Gte
checks that a number, string or time.Time is greater or equal than a value
HasPrefix
checks the prefix of a string, []byte, error or fmt.Stringer interfaces
HasSuffix
checks the suffix of a string, []byte, error or fmt.Stringer interfaces
Ignore
allows to ignore a comparison
Isa
checks the data type or whether data implements an interface or not
JSON
compares against JSON representation
JSONPointer
compares against JSON representation using a JSON pointer
Keys
checks keys of a map
Last
find the last matching item of a slice or an array then compare its content
Lax
temporarily enables BeLax config flag
Len
checks an array, slice, map, string or channel length
Lt
checks that a number, string or time.Time is lesser than a value
Lte
checks that a number, string or time.Time is lesser or equal than a value
Map
compares the contents of a map
MapEach
compares each map entry
N
compares a number with a tolerance value
NaN
checks a floating number is math.NaN
Nil
compares to nil
None
no values have to match
Not
value must not match
NotAny
compares the contents of an array or a slice, no values have to match
NotEmpty
checks that an array, a channel, a map, a slice or a string is not empty
NotNaN
checks a floating number is not math.NaN
NotNil
checks that data is not nil
NotZero
checks that data is not zero regarding its type
PPtr
allows to easily test a pointer of pointer value
Ptr
allows to easily test a pointer value
Re
allows to apply a regexp on a string (or convertible), []byte, error or fmt.Stringer interfaces, and even test the captured groups
ReAll
allows to successively apply a regexp on a string (or convertible), []byte, error or fmt.Stringer interfaces, and even test the captured groups
Recv
checks the value read from a channel
Set
compares the contents of an array or a slice ignoring duplicates and without taking care of the order of items
Shallow
compares pointers only, not their contents
Slice
compares the contents of a slice or a pointer on a slice
Smuggle
changes data contents or mutates it into another type via a custom function or a struct fields-path before stepping down in favor of generic comparison process
SStruct
strictly compares the contents of a struct or a pointer on a struct
String
checks a string, []byte, error or fmt.Stringer interfaces string contents
Struct
compares the contents of a struct or a pointer on a struct
SubBagOf
compares the contents of an array or a slice without taking care of the order of items but with potentially some exclusions
SubJSONOf
compares struct or map against JSON representation but with potentially some exclusions
SubMapOf
compares the contents of a map but with potentially some exclusions
SubSetOf
compares the contents of an array or a slice ignoring duplicates and without taking care of the order of items but with potentially some exclusions
SuperBagOf
compares the contents of an array or a slice without taking care of the order of items but with potentially some extra items
SuperJSONOf
compares struct or map against JSON representation but with potentially extra entries
SuperMapOf
compares the contents of a map but with potentially some extra entries
SuperSetOf
compares the contents of an array or a slice ignoring duplicates and without taking care of the order of items but with potentially some extra items
SuperSliceOf
compares the contents of a slice, a pointer on a slice, an array or a pointer on an array but with potentially some extra entries
Tag
names an operator or a value. Only useful as a parameter of JSON operator, to name placeholders
TruncTime
compares time.Time (or assignable) values after truncating them
Values
checks values of a map
Zero
checks data against its zero’ed conterpart

Smuggler operators

A smuggler operator is an operator able to transform the value (by changing its value or even its type) before comparing it.

The following operators are smuggler ones:

Cap
checks an array, slice or channel capacity
Catch
catches data on the fly before comparing it
Contains
checks that a string, []byte, error or fmt.Stringer interfaces contain a rune, byte or a sub-string; or a slice contains a single value or a sub-slice; or an array or map contain a single value
ContainsKey
checks that a map contains a key
ErrorIs
checks the data is an error and matches a wrapped error
First
find the first matching item of a slice or an array then compare its content
Grep
reduces a slice or an array before comparing its content
JSONPointer
compares against JSON representation using a JSON pointer
Keys
checks keys of a map
Last
find the last matching item of a slice or an array then compare its content
Lax
temporarily enables BeLax config flag
Len
checks an array, slice, map, string or channel length
PPtr
allows to easily test a pointer of pointer value
Ptr
allows to easily test a pointer value
Recv
checks the value read from a channel
Smuggle
changes data contents or mutates it into another type via a custom function or a struct fields-path before stepping down in favor of generic comparison process
Tag
names an operator or a value. Only useful as a parameter of JSON operator, to name placeholders
Values
checks values of a map

TypeBehind method

TypeBehind() reflect.Type

This method returns the type handled by the operator or nil if it is not known. tdhttp helper uses it to know how to unmarshal HTTP responses bodies before comparing them using the operator.

It is usually not used outside the go-testdeep repository.