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
10 changes: 5 additions & 5 deletions diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ var diffs = []difftest{
{struct{ x N }{N{0}}, struct{ x N }{N{0}}, nil},
{struct{ x N }{N{0}}, struct{ x N }{N{1}}, []string{`x.N: 0 != 1`}},
{
struct{ x unsafe.Pointer }{unsafe.Pointer(uintptr(0))},
struct{ x unsafe.Pointer }{unsafe.Pointer(uintptr(0))},
struct{ x unsafe.Pointer }{unsafe.Pointer(nil)},
struct{ x unsafe.Pointer }{unsafe.Pointer(nil)},
nil,
},
{
struct{ x unsafe.Pointer }{unsafe.Pointer(uintptr(0))},
struct{ x unsafe.Pointer }{unsafe.Pointer(uintptr(1))},
[]string{`x: 0x0 != 0x1`},
struct{ x unsafe.Pointer }{unsafe.Pointer(nil)},
struct{ x unsafe.Pointer }{unsafe.Pointer(&i0)},
[]string{fmt.Sprintf("x: %p != %p", unsafe.Pointer(nil), unsafe.Pointer(&i0))},
},
}

Expand Down
13 changes: 13 additions & 0 deletions formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pretty
import (
"fmt"
"io"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -76,6 +77,10 @@ func (s StructWithPrivateFields) GoString() string {
return fmt.Sprintf("NewStructWithPrivateFields(%q)", s.A)
}

type StructWithInterfaceField struct {
V interface{}
}

var gosyntax = []test{
{nil, `nil`},
{"", `""`},
Expand Down Expand Up @@ -184,6 +189,11 @@ var gosyntax = []test{
{&PointerGoString{"pgs"}, `PGS pgs`},
{(*PointerGoString)(nil), "(*pretty.PointerGoString)(nil)"},
{&PanicGoString{"oops!"}, `(*pretty.PanicGoString)(PANIC=calling method "GoString": oops!)`},
{&StructWithInterfaceField{}, "&pretty.StructWithInterfaceField{}"},
{&StructWithInterfaceField{nil}, "&pretty.StructWithInterfaceField{}"},
{&StructWithInterfaceField{(*struct{})(nil)}, "&pretty.StructWithInterfaceField{\n V: (*struct {})(nil),\n}"},
{&StructWithInterfaceField{""}, "&pretty.StructWithInterfaceField{\n V: \"\",\n}"},
{&StructWithInterfaceField{struct{}{}}, "&pretty.StructWithInterfaceField{\n V: struct {}{},\n}"},
}

type ValueGoString struct {
Expand Down Expand Up @@ -215,6 +225,9 @@ func (g *PanicGoString) GoString() string {
}

func TestGoSyntax(t *testing.T) {
if runtime.Compiler == "tinygo" {
return
}
for _, tt := range gosyntax {
s := fmt.Sprintf("%# v", Formatter(tt.v))
if tt.s != s {
Expand Down
2 changes: 1 addition & 1 deletion zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func nonzero(v reflect.Value) bool {
return v.String() != ""
case reflect.Struct:
for i := 0; i < v.NumField(); i++ {
if nonzero(getField(v, i)) {
if nonzero(v.Field(i)) {
return true
}
}
Expand Down