-
Notifications
You must be signed in to change notification settings - Fork 55
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 option that causes nil slices to equal empty slices. #27
Conversation
Often times when testing, the difference between a slice that is nil and a slice that contains zero elements isn't useful. This change adds the NilSlicesAreEmpty variable, which is initially false to retain backward compatibility. When set to true, slices are compared by length rather than by nilness. Care has been taken to ensure that the resulting diff still indicates that a slice is nil versus empty.
I'm ok with the option, but can you refactor the logic a little to make it easier to follow? I think in original code, the block on line 276 that starts with For tests, a = a[:1]
b = b[:0] because |
This resolves cases where the variables are declared, but unused.
Note: In a stunning turn of events, git was used poorly. The additional logic cannot be contained within the block as you suggest. As expressed in the PR, the primary branching point must occur at When I think the only revision that needs to be made here is to move the As for the tests, I've moved the additional cases in TestSlice to a separate TestEmptySlice function. All additional cases have also been commented to make them easier to distinguish. |
Hello, has there been any progress on this PR? I've just started using this library and stumbled across a case where I would like an empty slice to equal nil. I can just implement an Equal method but I do believe some people would benefit from having this feature. |
Yeah, just need to fix the merge conflict and double check the tests. Will do that and cut a new release soon. |
Released as v1.0.5 |
Often times when testing, the difference between a slice that is nil and a slice that contains zero elements isn't useful. This change adds the NilSlicesAreEmpty variable, which is initially false to retain backward compatibility. When set to true, slices are compared by length rather than by nilness. Care has been taken to ensure that the resulting diff still indicates that a slice is nil versus empty.