Tags: lstarboy/go-cmp
Tags
Additional cleanup with Go 1.13 as minimal version (google#295)
Add //go:build lines (google#285) Starting with Go 1.17, //go:build lines are preferred over // +build lines, see https://golang.org/doc/go1.17#build-lines and https://golang.org/design/draft-gobuild for details. This change was generated by running Go 1.17 go fmt ./... which automatically adds //go:build lines based on the existing // +build lines. Also update the corresponding GitHub action to use Go 1.17 gofmt.
Print as text if mostly text (google#258) The previous heuristic of treating strings as binary data if it contains any invalid UTF-8 was too strict. Loosen the heuristic to check if most of the characters are printable text. Fixes google#257
Fix reporter verbosity bug (google#253) FormatDiff should only set the verbosity to 3 if the current verbosity is lower than 3. Otherwise, it may remove an intended higher verbosity setting causing the reporter output to not differentiate between two large values that are different at the end. While we are at it, increase the maxVerbosityPreset to 6.
Impose verbosity limit when formatting map keys (google#248) Map keys should have a sensible verbosity limit imposed, otherwise the reporter can end up printing a massive data structure that cannot reasonably fit in memory.
Fix Diff documentation (google#237) The description inaccurately describes the operation of Diff, which is y - x, where a '+' prefix denotes elements added from y and a '-' prefix denotes elements removed from x. For example: // Consider this call to Diff and its result. x y cmp.Diff({b:2, c:3}, {a:1, b:2}) => {+a:1, b:2, -c:3} // Consider the same in mathematical notation. y - x {a:1, b:2} - {b:2, c:3} = {+a:1, b:2, -c:3}
Suggest use of cmpopts.EquateErrors (google#234) If cmp panics because it is trying to access an unexported field, specially suggest the use of cmpopts.EquateErrors if the parent type implements the error interface. Fixes google#233
Use triple-quote formatting for multiline strings (google#229) For strings, []bytes containing text data, Error method output, and String method output, use the triple-quoted syntax. This improves readability by presenting the data more naturally compared to a single-line quoted string with many escaped characters.
Improve reporting of values with cycles (google#217) Previously, the reporter could handle formatting values with cycles in that it did not crash with a stack overflow. However, the output was not particularly understandable as it did not surface to the user why a particular value was truncated, and if it was truncated due to a cyclic reference, what was the referent. This change annotates the reporter tree with pointer information so that a later pass can inject reference information if it is needed to produce more understandable output. Consider the following example: map[string]*cmp_test.CycleAlpha{ "Foo": &⟪ref#0⟫{ Name: "Foo", Bravos: map[string]*cmp_test.CycleBravo{ "FooBravo": &{ - ID: 101, + ID: 0, Name: "FooBravo", Mods: 100, Alphas: {"Foo": &⟪ref#0⟫(...)}, }, }, }, } This graph contains a cycle. To ensure that a graph can be formatted, the cycle is truncated as indicated with: &⟪ref#0⟫(...). The referent was identified earlier with: &⟪ref#0⟫{...}.
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
PreviousNext