aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2021-10-12 11:15:02 -0700
committerGitHub <noreply@github.com>2021-10-12 11:15:02 -0700
commit6faefd0594fae82639a62c23f0aed1451509dcc0 (patch)
tree7f30ca1ff28938cd6a4eec7f6189d4e233579295
parentf1773ad7bdb1ddccb1801c5b8ca4311cf0d301e4 (diff)
downloadgo-cmp-6faefd0594fae82639a62c23f0aed1451509dcc0.tar.gz
Reduce minimum length for specialize string diffing (#275)
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>
-rw-r--r--cmp/compare_test.go13
-rw-r--r--cmp/report_slices.go2
-rw-r--r--cmp/testdata/diffs12
3 files changed, 26 insertions, 1 deletions
diff --git a/cmp/compare_test.go b/cmp/compare_test.go
index 5f02a82..c7a409d 100644
--- a/cmp/compare_test.go
+++ b/cmp/compare_test.go
@@ -1338,6 +1338,19 @@ using the AllowUnexported option.`, "\n"),
x: struct{ X MyBytes }{MyBytes("\xde\xad\xbe\xef")},
y: struct{ X MyBytes }{},
reason: "MyBytes should not be printed as text since it is binary data",
+ }, {
+ label: label + "/ShortJSON",
+ x: `{
+ "id": 1,
+ "foo": true,
+ "bar": true,
+}`,
+ y: `{
+ "id": 1434180,
+ "foo": true,
+ "bar": true,
+}`,
+ reason: "short multiline JSON should prefer triple-quoted string diff as it is more readable",
}}
}
diff --git a/cmp/report_slices.go b/cmp/report_slices.go
index 9809228..68b5c1a 100644
--- a/cmp/report_slices.go
+++ b/cmp/report_slices.go
@@ -80,7 +80,7 @@ func (opts formatOptions) CanFormatDiffSlice(v *valueNode) bool {
}
// Use specialized string diffing for longer slices or strings.
- const minLength = 64
+ const minLength = 32
return vx.Len() >= minLength && vy.Len() >= minLength
}
diff --git a/cmp/testdata/diffs b/cmp/testdata/diffs
index 59afe6d..d207803 100644
--- a/cmp/testdata/diffs
+++ b/cmp/testdata/diffs
@@ -1122,6 +1122,18 @@
+ X: nil,
}
>>> TestDiff/Reporter/NonStringifiedNamedBytes
+<<< TestDiff/Reporter/ShortJSON
+ (
+ """
+ {
+- "id": 1,
++ "id": 1434180,
+ "foo": true,
+ "bar": true,
+ }
+ """
+ )
+>>> TestDiff/Reporter/ShortJSON
<<< TestDiff/EmbeddedStruct/ParentStructA/Inequal
teststructs.ParentStructA{
privateStruct: teststructs.privateStruct{