-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointer_test.go
46 lines (39 loc) · 1.18 KB
/
pointer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package dtomerge
import (
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func TestMergePointers(t *testing.T) {
t.Parallel()
t.Run("both filled", func(t *testing.T) {
t.Parallel()
src := 1
patch := 2
res, err := mergePointers(reflect.ValueOf(&src), reflect.ValueOf(&patch), newMergeContext(Options{}))
require.NoError(t, err)
require.Equal(t, 2, res.Elem().Interface())
})
t.Run("nil patch", func(t *testing.T) {
t.Parallel()
src := 1
res, err := mergePointers(reflect.ValueOf(&src), reflect.ValueOf((*int)(nil)), newMergeContext(Options{}))
require.NoError(t, err)
require.Equal(t, 1, res.Elem().Interface())
})
t.Run("zero filled patch", func(t *testing.T) {
t.Parallel()
src := 1
patch := 0
res, err := mergePointers(reflect.ValueOf(&src), reflect.ValueOf(&patch), newMergeContext(Options{}))
require.NoError(t, err)
require.Equal(t, 1, res.Elem().Interface())
})
t.Run("zero filled patch with nil src", func(t *testing.T) {
t.Parallel()
patch := 0
res, err := mergePointers(reflect.ValueOf((*int)(nil)), reflect.ValueOf(&patch), newMergeContext(Options{}))
require.NoError(t, err)
require.Equal(t, 0, res.Elem().Interface())
})
}