go-cmp
go-cmp copied to clipboard
question: have diff output ignore additions
From https://github.com/google/go-cmp/blob/v0.5.9/cmp/compare.go#L113
Diff returns a human-readable report of the differences between two values: // y - x. ... func Diff(x, y interface{}, opts ...Option)
Is there a way to ignore things added iny in the output? I realize I could post process the diff output and drop lines with + but without the preceeding - but wondering if there's a better way.
Not really. The behavior of cmp.Diff is to be symmetric such that the result of cmp.Equal(x, y) and cmp.Equal(y, x) are identical.
Functionally ignoring insertions implies an assymetric comparison, which is not something this package supports. Doing so would need to carefully think through the implications and how an asymmetric comparison would interact with existing cmp.Options that assume symmetric properties of equality.
@dsnet why is it renamed as x and y? I know many people do mistakes due to this, can't it be just got and want like in the shared example?