@@ -20,7 +20,7 @@ type testS struct {
20
20
list2 []int `stm:"list2"`
21
21
}
22
22
23
- func Test_structToMap (t * testing.T ) {
23
+ func Test_StructToMapExtraExport (t * testing.T ) {
24
24
ts := testS {
25
25
S1 : "s1" ,
26
26
s2 : "s2" ,
@@ -101,7 +101,79 @@ func Test_structToMap(t *testing.T) {
101
101
}
102
102
for _ , tt := range tests {
103
103
t .Run (tt .name , func (t * testing.T ) {
104
- assert .Equal (t , structToMap (ts , tt .args .tag ), tt .want )
104
+ assert .Equal (t , StructToMapExtraExport (ts , tt .args .tag ), tt .want )
105
+ })
106
+ }
107
+ }
108
+
109
+ func Test_StructToMap (t * testing.T ) {
110
+ ts := testS {
111
+ S1 : "s1" ,
112
+ s2 : "s2" ,
113
+ T1 : struct {
114
+ Name string `stm:"name"`
115
+ age int `stm:"age" stm2:"-"`
116
+ }{
117
+ Name : "name" ,
118
+ age : 18 ,
119
+ },
120
+ t2 : struct {
121
+ Gender bool `stm:"gender"`
122
+ }{
123
+ Gender : true ,
124
+ },
125
+ List1 : []string {"1" , "2" , "3" },
126
+ list2 : []int {1 , 2 , 3 },
127
+ }
128
+ type args struct {
129
+ tag string
130
+ }
131
+ tests := []struct {
132
+ name string
133
+ args args
134
+ want map [string ]interface {}
135
+ }{
136
+ {
137
+ name : "" ,
138
+ args : args {
139
+ tag : "" ,
140
+ },
141
+ want : map [string ]interface {}{
142
+ "S1" : "s1" ,
143
+ "T1" : map [string ]interface {}{
144
+ "Name" : "name" ,
145
+ },
146
+ "List1" : []string {"1" , "2" , "3" },
147
+ },
148
+ },
149
+ {
150
+ name : "" ,
151
+ args : args {
152
+ tag : "stm" ,
153
+ },
154
+ want : map [string ]interface {}{
155
+ "S_1" : "s1" ,
156
+ "T_1" : map [string ]interface {}{
157
+ "name" : "name" ,
158
+ },
159
+ "list1" : []string {"1" , "2" , "3" },
160
+ },
161
+ },
162
+ {
163
+ name : "" ,
164
+ args : args {
165
+ tag : "stm2" ,
166
+ },
167
+ want : map [string ]interface {}{
168
+ "T1" : map [string ]interface {}{
169
+ "Name" : "name" ,
170
+ },
171
+ },
172
+ },
173
+ }
174
+ for _ , tt := range tests {
175
+ t .Run (tt .name , func (t * testing.T ) {
176
+ assert .Equal (t , StructToMap (ts , tt .args .tag ), tt .want )
105
177
})
106
178
}
107
179
}
0 commit comments