From d18586a916fbfecc94cc6f6bf1f8a9283667190a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dario=20Casta=C3=B1=C3=A9?= Date: Sun, 17 May 2020 16:40:14 +0200 Subject: [PATCH] Issue #89 closed --- issue89_test.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 issue89_test.go diff --git a/issue89_test.go b/issue89_test.go new file mode 100644 index 0000000..eab7b0a --- /dev/null +++ b/issue89_test.go @@ -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]) + } + } +}