Add options to disable printing of type and length
This commit is contained in:
parent
346938d642
commit
49288ec620
|
@ -76,6 +76,13 @@ type ConfigState struct {
|
|||
// data structures in tests.
|
||||
DisableCapacities bool
|
||||
|
||||
// DisableTypes specifies whether to disable the printing of types.
|
||||
DisableTypes bool
|
||||
|
||||
// DisableLengths specifies whether to disable the printing of lengths.
|
||||
// This also disables the printing of capacities.
|
||||
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
|
||||
|
|
|
@ -100,6 +100,13 @@ The following configuration options are available:
|
|||
capacities for arrays, slices, maps and channels. This is useful when
|
||||
diffing data structures in tests.
|
||||
|
||||
* DisableTypes
|
||||
DisableTypes specifies whether to disable the printing of types.
|
||||
|
||||
* DisableLengths
|
||||
DisableLengths specifies whether to disable the printing of lengths.
|
||||
This also disables the printing of capacities.
|
||||
|
||||
* ContinueOnMethod
|
||||
Enables recursion into types after invoking error and Stringer interface
|
||||
methods. Recursion after method invocation is disabled by default.
|
||||
|
|
|
@ -266,15 +266,18 @@ func (d *dumpState) dump(v reflect.Value) {
|
|||
// Print type information unless already handled elsewhere.
|
||||
if !d.ignoreNextType {
|
||||
d.indent()
|
||||
if !d.cs.DisableTypes {
|
||||
d.w.Write(openParenBytes)
|
||||
d.w.Write([]byte(v.Type().String()))
|
||||
d.w.Write(closeParenBytes)
|
||||
d.w.Write(spaceBytes)
|
||||
}
|
||||
}
|
||||
d.ignoreNextType = false
|
||||
|
||||
// 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 +301,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
|
||||
|
|
Loading…
Reference in New Issue