Skip to content

Commit

Permalink
Reduce API complexity - drop elide default types
Browse files Browse the repository at this point in the history
The inclusion of elide default types was a half-way measure toward what
we have with option to elide statically defined types now. The
interaction between the two while completely definable are difficult to
reason about and the capaicty to elide default types is not really
useful.
  • Loading branch information
kortschak committed Mar 23, 2015
1 parent 7d1c146 commit 48ec2f9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 58 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,9 @@ options. See the ConfigState documentation for more details.
* IgnoreUnexported
Specifies that unexported fields should be ignored.
* ElideDefaultTypes
ElideDefaultTypes specifies that default built-in types' (int, float64,
string and bool) type information should not be printed in a dump.
* ElideImplicitTypes
ElideImplicitType specifies that type information defined by context
should not be printed in a dump.
* ElideType
ElideType specifies that type information defined by context should
not be printed in a dump.
* SortKeys
Specifies map keys should be sorted before being printed. Use
Expand Down
13 changes: 4 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,9 @@ type ConfigState struct {
// ignored during a dump.
IgnoreUnexported bool

// ElideDefaultTypes specifies that default built-in types' (int, float64,
// string and bool) type information should not be printed in a dump.
ElideDefaultTypes bool

// ElideImplicitType specifies that type information defined by context
// should not be printed in a dump.
ElideImplicitTypes bool
// ElideType specifies that type information defined by context should
// not be printed in a dump.
ElideType bool

// SortKeys specifies map keys should be sorted before being printed. Use
// this to have a more deterministic, diffable output. Note that only
Expand Down Expand Up @@ -115,8 +111,7 @@ func (c *ConfigState) Sdump(a interface{}) string {
// BytesWidth: 16
// CommentBytes: true
// IgnoreUnexported: false
// ElideDefaultTypes: false
// ElideImplicitTypes: false
// ElideType: false
// SortKeys: false
func NewDefaultConfig() *ConfigState {
return &ConfigState{Indent: " ", BytesWidth: 16, CommentBytes: true}
Expand Down
10 changes: 3 additions & 7 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ The following configuration options are available:
* IgnoreUnexported
Specifies that unexported fields should be ignored.
* ElideDefaultTypes
ElideDefaultTypes specifies that default built-in types' (int, float64,
string and bool) type information should not be printed in a dump.
* ElideImplicitTypes
ElideImplicitType specifies that type information defined by context
should not be printed in a dump.
* ElideType
ElideType specifies that type information defined by context should
not be printed in a dump.
* SortKeys
Specifies map keys should be sorted before being printed. Use
Expand Down
9 changes: 3 additions & 6 deletions dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,9 @@ func (d *dumpState) dump(v reflect.Value, wasPtr, static bool) {

typ := v.Type()
wantType := true
defType := !wasPtr && isDefault(typ)
if d.cs.ElideDefaultTypes {
wantType = !defType
}
if d.cs.ElideImplicitTypes {
wantType = wantType && (!(static || defType) || isCompound(kind)) && !(kind == reflect.Interface && v.IsNil())
if d.cs.ElideType {
defType := !wasPtr && isDefault(typ)
wantType = (!(static || defType) || isCompound(kind)) && !(kind == reflect.Interface && v.IsNil())
}

// Print type information unless already handled elsewhere.
Expand Down
41 changes: 12 additions & 29 deletions spew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,9 @@ func initSpewTests() {
ignUnexDefault := utter.NewDefaultConfig()
ignUnexDefault.IgnoreUnexported = true

// Elide default builtin types.
elideDefault := utter.NewDefaultConfig()
elideDefault.ElideDefaultTypes = true

// Elide implicit types.
elideImplDefault := utter.NewDefaultConfig()
elideImplDefault.ElideImplicitTypes = true

// Use both elision methods.
elideBothDefault := utter.NewDefaultConfig()
elideBothDefault.ElideImplicitTypes = true
elideBothDefault.ElideDefaultTypes = true
elideTypeDefault := utter.NewDefaultConfig()
elideTypeDefault.ElideType = true

// depthTester is used to test max depth handling for structs, array, slices
// and maps.
Expand All @@ -139,29 +130,21 @@ func initSpewTests() {
{ignUnexDefault, fCSFdump, Foo{Bar{flag: 1}, map[interface{}]interface{}{"one": true}},
"utter_test.Foo{\n ExportedField: map[interface{}]interface{}{\n string(\"one\"): bool(true),\n },\n}\n",
},
{elideDefault, fCSFdump, float64(1), "1.0\n"},
{elideDefault, fCSFdump, float32(1), "float32(1)\n"},
{elideDefault, fCSFdump, int(1), "1\n"},
{elideDefault, fCSFdump, Foo{Bar{flag: 1}, map[interface{}]interface{}{"one": true}}, "utter_test.Foo{\n" +
" unexportedField: utter_test.Bar{\n flag: utter_test.Flag(1),\n data: uintptr(0),\n },\n" +
" ExportedField: map[interface{}]interface{}{\n \"one\": true,\n },\n}\n",
},
{elideDefault, fCSFdump, []interface{}{true, 1.0, float32(1), "one", 1, 'a'},
{elideTypeDefault, fCSFdump, float64(1), "1.0\n"},
{elideTypeDefault, fCSFdump, float32(1), "float32(1)\n"},
{elideTypeDefault, fCSFdump, int(1), "1\n"},
{elideTypeDefault, fCSFdump, []interface{}{true, 1.0, float32(1), "one", 1, 'a'},
"[]interface{}{\n true,\n 1.0,\n float32(1),\n \"one\",\n 1,\n int32(97),\n}\n",
},
{elideImplDefault, fCSFdump, Foo{Bar{flag: 1}, map[interface{}]interface{}{"one": true}}, "utter_test.Foo{\n" +
" unexportedField: utter_test.Bar{\n flag: 1,\n data: 0,\n },\n" +
" ExportedField: map[interface{}]interface{}{\n \"one\": true,\n },\n}\n",
},
{elideImplDefault, fCSFdump, map[interface{}]interface{}{"one": nil}, "map[interface{}]interface{}{\n \"one\": nil,\n}\n"},
{elideImplDefault, fCSFdump, float32(1), "float32(1)\n"},
{elideImplDefault, fCSFdump, float64(1), "1.0\n"},
{elideImplDefault, fCSFdump, func() *float64 { f := 1.0; return &f }(), "&float64(1)\n"},
{elideImplDefault, fCSFdump, []float32{1, 2, 3, 4, 5}, "[]float32{\n 1.0,\n 2.0,\n 3.0,\n 4.0,\n 5.0,\n}\n"},
{elideBothDefault, fCSFdump, Foo{Bar{flag: 1}, map[interface{}]interface{}{"one": true}}, "utter_test.Foo{\n" +
{elideTypeDefault, fCSFdump, Foo{Bar{flag: 1}, map[interface{}]interface{}{"one": true}}, "utter_test.Foo{\n" +
" unexportedField: utter_test.Bar{\n flag: 1,\n data: 0,\n },\n" +
" ExportedField: map[interface{}]interface{}{\n \"one\": true,\n },\n}\n",
},
{elideTypeDefault, fCSFdump, map[interface{}]interface{}{"one": nil}, "map[interface{}]interface{}{\n \"one\": nil,\n}\n"},
{elideTypeDefault, fCSFdump, float32(1), "float32(1)\n"},
{elideTypeDefault, fCSFdump, float64(1), "1.0\n"},
{elideTypeDefault, fCSFdump, func() *float64 { f := 1.0; return &f }(), "&float64(1)\n"},
{elideTypeDefault, fCSFdump, []float32{1, 2, 3, 4, 5}, "[]float32{\n 1.0,\n 2.0,\n 3.0,\n 4.0,\n 5.0,\n}\n"},
}
}

Expand Down

0 comments on commit 48ec2f9

Please sign in to comment.