go-cmp v0.1.0 Release Notes

Release Date: 2017-08-09 // about 5 years ago
  • ๐Ÿ“ฆ 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 like reflect.DeepEqual. Unlike reflect.DeepEqual, unexported
    0๏ธโƒฃ fields are not compared by default; they result in panics unless suppressed
    ๐Ÿ‘€ by using an Ignore option (see cmpopts.IgnoreUnexported) or explictly
    compared using the AllowUnexported 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 creating cmp.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 { ... }