diff --git a/diff_test.go b/diff_test.go index 08ec64b..6a0af24 100644 --- a/diff_test.go +++ b/diff_test.go @@ -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))}, }, } diff --git a/formatter_test.go b/formatter_test.go index 6e27b27..77c273d 100644 --- a/formatter_test.go +++ b/formatter_test.go @@ -3,6 +3,7 @@ package pretty import ( "fmt" "io" + "runtime" "strings" "testing" "time" @@ -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`}, {"", `""`}, @@ -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 { @@ -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 { diff --git a/zero.go b/zero.go index abb5b6f..b8cb18f 100644 --- a/zero.go +++ b/zero.go @@ -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 } }