diff --git a/cmp/compare_test.go b/cmp/compare_test.go index 13a3a4e..84f7353 100644 --- a/cmp/compare_test.go +++ b/cmp/compare_test.go @@ -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", }} } diff --git a/cmp/report_reflect.go b/cmp/report_reflect.go index 5b47420..33f0357 100644 --- a/cmp/report_reflect.go +++ b/cmp/report_reflect.go @@ -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) } diff --git a/cmp/testdata/diffs b/cmp/testdata/diffs index dee035d..81d5769 100644 --- a/cmp/testdata/diffs +++ b/cmp/testdata/diffs @@ -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{