Skip to content

Commit

Permalink
Issue #89 closed
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio committed May 17, 2020
1 parent 3f3e57a commit d18586a
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions issue89_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package mergo

import (
"testing"
)

func TestIssue89Boolean(t *testing.T) {
type Foo struct {
Bar bool `json:"bar"`
}

src := Foo{Bar: true}
dst := Foo{Bar: false}

if err := Merge(&dst, src); err != nil {
t.Fatal(err)
}
if dst.Bar == false {
t.Fatalf("expected true, got false")
}
}

func TestIssue89MergeWithEmptyValue(t *testing.T) {
p1 := map[string]interface{}{
"A": 3, "B": "note", "C": true,
}
p2 := map[string]interface{}{
"B": "", "C": false,
}
if err := Merge(&p1, p2, WithOverwriteWithEmptyValue); err != nil {
t.Fatal(err)
}
testCases := []struct {
key string
expected interface{}
}{
{
"A",
3,
},
{
"B",
"",
},
{
"C",
false,
},
}
for _, tC := range testCases {
if p1[tC.key] != tC.expected {
t.Fatalf("expected %v in p1[%q], got %v", tC.expected, tC.key, p1[tC.key])
}
}
}

0 comments on commit d18586a

Please sign in to comment.