Label structs when they are members of other structs.
Adds the type label for non-pointer struct fields.
diff --git a/formatter.go b/formatter.go
index 1161de7..c834d46 100644
--- a/formatter.go
+++ b/formatter.go
@@ -2,11 +2,12 @@
import (
"fmt"
- "github.com/kr/text"
"io"
"reflect"
"strconv"
"text/tabwriter"
+
+ "github.com/kr/text"
)
const (
@@ -156,7 +157,7 @@
if expand {
writeByte(pp, '\t')
}
- showTypeInStruct = f.Type.Kind() == reflect.Interface
+ showTypeInStruct = labelType(f.Type)
}
pp.printValue(getField(v, i), showTypeInStruct, true)
if expand {
@@ -275,6 +276,14 @@
return false
}
+func labelType(t reflect.Type) bool {
+ switch t.Kind() {
+ case reflect.Interface, reflect.Struct:
+ return true
+ }
+ return false
+}
+
func (p *printer) fmtString(s string, quote bool) {
if quote {
s = strconv.Quote(s)
diff --git a/formatter_test.go b/formatter_test.go
index 303f033..ec9bbca 100644
--- a/formatter_test.go
+++ b/formatter_test.go
@@ -19,6 +19,7 @@
type SA struct {
t *T
+ v T
}
type T struct {
@@ -55,9 +56,10 @@
},
{F(5), "pretty.F(5)"},
{
- SA{&T{1, 2}},
+ SA{&T{1, 2}, T{3, 4}},
`pretty.SA{
t: &pretty.T{x:1, y:2},
+ v: pretty.T{x:3, y:4},
}`,
},
{