diff --git a/coalescer.go b/coalescer.go index 75e2f19..7094070 100644 --- a/coalescer.go +++ b/coalescer.go @@ -81,8 +81,9 @@ func (c *coalescer) defaultDeepMerge(v1, v2 reflect.Value) (reflect.Value, error return c.deepMergeSlice(v1, v2) case reflect.Array: return c.deepMergeArray(v1, v2) + default: + return c.deepMergeAtomic(v1, v2) } - return c.deepMergeAtomic(v1, v2) } // defaultDeepCopy is the default implementation of DeepCopyFunc. It is used when the coalescer is @@ -111,6 +112,7 @@ func (c *coalescer) defaultDeepCopy(v reflect.Value) (reflect.Value, error) { return c.deepCopySlice(v) case reflect.Array: return c.deepCopyArray(v) + default: + return c.deepCopyAtomic(v) } - return c.deepCopyAtomic(v) } diff --git a/go.mod b/go.mod index f8ddd73..2651724 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ module github.com/adutra/goalesce -go 1.18 +go 1.22 -require github.com/stretchr/testify v1.7.1 +require github.com/stretchr/testify v1.9.0 require ( - github.com/davecgh/go-spew v1.1.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 2dca7c9..4eb7711 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,17 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/options.go b/options.go index ef7f76f..838ece4 100644 --- a/options.go +++ b/options.go @@ -105,20 +105,22 @@ func WithAtomicMerge(t reflect.Type) Option { // "trileans", that is, a type with 3 possible values: nil (its zero-value), false and true // (contrary to booleans, with trileans false is NOT a zero-value). // The merge of trileans obeys the following rules: -// v1 v2 merged -// nil nil nil -// nil false false -// nil true true -// false nil false -// false false false -// false true true -// true nil true -// true false false -// true true true +// +// v1 v2 merged +// nil nil nil +// nil false false +// nil true true +// false nil false +// false false false +// false true true +// true nil true +// true false false +// true true true +// // The biggest difference with regular boolean pointers is that DeepMerge(&true, &false) will return // &true for boolean pointers, while with trileans, it will return &false. func WithTrileanMerge() Option { - return WithAtomicMerge(reflect.PtrTo(reflect.TypeOf(false))) + return WithAtomicMerge(reflect.PointerTo(reflect.TypeOf(false))) } // WithTypeMerger will defer the merge of the given type to the given custom merger. This option diff --git a/options_test.go b/options_test.go index 45438d9..f32bbac 100644 --- a/options_test.go +++ b/options_test.go @@ -110,7 +110,7 @@ func TestWithAtomicMerge(t *testing.T) { func TestWithTrileanMerge(t *testing.T) { c := newCoalescer(WithTrileanMerge()) - assert.NotNil(t, c.typeMergers[reflect.PtrTo(reflect.TypeOf(false))]) + assert.NotNil(t, c.typeMergers[reflect.PointerTo(reflect.TypeOf(false))]) got, err := c.deepMerge(reflect.ValueOf(boolPtr(true)), reflect.ValueOf(boolPtr(false))) assert.Equal(t, boolPtr(false), got.Interface()) assert.NoError(t, err) diff --git a/pointer_test.go b/pointer_test.go index d8b42b8..8e7cf2d 100644 --- a/pointer_test.go +++ b/pointer_test.go @@ -349,6 +349,7 @@ func assertNotSame(t *testing.T, o1, o2 interface{}) bool { return false } } + default: } return true }