Age | Commit message (Collapse) | Author |
|
This helper function makes it easier to specify that comparable types
are safe to directly compare with the == operator in Go.
The API does not use generics as it follows existing options like
cmp.AllowUnexported, cmpopts.IgnoreUnexported, or cmpopts.IgnoreTypes.
While generics provides type safety, the user experience is not as nice.
Our current API allows multiple types to be specified:
cmpopts.EquateComparable(netip.Addr{}, netip.Prefix{})
While generics would not allow variadic arguments:
cmpopts.EquateComparable[netip.Addr]()
cmpopts.EquateComparable[netip.Prefix]()
Bump mininimum supported Go to 1.18 for net/netip type.
Start testing on Go 1.21.
Fixes #339
|
|
GoDoc now supports hot linking to specific Go identifiers.
Use that feature to enhance the usability of cmp docs.
Since cmp lacks a direct dependency on cmpopts,
you are forced to use the fully-qualified import path
to references identifiers in the cmpopts package.
It can future improvements to the go/doc to handle this case,
either by rendering the doc with short form,
or by detecting the use of cmpopts from the unit tests as well
(since those can break circular dependencies).
|
|
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
|
|
|
|
|
|
Having go-cmp panic when using the purego build tag makes it hard to use
go-cmp for testing packages that themselves have purego fallbacks.
Since go-cmp can't implement its functionality without unsafe (the
"fallback" panics) and since environments that prohibit unsafe are much
less common these days anyway, simply remove purego code entirely.
Fixes #283.
|
|
If the string has many characters that require escape sequences to print,
then we need to take that into consideration and avoid byte-by-byte diffing.
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
|
|
* Run tests on Go 1.19
* Format comment
Finish the rest of the work for https://github.com/google/go-cmp/pull/304
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
|
|
The value.TypeString function is what the rest of the package uses
and is slightly cleaner than using reflect.Type.String.
Updates #305
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
|
|
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
|
|
|
|
This allows the GoDoc to take advantage of new markup syntax
introduced in Go 1.19. This does not require that our minimum
supported version be bumped to Go 1.19 since the pkgsite renders
our godoc regardless of supported Go version.
|
|
Now that Go 1.13 is the minimum version, we can use the reflect.Value.IsZero
method instead of our own internal/value.IsZero function.
Interestingly, our IsZero function pre-dates the IsZero method,
but fortunately has the exact same semantics, since both are targetting
semantics defined by the Go language specification.
|
|
|
|
Versions older than Go 1.13 are no longer in use. Remove unnecessary
dependencies.
|
|
If a slice of bytes is mostly text, format them as text
instead of as []byte literal with hexadecimal digits.
Avoid always printing the type. This is technically invalid Go code,
but is unnecessary in many cases since the type is inferred
from the parent concrete type.
Fixes #272
|
|
When printing a pointer, only elide the type for unnamed pointers.
Otherwise, we can run into situations where named and unnamed pointers
format the same way in indistinguishable ways.
When printing an interview, never skip the interface type.
Whether we skip printing the type should be determined by the
parent containers, and not locally determined.
For examples, interface values within a struct, slice, or map
will always be elided since they can be inferred.
|
|
|
|
Starting with Go 1.17, //go:build lines are preferred over // +build
lines, see https://golang.org/doc/go1.17#build-lines and
https://golang.org/design/draft-gobuild for details.
This change was generated by running Go 1.17 go fmt ./... which
automatically adds //go:build lines based on the existing // +build
lines.
Also update the corresponding GitHub action to use Go 1.17 gofmt.
|
|
Now that Go 1.11 is the minimally supported version,
we can drop some local hacks to work around bugs in
reflect that were present in Go1.9.
|
|
|
|
The original threshold of 64 was chosen without much thought.
Lower it to 32 now that we have some concrete examples
that it is aesthetically better.
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
|
|
See golang/go#33232.
|
|
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
|
|
|
|
Some aggressive dependency checks flag the use of md5.
Switch to sha256 as it accomplishes the same purpose.
|
|
Fix textual printing of byte slices
|
|
There are two bugs being fixed:
1. The hueristic for whether a slice of byte looks like text
should check whether a rune IsPrint OR IsSpace, and not both.
Only a single rune (i.e., U+0020) ever satisfies both conditions.
Previously, it would print as:
MyBytes{0x68, 0x65, 0x6c, 0x6c, 0x6f}
and now it would now print as:
MyBytes(MyBytes("hello"))
2. If we're printing as string, then we should set skipType=true
since we already explicitly format the value with the type.
Previously, it would print as:
MyBytes(MyBytes("hello"))
and now it would now print as:
MyBytes("hello")
|
|
Rename the shadowed variable i to j for better readability.
|
|
Address some minor issues flagged by staticcheck.
None of these affect the correctness of the package.
|
|
The previous heuristic of treating strings as binary data
if it contains any invalid UTF-8 was too strict.
Loosen the heuristic to check if most of the characters
are printable text.
Fixes #257
|
|
Avoid diffing by lines if it turns out to be significantly less
efficient than diffing by bytes.
Before this change:
(
"""
- d5c14bdf6bac81c27afc5429500ed750
- 25483503b557c606dad4f144d27ae10b
- 90bdbcdbb6ea7156068e3dcfb7459244
- 978f480a6e3cced51e297fbff9a506b7
+ Xd5c14bdf6bac81c27afc5429500ed750
+ X25483503b557c606dad4f144d27ae10b
+ X90bdbcdbb6ea7156068e3dcfb7459244
+ X978f480a6e3cced51e297fbff9a506b7
"""
)
After this change:
strings.Join({
+ "X",
"d5c14bdf6bac81c27afc5429500ed750\n",
+ "X",
"25483503b557c606dad4f144d27ae10b\n",
+ "X",
"90bdbcdbb6ea7156068e3dcfb7459244\n",
+ "X",
"978f480a6e3cced51e297fbff9a506b7\n",
}, "")
|
|
Even with an optimal diffing algoritm, coalescing adjacent edit groups
may cause the corresponding pair of strings for an edit group to have
leading or trailing spans of equal elements.
While this is technically a correct representation of a diff,
it is a suboptimal outcome. As such, scan through all unequal groups and
move leading/trailing equal spans to the preceding/succeeding equal group.
Before this change:
strings.Join({
"org-4747474747474747,bucket-4242424242424242:m,tag1=a,tag2=aa",
- ",#=_value _value=2 ",
+ " _value=2 ",
`11 org-4747474747474747,bucket-4242424242424242:m,tag1=a,tag2=bb`,
- ",#=_value _value=2 2",
+ " _value=2 2",
`1 org-4747474747474747,bucket-4242424242424242:m,tag1=b,tag2=cc`,
- ",#=_value",
` _value=1 21 org-4747474747474747,bucket-4242424242424242:m,tag1`,
"=a,tag2",
- "=dd,#=_value",
+ "=dd",
` _value=3 31 org-4747474747474747,bucket-4242424242424242:m,tag1`,
- "=c,#=_value",
+ "=c",
` _value=4 41 `,
}, "")
After this change:
strings.Join({
"org-4747474747474747,bucket-4242424242424242:m,tag1=a,tag2=aa",
- ",#=_value",
` _value=2 11 org-4747474747474747,bucket-4242424242424242:m,tag1`,
"=a,tag2=bb",
- ",#=_value",
` _value=2 21 org-4747474747474747,bucket-4242424242424242:m,tag1`,
"=b,tag2=cc",
- ",#=_value",
` _value=1 21 org-4747474747474747,bucket-4242424242424242:m,tag1`,
"=a,tag2=dd",
- ",#=_value",
` _value=3 31 org-4747474747474747,bucket-4242424242424242:m,tag1`,
"=c",
- ",#=_value",
` _value=4 41 `,
}, "")
|
|
s/seperate/separate/
|
|
FormatDiff should only set the verbosity to 3 if the current verbosity
is lower than 3. Otherwise, it may remove an intended higher verbosity
setting causing the reporter output to not differentiate between
two large values that are different at the end.
While we are at it, increase the maxVerbosityPreset to 6.
|
|
Specialized diffing strings and slices should occur for
interface types where both values have the same concrete type.
This is especially relevant for protocmp.Transform,
which transforms every proto.Message as a map[string]interface{}.
|
|
Add Go 1.16 to the GitHub actions test coverage matrix.
Also switch the gofmt check to only run on Go 1.16, i.e. the latest
supported version.
|
|
Use the standard definition of errors.Is to implement compareErrors with
≥go1.13. Retain the implementation using golang.org/x/xerrors for versions <go1.13.
This will allow packages using newer Go versions and already relying on
the errors package to get rid of the transitive dependency on
golang.org/x/xerrors.
|
|
Map keys should have a sensible verbosity limit imposed,
otherwise the reporter can end up printing a massive data structure
that cannot reasonably fit in memory.
|
|
A previous attempt to add non-determinism to the diffing algorithm
unfortunately broke the algorithm for half the cases.
This change modifies the algorithm to truly switch between starting
with a forward search versus a reverse search.
The main for-loop of Difference would switch repeatedly between
performing a forward search, then a reverse search, and vice-versa.
Since we can't jump into the middle of a for-loop to start with the
reverse search first, we use a series of labels and goto statements
to accomplish the same effect.
Fixes #238
|
|
Use a GitHub action to run test on each push and pull request.
We test across a matrix covering Linux and MacOSX, and Go 1.8 to 1.15.
|
|
The description inaccurately describes the operation of Diff,
which is y - x, where a '+' prefix denotes elements added from y
and a '-' prefix denotes elements removed from x.
For example:
// Consider this call to Diff and its result.
x y
cmp.Diff({b:2, c:3}, {a:1, b:2}) => {+a:1, b:2, -c:3}
// Consider the same in mathematical notation.
y - x
{a:1, b:2} - {b:2, c:3} = {+a:1, b:2, -c:3}
|
|
This reverts commit ab46b8bd0abd4c4557cc4709ad7ae12d47570603.
The upstream change in Go1.16 has been rolled back.
See golang/go#42123
|
|
In Go1.16, the reflect.Type.NumMethod method will no longer report
unexported fields, matching the documented behavior on the method.
This means that t.NumMethod() == 0 is no longer a reliable means
to detect whether an interface type is the empty interface or not.
Fix the code to check whether the empty interface itself implements
the target type.
|
|
Add an example for IgnoreFields. This resuses the test data from the example
in the cmp package to provide consistency between examples.
|
|
There is no LICENSE.md file, but there is a LICENSE file.
|
|
If cmp panics because it is trying to access an unexported field,
specially suggest the use of cmpopts.EquateErrors if the parent type
implements the error interface.
Fixes #233
|
|
|
|
Fix the documentation on Diff. It was mentioning the plus or minus sign being printed if the field was added to y or removed from y, but both are the same. Fix it so that it properly mentions the use of a minus sign for elements removed from x.
|
|
For strings, []bytes containing text data, Error method output, and
String method output, use the triple-quoted syntax.
This improves readability by presenting the data more naturally
compared to a single-line quoted string with many escaped characters.
|