Refactor option evaluation logic (#32)

The previous implementation of options had a single "option" type
that was used to represent either an Ignore, Comparer, or Transformer
and all of the filters relevant to each of them.

We refactor this logic by creating a new type to represent each of
the fundamental options and filtering options. Construction of
filtered options is now as simple as wrapping the input option with
the appropriate filter type.

Evaluation of filters now takes a top-down two-step approach where
1. We start with the set of all options, and recursively apply the filters
to create the "applicable" set S.
2. We apply the set S.

Both steps are represented as the filter and apply methods on
each of the core options.

This approach has the following advantages:
* It is faster because the same filter that was applied to multiple
options now only needs to execute once.
* It more closely matches the documented algorithm in cmp.Equal.
* It allows for easier extension of the API to add new fundamental
option types.
4 files changed
tree: 4eafcf2c12800217e0366ea1db1fd7e8aa918af1
  1. .travis.yml
  2. CONTRIBUTING.md
  3. LICENSE
  4. README.md
  5. cmp/
README.md

Package for equality of Go values

GoDoc Build Status

This package 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 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.

See the GoDoc documentation for more information.

This is not an official Google product.

Install

go get -u github.com/google/go-cmp/cmp

License

BSD - See LICENSE file