-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_test.go
161 lines (130 loc) · 2.23 KB
/
data_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package deepcopy
import (
"errors"
"reflect"
)
type errorCopier struct {
}
func (c *errorCopier) Copy(dst, src reflect.Value) error {
return errTest
}
type StrT string
type IntT int
func ptrOf[T any](v T) *T {
return &v
}
var (
errTest = errors.New("err test")
)
type srcStruct2 struct {
S string
I int
U uint32
F float64
B bool
Method int
}
type dstStruct2 struct {
S string
I int
U uint32
F float64
B bool
MethodVal int `copy:"Method"`
}
func (d *dstStruct2) CopyMethod(v int) error {
d.MethodVal = v * 2
return nil
}
func (d *dstStruct2) EqualSrcStruct2(s *srcStruct2) bool {
return d.S == s.S && d.I == s.I && d.U == s.U && d.F == s.F && d.B == s.B && d.MethodVal == s.Method*2
}
type srcStruct1 struct {
S string
I int
U uint32
F float64
B bool
II []int
UU []uint
SS []string
V srcStruct2
VV []srcStruct2
M1 map[int]string
M2 *map[int8]int8
M3 map[int]int
M4 map[[3]int]*srcStruct2
NilP2V *int
P2V *int
V2P int
S2A []string
MatchedX string `copy:"Matched"`
UnmatchedX string `copy:"UnmatchedX"`
}
type dstStruct1 struct {
S StrT
I int
U uint32
F float64
B *bool
II []int
UU []uint
SS []*StrT
V dstStruct2
VV []dstStruct2
M1 map[int]string
M2 map[int8]int8
M3 *map[int]IntT
M4 map[[3]int]*dstStruct2
NilP2V int
P2V int
V2P *int
S2A [3]string
MatchedY string `copy:"Matched"`
UnmatchedY string `copy:"UnmatchedY"`
}
var (
srcStructA = srcStruct2{
S: "string",
I: 10,
U: 100,
F: 1.234,
B: true,
Method: 1234,
}
srcStructB = srcStruct2{
S: "string",
I: 10,
U: 100,
F: 1.234,
B: true,
Method: 4321,
}
p2v = 1234
//nolint
srcStruct = srcStruct1{
S: "string",
I: 10,
U: 10,
F: 1.234,
B: true,
II: []int{1, 2, 3},
UU: nil,
SS: []string{"string1", "string2", "", "string4", "string5"},
V: srcStructA,
VV: []srcStruct2{srcStructA, srcStructB, srcStructA, srcStructB, srcStructA},
M1: map[int]string{1: "11", 2: "22", 3: "33"},
M2: nil,
M3: map[int]int{7: 77, 8: 88, 9: 99},
M4: map[[3]int]*srcStruct2{
[3]int{1, 1, 1}: &srcStructA,
[3]int{2, 2, 2}: &srcStructB,
},
NilP2V: nil,
P2V: &p2v,
V2P: 123,
S2A: []string{"1", "2", "3", "4"},
MatchedX: "MatchedX",
UnmatchedX: "UnmatchedX",
}
)