-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy_interface_test.go
55 lines (45 loc) · 1.26 KB
/
copy_interface_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
47
48
49
50
51
52
53
54
55
package mapper
import (
"github.com/stretchr/testify/require"
"reflect"
"testing"
)
/***************************
@author: tiansheng.ren
@date: 7/25/23
@desc:
***************************/
func TestCopyInterfaceUseRawTypeIssue21(t *testing.T) {
getCopyResult := func() interface{} {
return make(map[string]int, 0)
}
result := getCopyResult()
srcValue := map[string]interface{}{
"int": int(1),
"int8": int8(1),
"int64": int64(1),
"float": float64(1),
}
dstKv := map[string]int{
"int": 1,
"int8": 1,
"int64": 1,
"float": 1,
}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.InterfaceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err, "TestCopyInterfaceUseRawTypeIssue21")
require.Equal(t, dstKv, result, "TestCopyInterfaceUseRawTypeIssue21")
}
func TestCopyInterfaceUseRawTypeBuildInIssue21(t *testing.T) {
getCopyResult := func() interface{} {
var i int64
return i
}
result := getCopyResult()
srcValue := 1.0
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.InterfaceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err, "TestCopyInterfaceUseRawTypeBuildInIssue21")
require.Equal(t, int64(1), result, "TestCopyInterfaceUseRawTypeBuildInIssue21")
}