Changelog History
Page 2
-
v0.1.0 Changes
August 09, 2017๐ฆ Package
cmp
is intended to be a more powerful and safer alternative to
reflect.DeepEqual
for comparing whether two values are semantically equal.The primary features of
cmp
are:โ When the default behavior of equality does not suit the needs of the test,
custom equality functions can override the equality operation.
For example, an equality function may report floats as equal so long as they
are within some tolerance of each other.Types that have an
Equal
method may use that method to determine equality.
๐ฆ This allows package authors to determine the equality operation for the types
that they define.If no custom equality functions are used and no
Equal
method is defined,
equality is determined by recursively comparing the primitive kinds on both
values, much likereflect.DeepEqual
. Unlikereflect.DeepEqual
, unexported
0๏ธโฃ fields are not compared by default; they result in panics unless suppressed
๐ by using anIgnore
option (seecmpopts.IgnoreUnexported
) or explictly
compared using theAllowUnexported
option.๐ฆ Package API:
func Equal(x, y interface{}, opts ...Option) bool { ... }func Diff(x, y interface{}, opts ...Option) string { ... }// Section: 1. Configuration options for Equal and Difftype Option interface{ ... } func AllowUnexported(types ...interface{}) Option { ... }type Options []Option// Section: 1.1. Fundamental options to customize comparison of valuesfunc Ignore() Option { ... }func Comparer(f func(T, T) bool) Option { ... }func Transformer(name string, f func(T) R) Option { ... }// Section: 1.2. Filter options to control the scope of fundamental optionsfunc FilterPath(f func(Path) bool, opt Option) Option { ... }func FilterValues(f func(T, T) bool, opt Option) Option { ... }// Section: 2. Path to a node in the value treetype Path []PathSteptype PathStep interface{ ... }// Section: 2.1. Individual steps that comprise a Pathtype StructField interface{ ... }type SliceIndex interface{ ... }type MapIndex interface{ ... }type Indirect interface{ ... }type TypeAssertion interface{ ... }type Transform interface{ ... }
๐ฆ Package
cmpopts
provides helper functions for creatingcmp.Option
values
๐ง to configure comparisons for common use-cases.๐ฆ Package API:
// Section: Comparersfunc EquateApprox(fraction, margin float64) cmp.Option { ... }func EquateEmpty() cmp.Option { ... }func EquateNaNs() cmp.Option { ... }// Section: Ignorersfunc IgnoreFields(typ interface{}, names ...string) cmp.Option { ... }func IgnoreInterfaces(ifaces interface{}) cmp.Option { ... }func IgnoreTypes(typs ...interface{}) cmp.Option { ... }func IgnoreUnexported(typs ...interface{}) cmp.Option { ... }// Section: Transformersfunc SortMaps(less func(T, T) bool) cmp.Option { ... }func SortSlices(less func(T, T) bool) cmp.Option { ... }