feat(Go-StudyExample):2021/02/09:新增merge源码阅读和单测代码

This commit is contained in:
Huangzj
2021-02-09 16:00:31 +08:00
parent 05f55b0eac
commit cf02f0bf10
51 changed files with 3712 additions and 1 deletions
@@ -0,0 +1,49 @@
package mergo_test
import (
"testing"
"github.com/imdario/mergo"
)
func TestIssue129Boolean(t *testing.T) {
type Foo struct {
A bool
B bool
}
src := Foo{
A: true,
B: false,
}
dst := Foo{
A: false,
B: true,
}
// Standard behavior
if err := mergo.Merge(&dst, src); err != nil {
t.Error(err)
}
if dst.A != true {
t.Errorf("expected true, got false")
}
if dst.B != true {
t.Errorf("expected true, got false")
}
// Expected behavior
dst = Foo{
A: false,
B: true,
}
if err := mergo.Merge(&dst, src, mergo.WithOverwriteWithEmptyValue); err != nil {
t.Error(err)
}
if dst.A != true {
t.Errorf("expected true, got false")
}
if dst.B != false {
t.Errorf("expected false, got true")
}
}