go 1.22.5
github.com/google/go-cmp v0.6.0
I noticed that cmp.Diff alternates between regular and non-breaking space in +- column. One is way more likely to get regular space.
This behavior creates issues when output is compared verbatim, e.g. in testable examples:
func ExampleCmpRepr() {
type foo struct{ B, A int }
fmt.Printf("%#v\n", cmp.Diff(foo{A: 1}, foo{A: 2}))
// Output: " testnet.foo{\n \tB: 0,\n- \tA: 1,\n+ \tA: 2,\n }\n"
}
It fails occasionally with the following output. Using go test -bench=. somehow makes it more likely to manifest.
--- FAIL: ExampleCmpRepr (0.00s)
got:
"\u00a0\u00a0testnet.foo{\n\u00a0\u00a0\tB: 0,\n-\u00a0\tA: 1,\n+\u00a0\tA: 2,\n\u00a0\u00a0}\n"
want:
" testnet.foo{\n \tB: 0,\n- \tA: 1,\n+ \tA: 2,\n }\n"