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

Impose verbosity limit when formatting map keys #248

Merged
merged 2 commits into from Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions cmp/compare_test.go
Expand Up @@ -1276,6 +1276,17 @@ using the AllowUnexported option.`, "\n"),
y: MyComposite{},
wantEqual: false,
reason: "batched diffing for empty slices and nil slices",
}, {
label: label + "/LargeMapKey",
x: map[*[]byte]int{func() *[]byte {
b := make([]byte, 1<<20, 1<<20)
return &b
}(): 0},
y: map[*[]byte]int{func() *[]byte {
b := make([]byte, 1<<20, 1<<20)
return &b
}(): 0},
reason: "printing map keys should have some verbosity limit imposed",
}}
}

Expand Down
2 changes: 2 additions & 0 deletions cmp/report_reflect.go
Expand Up @@ -351,6 +351,8 @@ func formatMapKey(v reflect.Value, disambiguate bool, ptrs *pointerReferences) s
opts.PrintAddresses = disambiguate
opts.AvoidStringer = disambiguate
opts.QualifiedNames = disambiguate
opts.VerbosityLevel = maxVerbosityPreset
opts.LimitVerbosity = true
s := opts.FormatValue(v, reflect.Map, ptrs).String()
return strings.TrimSpace(s)
}
Expand Down
6 changes: 6 additions & 0 deletions cmp/testdata/diffs
Expand Up @@ -1008,6 +1008,12 @@
+ FloatsC: nil,
}
>>> TestDiff/Reporter/EmptySlices
<<< TestDiff/Reporter/LargeMapKey
map[*[]uint8]int{
- &⟪0xdeadf00f⟫⟪ptr:0xdeadf00f, len:1048576, cap:1048576⟫{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ...}: 0,
+ &⟪0xdeadf00f⟫⟪ptr:0xdeadf00f, len:1048576, cap:1048576⟫{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ...}: 0,
}
>>> TestDiff/Reporter/LargeMapKey
<<< TestDiff/EmbeddedStruct/ParentStructA/Inequal
teststructs.ParentStructA{
privateStruct: teststructs.privateStruct{
Expand Down