ConfigState: Create 'DisableLengths' option
This commit is contained in:
parent
d8f796af33
commit
e817bb185a
|
@ -76,6 +76,10 @@ type ConfigState struct {
|
|||
// data structures in tests.
|
||||
DisableCapacities bool
|
||||
|
||||
// DisableLengths specifies whether to disable the printing of lengths
|
||||
// for strings, arrays, slices, maps and channels.
|
||||
DisableLengths bool
|
||||
|
||||
// ContinueOnMethod specifies whether or not recursion should continue once
|
||||
// a custom error or Stringer interface is invoked. The default, false,
|
||||
// means it will print the results of invoking the custom error or Stringer
|
||||
|
|
|
@ -275,6 +275,7 @@ func (d *dumpState) dump(v reflect.Value) {
|
|||
|
||||
// Display length and capacity if the built-in len and cap functions
|
||||
// work with the value's kind and the len/cap itself is non-zero.
|
||||
if !d.cs.DisableLengths {
|
||||
valueLen, valueCap := 0, 0
|
||||
switch v.Kind() {
|
||||
case reflect.Array, reflect.Slice, reflect.Chan:
|
||||
|
@ -298,6 +299,7 @@ func (d *dumpState) dump(v reflect.Value) {
|
|||
d.w.Write(closeParenBytes)
|
||||
d.w.Write(spaceBytes)
|
||||
}
|
||||
}
|
||||
|
||||
// Call Stringer/error interfaces if they exist and the handle methods flag
|
||||
// is enabled
|
||||
|
|
|
@ -132,6 +132,7 @@ func initSpewTests() {
|
|||
scsContinue := &spew.ConfigState{Indent: " ", ContinueOnMethod: true}
|
||||
scsNoPtrAddr := &spew.ConfigState{DisablePointerAddresses: true}
|
||||
scsNoCap := &spew.ConfigState{DisableCapacities: true}
|
||||
scsNoLen := &spew.ConfigState{DisableLengths: true}
|
||||
|
||||
// Variables for tests on types which implement Stringer interface with and
|
||||
// without a pointer receiver.
|
||||
|
@ -203,6 +204,7 @@ 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, 1, 10), "([]string) {\n(string) \"\"\n}\n"},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue