Skip to content

Commit

Permalink
Merge 06b23e4 into 364ec7d
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Oct 20, 2018
2 parents 364ec7d + 06b23e4 commit 9388cb2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
5 changes: 5 additions & 0 deletions dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,18 @@ func (d *dumpState) dump(v reflect.Value, wasPtr, static bool, addr uintptr) {
d.w.Write(closeParenBytes)
break
}
if v.Len() == 0 {
d.dumpSlice(v)
break
}
// Remove pointers at or below the current depth from map used to detect
// circular refs.
for k, depth := range d.pointers {
if depth >= d.depth {
delete(d.pointers, k)
}
}
addr = v.Index(0).Addr().Pointer()
if pd, ok := d.pointers[addr]; ok && pd < d.depth {
d.w.Write(circularBytes)
break
Expand Down
30 changes: 22 additions & 8 deletions dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,7 @@ var sliceElementCycles = []struct {
// the cycle as the initial v seen by utter.Dump was not
// addressable.
want: `[]interface{}{
[]interface{}{
[]interface{}(<already shown>),
},
[]interface{}(<already shown>),
}
`,
},
Expand All @@ -900,9 +898,7 @@ var sliceElementCycles = []struct {
return &r
}(),
want: `&[]interface{}{
[]interface{}{
[]interface{}(<already shown>),
},
[]interface{}(<already shown>),
}
`,
},
Expand All @@ -913,7 +909,7 @@ var sliceElementCycles = []struct {
return &r
}(),
want: `&[]interface{}{
(*[]interface{})(<already shown>),
&[]interface{}(<already shown>),
}
`,
},
Expand Down Expand Up @@ -948,7 +944,25 @@ var sliceElementCycles = []struct {
return &r
}(),
want: `&utter_test.recurrence{
v: []interface{}(<already shown>),
v: []interface{}{
utter_test.recurrence{
v: []interface{}(<already shown>),
},
},
}
`,
},
{
v: func() interface{} {
type container struct {
v []int
}
return &container{[]int{1}}
}(),
want: `&utter_test.container{
v: []int{
int(1),
},
}
`,
},
Expand Down
4 changes: 2 additions & 2 deletions spew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func initSpewTests() {
{comPtrDefault, fCSFdump, spp, fmt.Sprintf("&&struct { *int } /*%p->%p*/ {\n int: &int /*%p*/ (10),\n}\n", spp, sp, v)},
{comPtrDefault, fCSFdump, c, fmt.Sprintf("[]interface{}{\n"+
" int( /*%p*/ 5),\n int( /*%p*/ 5),\n"+
" &int /*%[1]p*/ (5),\n &int /*%p*/ (5),\n}\n", &c[0], &c[1])},
" (*interface{}) /*%[1]p*/ (<already shown>),\n &int /*%p*/ (5),\n}\n", &c[0], &c[1])},
{comPtrDefault, fCSFdump, d, fmt.Sprintf("&struct { a [2]int; p *int } /*%p*/ {\n"+
" a: [2]int{\n int(0),\n"+
" int( /*%p*/ 10),\n },\n"+
Expand All @@ -193,7 +193,7 @@ func initSpewTests() {
" int(1): []interface{}{\n"+
" int( /*%p*/ 5),\n"+
" int( /*%p*/ 5),\n"+
" &int /*%[1]p*/ (5),\n"+
" (*interface{}) /*%[1]p*/ (<already shown>),\n"+
" &int /*%p*/ (5),\n },\n}\n", &c[0], &c[1])},
{bs8Default, fCSFdump, []byte{1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3}, "[]uint8{\n" +
" 0x01, 0x02, 0x03, 0x04, 0x05, 0x00, 0x01, 0x02, // |........|\n" +
Expand Down

0 comments on commit 9388cb2

Please sign in to comment.