Tags: Catorpilor/go-cmp
Tags
Format units in decimal except bytes (google#199) In general, decimal formatting is preferred except for []byte where hexadecimal is preferred for individual elements. Fixes google#185
Add support for comparing graphs (google#85) Previously, trying to call Equal on a graph would result in a stack-overflow due to infinite recursion traversing cycles on a graph. While a vast majority of Go values are trees or acyclic graphs, there exist a small number of cases where graph equality is required. As such, we add cycle detection to Equal and define what it means for two graphs to be equal. Contrary to reflect.DeepEqual, which declares two graphs to be equal so long any cycle were encountered, we require two graphs to have equivalent graph structures. Mathematically speaking, a graph G is a tuple (V, E) consisting of the set of vertices and edges in that graph. Graphs G1 and G2 are equal if V1 == V2, E1 == E2, and both have the same root vertex (entry point into the graph). When traversing G1 and G2, we remember a stack of previously visited edges ES1 and ES2. If the current edge e1 is in ES1 or e2 is in ES2, then we know that a cycle exists. The graphs have the same structure when the previously encountered edge ep1 and ep2 were encountered together. Note that edges and vertices unreachable from the root vertex are ignored. Appreciation goes to Eyal Posener (@posener), who proposed a different (but semantically equivalent) approach in google#79, which served as inspiration. Fixes google#74
cmp/internal/value: fix handling of negative zero for floats (google#152 ) * Fix IsZero to properly report false for IsZero(-0.0) since we define IsZero as whether it is equal to the zero memory value. * Add note to isLess that we don't need to handle -0.0 since we can't possibly have both keys present in the same map. * Use sort.SliceStable in SortedKeys for deterministic output since it is possible to have both -0.0 and +0.0 from two different maps. The zero key from the left left map will be taken over the right map.
Support purego build tag (google#68) The proposal in golang/go#23172 was accepted. The "purego" build tag is intended to be a community agreed upon soft-signal to indicate the forbidden use of unsafe, assembly, or cgo. A change in the future will remove special-casing the appengine and js tags once the related toolchains support purego (possibly after some bake-in period).
Refactor option evaluation logic (google#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.