Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ func (p *printer) printValue(v reflect.Value, showType, quote bool) {
}

if showType {
io.WriteString(p, t.String())
if t.Name() == "" {
io.WriteString(p, "struct")
} else {
io.WriteString(p, t.String())
}
}
writeByte(p, '{')
if nonzero(v) {
Expand Down
25 changes: 25 additions & 0 deletions formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ func (f F) Format(s fmt.State, c rune) {

var long = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

type Embedded struct {
Foo string `json:"foo"`
Bar struct {
A int `json:"a"`
B float64 `json:"b"`
C string `json:"c"`
} `json:"bar"`
}

var embedded Embedded

func init() {
embedded.Foo = "foo"
embedded.Bar.A = 1
embedded.Bar.B = 1.1
embedded.Bar.C = "bar"
}

var gosyntax = []test{
{nil, `nil`},
{"", `""`},
Expand Down Expand Up @@ -132,6 +150,13 @@ var gosyntax = []test{
longFieldName: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
otherLongFieldName: nil,
},
}`,
},
{
&embedded,
`&pretty.Embedded{
Foo: "foo",
Bar: struct{A:1, B:1.1, C:"bar"},
}`,
},
}
Expand Down