Skip to content

Commit

Permalink
remove the capacity and length part if input is an array
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinebenaid committed Nov 17, 2024
1 parent dbfec3c commit 39f1f00
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
18 changes: 11 additions & 7 deletions dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,20 @@ func (d *Dumper) dumpSlice(v reflect.Value) {
d.ptrTag = 0
}

if v.Kind() == reflect.Slice && v.IsNil() {
length := v.Len()

if v.Kind() == reflect.Slice {
if v.IsNil() {
d.buf.WriteString(__(d.Theme.Types, v.Type().String()))
d.writeNil()
d.buf.WriteString(tag)
return
}
d.buf.WriteString(__(d.Theme.Types, fmt.Sprintf("%s:%d:%d", v.Type(), length, v.Cap())))
} else {
d.buf.WriteString(__(d.Theme.Types, v.Type().String()))
d.writeNil()
d.buf.WriteString(tag)
return
}

length := v.Len()

d.buf.WriteString(__(d.Theme.Types, fmt.Sprintf("%s:%d:%d", v.Type(), length, v.Cap())))
d.buf.WriteString(__(d.Theme.Braces, fmt.Sprintf(" {%s", tag)))

d.depth++
Expand Down
8 changes: 4 additions & 4 deletions testdata/slices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ godump_test.Slice:13:24 {
nil,
},
[]godump_test.Slice(nil),
[2]int:2:2 {
[2]int {
1,
2,
},
[2]interface {}:2:2 {
[2]interface {} {
nil,
nil,
},
Expand All @@ -47,11 +47,11 @@ godump_test.Slice:13:24 {
nil,
},
[]godump_test.Slice(nil),
[2]int:2:2 {
[2]int {
1,
2,
},
[2]interface {}:2:2 {
[2]interface {} {
nil,
nil,
},
Expand Down

0 comments on commit 39f1f00

Please sign in to comment.