@@ -65,12 +65,13 @@ func Test_Collector_Collecting(t *testing.T) {
65
65
depCount (t , decl1 , 2 )
66
66
depCount (t , decl2 , 3 )
67
67
68
- // The second collection overwrites the first collection .
68
+ // The second collection adds to existing dependencies .
69
69
c .CollectDCEDeps (decl2 , func () {
70
+ c .DeclareDCEDep (obj4 )
70
71
c .DeclareDCEDep (obj5 )
71
72
})
72
73
depCount (t , decl1 , 2 )
73
- depCount (t , decl2 , 1 )
74
+ depCount (t , decl2 , 4 )
74
75
}
75
76
76
77
func Test_Info_SetNameAndDep (t * testing.T ) {
@@ -86,8 +87,7 @@ func Test_Info_SetNameAndDep(t *testing.T) {
86
87
`package jim
87
88
import Sarah "fmt"` ),
88
89
want : Info {
89
- importPath : `jim` ,
90
- objectFilter : `Sarah` ,
90
+ objectFilter : `jim.Sarah` ,
91
91
},
92
92
wantDep : `jim.Sarah` ,
93
93
},
@@ -97,8 +97,7 @@ func Test_Info_SetNameAndDep(t *testing.T) {
97
97
`package jim
98
98
var Toby float64` ),
99
99
want : Info {
100
- importPath : `jim` ,
101
- objectFilter : `Toby` ,
100
+ objectFilter : `jim.Toby` ,
102
101
},
103
102
wantDep : `jim.Toby` ,
104
103
},
@@ -108,8 +107,7 @@ func Test_Info_SetNameAndDep(t *testing.T) {
108
107
`package jim
109
108
const Ludo int = 42` ),
110
109
want : Info {
111
- importPath : `jim` ,
112
- objectFilter : `Ludo` ,
110
+ objectFilter : `jim.Ludo` ,
113
111
},
114
112
wantDep : `jim.Ludo` ,
115
113
},
@@ -126,8 +124,7 @@ func Test_Info_SetNameAndDep(t *testing.T) {
126
124
}
127
125
}` ),
128
126
want : Info {
129
- importPath : `jim` ,
130
- objectFilter : `Gobo` ,
127
+ objectFilter : `jim.Gobo` ,
131
128
},
132
129
wantDep : `jim.Gobo` ,
133
130
},
@@ -137,8 +134,7 @@ func Test_Info_SetNameAndDep(t *testing.T) {
137
134
`package jim
138
135
type Jen struct{}` ),
139
136
want : Info {
140
- importPath : `jim` ,
141
- objectFilter : `Jen` ,
137
+ objectFilter : `jim.Jen` ,
142
138
},
143
139
wantDep : `jim.Jen` ,
144
140
},
@@ -148,8 +144,7 @@ func Test_Info_SetNameAndDep(t *testing.T) {
148
144
`package jim
149
145
type Henson[T comparable] struct{}` ),
150
146
want : Info {
151
- importPath : `jim` ,
152
- objectFilter : `Henson` ,
147
+ objectFilter : `jim.Henson` ,
153
148
},
154
149
wantDep : `jim.Henson` ,
155
150
},
@@ -159,8 +154,7 @@ func Test_Info_SetNameAndDep(t *testing.T) {
159
154
`package jim
160
155
func Jareth() {}` ),
161
156
want : Info {
162
- importPath : `jim` ,
163
- objectFilter : `Jareth` ,
157
+ objectFilter : `jim.Jareth` ,
164
158
},
165
159
wantDep : `jim.Jareth` ,
166
160
},
@@ -170,8 +164,7 @@ func Test_Info_SetNameAndDep(t *testing.T) {
170
164
`package jim
171
165
func Didymus[T comparable]() {}` ),
172
166
want : Info {
173
- importPath : `jim` ,
174
- objectFilter : `Didymus` ,
167
+ objectFilter : `jim.Didymus` ,
175
168
},
176
169
wantDep : `jim.Didymus` ,
177
170
},
@@ -182,8 +175,7 @@ func Test_Info_SetNameAndDep(t *testing.T) {
182
175
type Fizzgig string
183
176
func (f Fizzgig) Kira() {}` ),
184
177
want : Info {
185
- importPath : `jim` ,
186
- objectFilter : `Fizzgig` ,
178
+ objectFilter : `jim.Fizzgig` ,
187
179
},
188
180
wantDep : `jim.Kira~` ,
189
181
},
@@ -194,9 +186,8 @@ func Test_Info_SetNameAndDep(t *testing.T) {
194
186
type Aughra int
195
187
func (a Aughra) frank() {}` ),
196
188
want : Info {
197
- importPath : `jim` ,
198
- objectFilter : `Aughra` ,
199
- methodFilter : `frank~` ,
189
+ objectFilter : `jim.Aughra` ,
190
+ methodFilter : `jim.frank~` ,
200
191
},
201
192
wantDep : `jim.frank~` ,
202
193
},
@@ -207,8 +198,7 @@ func Test_Info_SetNameAndDep(t *testing.T) {
207
198
type wembley struct{}
208
199
func (w wembley) Red() {}` ),
209
200
want : Info {
210
- importPath : `jim` ,
211
- objectFilter : `wembley` ,
201
+ objectFilter : `jim.wembley` ,
212
202
},
213
203
wantDep : `jim.Red~` ,
214
204
},
@@ -219,12 +209,11 @@ func Test_Info_SetNameAndDep(t *testing.T) {
219
209
t .Run (tt .name , func (t * testing.T ) {
220
210
d := & testDecl {}
221
211
equal (t , d .Dce ().unnamed (), true )
222
- equal (t , d .Dce ().String (), `[unnamed] . -> []` )
212
+ equal (t , d .Dce ().String (), `[unnamed] -> []` )
223
213
t .Log (`object:` , types .ObjectString (tt .obj , nil ))
224
214
225
215
d .Dce ().SetName (tt .obj )
226
216
equal (t , d .Dce ().unnamed (), tt .want .unnamed ())
227
- equal (t , d .Dce ().importPath , tt .want .importPath )
228
217
equal (t , d .Dce ().objectFilter , tt .want .objectFilter )
229
218
equal (t , d .Dce ().methodFilter , tt .want .methodFilter )
230
219
equal (t , d .Dce ().String (), tt .want .String ())
@@ -238,11 +227,17 @@ func Test_Info_SetNameAndDep(t *testing.T) {
238
227
d := & testDecl {}
239
228
t .Log (`object:` , types .ObjectString (tt .obj , nil ))
240
229
241
- d .Dce ().setDeps (map [types.Object ]struct {}{
242
- tt .obj : {},
230
+ wantDeps := []string {}
231
+ if len (tt .wantDep ) > 0 {
232
+ wantDeps = append (wantDeps , tt .wantDep )
233
+ }
234
+ sort .Strings (wantDeps )
235
+
236
+ c := Collector {}
237
+ c .CollectDCEDeps (d , func () {
238
+ c .DeclareDCEDep (tt .obj )
243
239
})
244
- equal (t , len (d .Dce ().deps ), 1 )
245
- equal (t , d .Dce ().deps [0 ], tt .wantDep )
240
+ equalSlices (t , d .Dce ().getDeps (), wantDeps )
246
241
})
247
242
}
248
243
})
@@ -269,11 +264,11 @@ func Test_Info_SetAsAlive(t *testing.T) {
269
264
obj := quickVar (pkg , `Falkor` )
270
265
decl := & testDecl {}
271
266
equal (t , decl .Dce ().isAlive (), true ) // unnamed is automatically alive
272
- equal (t , decl .Dce ().String (), `[unnamed] . -> []` )
267
+ equal (t , decl .Dce ().String (), `[unnamed] -> []` )
273
268
274
269
decl .Dce ().SetAsAlive ()
275
270
equal (t , decl .Dce ().isAlive (), true ) // still alive but now explicitly alive
276
- equal (t , decl .Dce ().String (), `[alive] [unnamed] . -> []` )
271
+ equal (t , decl .Dce ().String (), `[alive] [unnamed] -> []` )
277
272
278
273
decl .Dce ().SetName (obj )
279
274
equal (t , decl .Dce ().isAlive (), true ) // alive because SetAsAlive was called
@@ -284,7 +279,7 @@ func Test_Info_SetAsAlive(t *testing.T) {
284
279
obj := quickVar (pkg , `Artax` )
285
280
decl := & testDecl {}
286
281
equal (t , decl .Dce ().isAlive (), true ) // unnamed is automatically alive
287
- equal (t , decl .Dce ().String (), `[unnamed] . -> []` )
282
+ equal (t , decl .Dce ().String (), `[unnamed] -> []` )
288
283
289
284
decl .Dce ().SetName (obj )
290
285
equal (t , decl .Dce ().isAlive (), false ) // named so no longer automatically alive
@@ -493,6 +488,7 @@ func Test_Selector_SpecificMethods(t *testing.T) {
493
488
494
489
for _ , tt := range tests {
495
490
t .Run (tt .name , func (t * testing.T ) {
491
+ vetinari .Dce ().deps = nil // reset deps
496
492
c .CollectDCEDeps (vetinari , func () {
497
493
for _ , decl := range tt .deps {
498
494
c .DeclareDCEDep (decl .obj )
@@ -626,6 +622,17 @@ func depCount(t *testing.T, decl *testDecl, want int) {
626
622
func equal [T comparable ](t * testing.T , got , want T ) {
627
623
t .Helper ()
628
624
if got != want {
629
- t .Errorf (`expected %#v but got %#v` , want , got )
625
+ t .Errorf ("Unexpected value was gotten:\n \t exp: %#v\n \t got: %#v" , want , got )
626
+ }
627
+ }
628
+
629
+ func equalSlices [T comparable ](t * testing.T , got , want []T ) {
630
+ t .Helper ()
631
+ if len (got ) != len (want ) {
632
+ t .Errorf ("expected %d but got %d\n \t exp: %#v\n \t got: %#v" , len (want ), len (got ), want , got )
633
+ return
634
+ }
635
+ for i , wantElem := range want {
636
+ equal (t , got [i ], wantElem )
630
637
}
631
638
}
0 commit comments