Merge 0770b47fe5
into d8f796af33
This commit is contained in:
commit
c01f6f9bfc
|
@ -71,6 +71,11 @@ type ConfigState struct {
|
|||
// pointer addresses. This is useful when diffing data structures in tests.
|
||||
DisablePointerAddresses bool
|
||||
|
||||
// DisableLengths specifies whether to disable the printing of lengths
|
||||
// for arrays, slices, maps and channels. This is useful when diffing
|
||||
// data structures in tests.
|
||||
DisableLengths bool
|
||||
|
||||
// DisableCapacities specifies whether to disable the printing of capacities
|
||||
// for arrays, slices, maps and channels. This is useful when diffing
|
||||
// data structures in tests.
|
||||
|
|
12
spew/dump.go
12
spew/dump.go
|
@ -282,14 +282,18 @@ func (d *dumpState) dump(v reflect.Value) {
|
|||
case reflect.Map, reflect.String:
|
||||
valueLen = v.Len()
|
||||
}
|
||||
if valueLen != 0 || !d.cs.DisableCapacities && valueCap != 0 {
|
||||
|
||||
showLen := !d.cs.DisableLengths && valueLen != 0
|
||||
showCap := !d.cs.DisableCapacities && valueCap != 0
|
||||
|
||||
if showLen || showCap {
|
||||
d.w.Write(openParenBytes)
|
||||
if valueLen != 0 {
|
||||
if showLen {
|
||||
d.w.Write(lenEqualsBytes)
|
||||
printInt(d.w, int64(valueLen), 10)
|
||||
}
|
||||
if !d.cs.DisableCapacities && valueCap != 0 {
|
||||
if valueLen != 0 {
|
||||
if showCap {
|
||||
if showLen {
|
||||
d.w.Write(spaceBytes)
|
||||
}
|
||||
d.w.Write(capEqualsBytes)
|
||||
|
|
|
@ -132,6 +132,8 @@ func initSpewTests() {
|
|||
scsContinue := &spew.ConfigState{Indent: " ", ContinueOnMethod: true}
|
||||
scsNoPtrAddr := &spew.ConfigState{DisablePointerAddresses: true}
|
||||
scsNoCap := &spew.ConfigState{DisableCapacities: true}
|
||||
scsNoLen := &spew.ConfigState{DisableLengths: true}
|
||||
scsNoLenNoCap := &spew.ConfigState{DisableCapacities: true, DisableLengths: true}
|
||||
|
||||
// Variables for tests on types which implement Stringer interface with and
|
||||
// without a pointer receiver.
|
||||
|
@ -203,6 +205,10 @@ func initSpewTests() {
|
|||
{scsNoPtrAddr, fCSSdump, "", tptr, "(*spew_test.ptrTester)({\ns: (*struct {})({\n})\n})\n"},
|
||||
{scsNoCap, fCSSdump, "", make([]string, 0, 10), "([]string) {\n}\n"},
|
||||
{scsNoCap, fCSSdump, "", make([]string, 1, 10), "([]string) (len=1) {\n(string) \"\"\n}\n"},
|
||||
{scsNoLen, fCSSdump, "", make([]string, 0, 10), "([]string) (cap=10) {\n}\n"},
|
||||
{scsNoLen, fCSSdump, "", make([]string, 1, 10), "([]string) (cap=10) {\n(string) \"\"\n}\n"},
|
||||
{scsNoLenNoCap, fCSSdump, "", make([]string, 0, 10), "([]string) {\n}\n"},
|
||||
{scsNoLenNoCap, fCSSdump, "", make([]string, 1, 10), "([]string) {\n(string) \"\"\n}\n"},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue