From 39f1f00ca486bae8673d205bfcca74385422d03a Mon Sep 17 00:00:00 2001 From: yassinebenaid Date: Sun, 17 Nov 2024 08:10:38 +0100 Subject: [PATCH] remove the capacity and length part if input is an array --- dumper.go | 18 +++++++++++------- testdata/slices.txt | 8 ++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/dumper.go b/dumper.go index c39b55e..b92d47e 100644 --- a/dumper.go +++ b/dumper.go @@ -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++ diff --git a/testdata/slices.txt b/testdata/slices.txt index dbf044d..f4faead 100644 --- a/testdata/slices.txt +++ b/testdata/slices.txt @@ -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, }, @@ -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, },