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

Reduce minimum length for specialized string diffing #275

Merged
merged 3 commits into from Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmp/compare_test.go
Expand Up @@ -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",
}}
}

Expand Down
2 changes: 1 addition & 1 deletion cmp/report_slices.go
Expand Up @@ -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
}

Expand Down
12 changes: 12 additions & 0 deletions cmp/testdata/diffs
Expand Up @@ -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{
Expand Down