Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: have diff output ignore additions #318

Open
dprotaso opened this issue Jan 17, 2023 · 2 comments
Open

question: have diff output ignore additions #318

dprotaso opened this issue Jan 17, 2023 · 2 comments

Comments

@dprotaso
Copy link

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.

@dsnet
Copy link
Collaborator

dsnet commented Jan 18, 2023

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.

@mrwormhole
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants