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

Add a Comparable helper #5

Open
mvdan opened this issue Jul 9, 2018 · 2 comments
Open

Add a Comparable helper #5

mvdan opened this issue Jul 9, 2018 · 2 comments
Labels
back burner on hold for now

Comments

@mvdan
Copy link
Contributor

mvdan commented Jul 9, 2018

I was just thinking that most of the types one might want to diff can already be compared for equality, as per the language spec.

So, we could add func Comparable(a, b interface{}) DiffWriteable. It would ensure that both params are of the same type, that both are slice types, and that both element types are comparable.

For example, this would be useful with integers, arrays, custom struct types, et cetera.

I'd still keep Strings, because for the foreseeable future, avoiding interface parameters will make the code faster and easier.

Potentially, we could also use the Equal method as defined in https://github.com/google/go-cmp.

@mvdan mvdan changed the title Add a Comparable helper? Add a Comparable helper Jul 9, 2018
@josharian
Copy link
Contributor

I have had a similar idea. Quoting from diff.go:

// TODO: consider adding an "it just works" test helper that accepts two slices (via interface{}),
// diffs them using Strings or Bytes or Slices (using reflect.DeepEqual) as appropriate,
// and calls t.Errorf with a generated diff if they're not equal.

My only hesitation is that it expand the API, and the API already feels kinda large. Let's leave this one on the back burner for a bit until someone has a concrete need for it (I don't yet), since it is easy to add and hard to remove.

@mvdan
Copy link
Contributor Author

mvdan commented Aug 28, 2019

Sure!

@josharian josharian added the back burner on hold for now label Aug 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back burner on hold for now
Projects
None yet
Development

No branches or pull requests

2 participants