Documentation ¶
Index ¶
Constants ¶
View Source
const ( // MaxDiff specifies the maximum number of differences to return. MaxDiff = 10 // FloatPrecision is the number of decimal places to round float values // to when comparing. FloatPrecision = 10 )
Variables ¶
This section is empty.
Functions ¶
func Respect ¶
Respect check if obj respect the respectObj by recursing into their structure, and returns a list of differences, or nil if there are none.
Respect means:
- if obj and respectObj are primitive types, they should be equal with each other.
- if obj and respectObj are slice/array type, obj should be a superset of respectObj and elements in obj should respect the corresponding elements in respectObj. If the slice/array items' kind is reflect.Struct, below is the way we used to find the corresponding elements. Use all the valid/non-zero string/*string fields of respectObj as the identifier to find the corresponding element in obj. If LengthMatters option provided, they should have same length. If OrderMatters option provided, they'll be compared one by one in order.
- if obj and respectObj are map type, obj should contain all the key value pair in respectObj.
- if obj and respectObj are struct type, obj should contains all the fields and respect their value in respectObj. Reminder: Be care of the non-pointer field in respectObj struct, these field will be considered as zero value if omitted and participate into the comparison which might lead to unexpected result
Types ¶
type Options ¶
type Options int
Options is the type for options passed to respect function/matcher.
const ( //OrderMatters will consider the items order when comparing array/slice, rather than triggering a failure. OrderMatters Options = 1 << iota //LengthMatters will consider the length of array/slice when comparing, rather than triggering a failure. LengthMatters //ZeroValueMatters will also respect zero values, rather than ignore them ZeroValueMatters )
Click to show internal directories.
Click to hide internal directories.