1
- using System ;
2
- using System . Collections . Generic ;
3
- using System . Diagnostics ;
4
- using System . Linq ;
5
- using System . Text ;
1
+ using System . Linq ;
6
2
using System . Threading ;
7
- using System . Threading . Tasks ;
8
3
using NUnit . Framework ;
9
4
using Rubberduck . Inspections . Concrete ;
10
5
using Rubberduck . Inspections . QuickFixes ;
@@ -127,6 +122,50 @@ End Sub
127
122
Assert . AreEqual ( expected , actual ) ;
128
123
}
129
124
125
+ [ Test ]
126
+ [ Category ( "QuickFixes" ) ]
127
+ public void OptionalArray_QuickFixWorks ( )
128
+ {
129
+ const string inputCode =
130
+ @"
131
+ Public Sub Foo(Optional bar() As Variant)
132
+ Debug.Print IsMissing(bar)
133
+ End Sub
134
+ " ;
135
+
136
+ const string expected =
137
+ @"
138
+ Public Sub Foo(Optional bar() As Variant)
139
+ Debug.Print LBound(bar) > UBound(bar)
140
+ End Sub
141
+ " ;
142
+
143
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
144
+ Assert . AreEqual ( expected , actual ) ;
145
+ }
146
+
147
+ [ Test ]
148
+ [ Category ( "QuickFixes" ) ]
149
+ public void NonOptionalArray_QuickFixWorks ( )
150
+ {
151
+ const string inputCode =
152
+ @"
153
+ Public Sub Foo(bar() As String)
154
+ Debug.Print IsMissing(bar)
155
+ End Sub
156
+ " ;
157
+
158
+ const string expected =
159
+ @"
160
+ Public Sub Foo(bar() As String)
161
+ Debug.Print LBound(bar) > UBound(bar)
162
+ End Sub
163
+ " ;
164
+
165
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
166
+ Assert . AreEqual ( expected , actual ) ;
167
+ }
168
+
130
169
[ Test ]
131
170
[ Category ( "QuickFixes" ) ]
132
171
public void OptionalStringArgumentDefaultDoubleQuotes_QuickFixWorks ( )
@@ -151,7 +190,7 @@ End Sub
151
190
152
191
[ Test ]
153
192
[ Category ( "QuickFixes" ) ]
154
- public void ReferenceType_QuickFixWorks ( )
193
+ public void NonOptionalReferenceType_QuickFixWorks ( )
155
194
{
156
195
const string inputCode =
157
196
@"
@@ -171,6 +210,226 @@ End Sub
171
210
Assert . AreEqual ( expected , actual ) ;
172
211
}
173
212
213
+ [ Test ]
214
+ [ Category ( "QuickFixes" ) ]
215
+ public void NonOptionalObject_QuickFixWorks ( )
216
+ {
217
+ const string inputCode =
218
+ @"
219
+ Public Sub Foo(bar As Object)
220
+ Debug.Print IsMissing(bar)
221
+ End Sub
222
+ " ;
223
+
224
+ const string expected =
225
+ @"
226
+ Public Sub Foo(bar As Object)
227
+ Debug.Print bar Is Nothing
228
+ End Sub
229
+ " ;
230
+
231
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
232
+ Assert . AreEqual ( expected , actual ) ;
233
+ }
234
+
235
+ [ Test ]
236
+ [ Category ( "QuickFixes" ) ]
237
+ public void NonOptionalNumeric_QuickFixWorks ( )
238
+ {
239
+ const string inputCode =
240
+ @"
241
+ Public Sub Foo(bar As Long)
242
+ Debug.Print IsMissing(bar)
243
+ End Sub
244
+ " ;
245
+
246
+ const string expected =
247
+ @"
248
+ Public Sub Foo(bar As Long)
249
+ Debug.Print bar = 0
250
+ End Sub
251
+ " ;
252
+
253
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
254
+ Assert . AreEqual ( expected , actual ) ;
255
+ }
256
+
257
+ [ Test ]
258
+ [ Category ( "QuickFixes" ) ]
259
+ public void NonOptionalVariant_QuickFixWorks ( )
260
+ {
261
+ const string inputCode =
262
+ @"
263
+ Public Sub Foo(bar As Variant)
264
+ Debug.Print IsMissing(bar)
265
+ End Sub
266
+ " ;
267
+
268
+ const string expected =
269
+ @"
270
+ Public Sub Foo(bar As Variant)
271
+ Debug.Print IsEmpty(bar)
272
+ End Sub
273
+ " ;
274
+
275
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
276
+ Assert . AreEqual ( expected , actual ) ;
277
+ }
278
+
279
+ [ Test ]
280
+ [ Category ( "QuickFixes" ) ]
281
+ public void NonOptionalImplicitVariant_QuickFixWorks ( )
282
+ {
283
+ const string inputCode =
284
+ @"
285
+ Public Sub Foo(bar)
286
+ Debug.Print IsMissing(bar)
287
+ End Sub
288
+ " ;
289
+
290
+ const string expected =
291
+ @"
292
+ Public Sub Foo(bar)
293
+ Debug.Print IsEmpty(bar)
294
+ End Sub
295
+ " ;
296
+
297
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
298
+ Assert . AreEqual ( expected , actual ) ;
299
+ }
300
+
301
+ [ Test ]
302
+ [ Category ( "QuickFixes" ) ]
303
+ public void NonOptionalString_QuickFixWorks ( )
304
+ {
305
+ const string inputCode =
306
+ @"
307
+ Public Sub Foo(bar As String)
308
+ Debug.Print IsMissing(bar)
309
+ End Sub
310
+ " ;
311
+
312
+ const string expected =
313
+ @"
314
+ Public Sub Foo(bar As String)
315
+ Debug.Print bar = vbNullString
316
+ End Sub
317
+ " ;
318
+
319
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
320
+ Assert . AreEqual ( expected , actual ) ;
321
+ }
322
+
323
+ [ Test ]
324
+ [ Category ( "QuickFixes" ) ]
325
+ public void NonOptionalDate_QuickFixWorks ( )
326
+ {
327
+ const string inputCode =
328
+ @"
329
+ Public Sub Foo(bar As Date)
330
+ Debug.Print IsMissing(bar)
331
+ End Sub
332
+ " ;
333
+
334
+ const string expected =
335
+ @"
336
+ Public Sub Foo(bar As Date)
337
+ Debug.Print bar = CDate(0)
338
+ End Sub
339
+ " ;
340
+
341
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
342
+ Assert . AreEqual ( expected , actual ) ;
343
+ }
344
+
345
+ [ Test ]
346
+ [ Category ( "QuickFixes" ) ]
347
+ public void NonOptionalBoolean_QuickFixWorks ( )
348
+ {
349
+ const string inputCode =
350
+ @"
351
+ Public Sub Foo(bar As Boolean)
352
+ Debug.Print IsMissing(bar)
353
+ End Sub
354
+ " ;
355
+
356
+ const string expected =
357
+ @"
358
+ Public Sub Foo(bar As Boolean)
359
+ Debug.Print bar = False
360
+ End Sub
361
+ " ;
362
+
363
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
364
+ Assert . AreEqual ( expected , actual ) ;
365
+ }
366
+
367
+ [ Test ]
368
+ [ Category ( "QuickFixes" ) ]
369
+ public void NonOptionalTypeHinted_QuickFixWorks ( )
370
+ {
371
+ const string inputCode =
372
+ @"
373
+ Public Sub Foo(bar&)
374
+ Debug.Print IsMissing(bar)
375
+ End Sub
376
+ " ;
377
+
378
+ const string expected =
379
+ @"
380
+ Public Sub Foo(bar&)
381
+ Debug.Print bar = 0
382
+ End Sub
383
+ " ;
384
+
385
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
386
+ Assert . AreEqual ( expected , actual ) ;
387
+ }
388
+
389
+ [ Test ]
390
+ [ Category ( "QuickFixes" ) ]
391
+ public void NonOptionalEnumeration_QuickFixPicksMember ( )
392
+ {
393
+ const string inputCode =
394
+ @"
395
+ Public Sub Foo(bar As VbVarType)
396
+ Debug.Print IsMissing(bar)
397
+ End Sub
398
+ " ;
399
+
400
+ const string expected =
401
+ @"
402
+ Public Sub Foo(bar As VbVarType)
403
+ Debug.Print bar = vbEmpty
404
+ End Sub
405
+ " ;
406
+
407
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
408
+ Assert . AreEqual ( expected , actual ) ;
409
+ }
410
+
411
+ [ Test ]
412
+ [ Category ( "QuickFixes" ) ]
413
+ public void NonOptionalEnumerationNoDefault_QuickFixPicksZero ( )
414
+ {
415
+ const string inputCode =
416
+ @"
417
+ Public Sub Foo(bar As VbStrConv)
418
+ Debug.Print IsMissing(bar)
419
+ End Sub
420
+ " ;
421
+
422
+ const string expected =
423
+ @"
424
+ Public Sub Foo(bar As VbStrConv)
425
+ Debug.Print bar = 0
426
+ End Sub
427
+ " ;
428
+
429
+ var actual = ArrangeAndApplyQuickFix ( inputCode ) ;
430
+ Assert . AreEqual ( expected , actual ) ;
431
+ }
432
+
174
433
private string ArrangeAndApplyQuickFix ( string code )
175
434
{
176
435
var builder = new MockVbeBuilder ( ) ;
0 commit comments