Codebase list golang-github-imdario-mergo / 1b0ca7e2-597c-4e42-b83d-7f35bcd7ba7a/main issue129_test.go
1b0ca7e2-597c-4e42-b83d-7f35bcd7ba7a/main

Tree @1b0ca7e2-597c-4e42-b83d-7f35bcd7ba7a/main (Download .tar.gz)

issue129_test.go @1b0ca7e2-597c-4e42-b83d-7f35bcd7ba7a/main

b4faec0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")
	}
}