Skip to content

Commit

Permalink
fix: result zero values
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin committed Feb 28, 2019
1 parent d02295f commit 5644a65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
22 changes: 8 additions & 14 deletions dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,11 @@ type T struct {
type Tbis struct {
Cbis string
Cter string
X *Tter
}

type Tter struct {
X string
}

func TestDumpStruct_Nested(t *testing.T) {

a := T{23, "foo bar", Tbis{"lol", "lol", &Tter{"X"}}}
a := T{23, "foo bar", Tbis{"lol", "lol"}}

out := &bytes.Buffer{}
err := dump.Fdump(out, a)
Expand All @@ -90,7 +85,6 @@ func TestDumpStruct_Nested(t *testing.T) {
T.B: foo bar
T.C.Cbis: lol
T.C.Cter: lol
T.C.X.X: X
`
assert.Equal(t, expected, out.String())

Expand All @@ -104,7 +98,7 @@ type TP struct {

func TestDumpStruct_NestedWithPointer(t *testing.T) {
i := 23
a := TP{&i, "foo bar", &Tbis{"lol", "lol", nil}}
a := TP{&i, "foo bar", &Tbis{"lol", "lol"}}

out := &bytes.Buffer{}
err := dump.Fdump(out, a)
Expand All @@ -129,8 +123,8 @@ func TestDumpStruct_Map(t *testing.T) {

a := TM{A: 23, B: "foo bar"}
a.C = map[string]Tbis{}
a.C["bar"] = Tbis{"lel", "lel", nil}
a.C["foo"] = Tbis{"lol", "lol", nil}
a.C["bar"] = Tbis{"lel", "lel"}
a.C["foo"] = Tbis{"lol", "lol"}

out := &bytes.Buffer{}
dumper := dump.NewEncoder(out)
Expand Down Expand Up @@ -158,8 +152,8 @@ __Type__: TM

func TestDumpArray(t *testing.T) {
a := []T{
{23, "foo bar", Tbis{"lol", "lol", nil}},
{24, "fee bor", Tbis{"lel", "lel", nil}},
{23, "foo bar", Tbis{"lol", "lol"}},
{24, "fee bor", Tbis{"lel", "lel"}},
}

out := &bytes.Buffer{}
Expand Down Expand Up @@ -199,8 +193,8 @@ func TestDumpStruct_Array(t *testing.T) {
A: 0,
B: "here",
C: []T{
{23, "foo bar", Tbis{"lol", "lol", nil}},
{24, "fee bor", Tbis{"lel", "lel", nil}},
{23, "foo bar", Tbis{"lol", "lol"}},
{24, "fee bor", Tbis{"lel", "lel"}},
},
D: []bool{true, false},
}
Expand Down
3 changes: 0 additions & 3 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ func (e *Encoder) Sdump(i interface{}) (string, error) {
}

func (e *Encoder) fdumpInterface(w map[string]interface{}, i interface{}, roots []string) error {
if reflect.ValueOf(i).Kind() == reflect.Ptr && reflect.ValueOf(i).IsNil() {
return nil
}
f := valueFromInterface(i)
if !validAndNotEmpty(f) {
if len(roots) == 0 {
Expand Down

0 comments on commit 5644a65

Please sign in to comment.