@@ -295,6 +295,158 @@ Sub Foo(arg1 As Integer)
295
295
Assert . AreEqual ( expectedCode , module . Content ( ) ) ;
296
296
}
297
297
298
+ //http://chat.stackexchange.com/transcript/message/34001991#34001991
299
+ [ TestMethod ]
300
+ [ TestCategory ( "Inspections" ) ]
301
+ public void ImplicitByRefParameter_QuickFixWorks_OptionalParameter ( )
302
+ {
303
+ const string inputCode =
304
+ @"Sub Foo(Optional arg1 As Integer)
305
+ End Sub" ;
306
+
307
+ const string expectedCode =
308
+ @"Sub Foo(Optional ByRef arg1 As Integer)
309
+ End Sub" ;
310
+
311
+ //Arrange
312
+ var builder = new MockVbeBuilder ( ) ;
313
+ IVBComponent component ;
314
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
315
+ var project = vbe . Object . VBProjects [ 0 ] ;
316
+ var module = project . VBComponents [ 0 ] . CodeModule ;
317
+ var mockHost = new Mock < IHostApplication > ( ) ;
318
+ mockHost . SetupAllProperties ( ) ;
319
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
320
+
321
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
322
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
323
+
324
+ var inspection = new ImplicitByRefParameterInspection ( parser . State ) ;
325
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
326
+
327
+ inspectionResults . First ( ) . QuickFixes . First ( ) . Fix ( ) ;
328
+
329
+ Assert . AreEqual ( expectedCode , module . Content ( ) ) ;
330
+ }
331
+
332
+ //http://chat.stackexchange.com/transcript/message/34001991#34001991
333
+ [ TestMethod ]
334
+ [ TestCategory ( "Inspections" ) ]
335
+ public void ImplicitByRefParameter_QuickFixWorks_Optional_LineContinuations ( )
336
+ {
337
+ const string inputCode =
338
+ @"Sub Foo(Optional _
339
+ bar _
340
+ As Byte)
341
+ bar = 1
342
+ End Sub" ;
343
+
344
+ const string expectedCode =
345
+ @"Sub Foo(Optional _
346
+ ByRef bar _
347
+ As Byte)
348
+ bar = 1
349
+ End Sub" ;
350
+
351
+ //Arrange
352
+ var builder = new MockVbeBuilder ( ) ;
353
+ IVBComponent component ;
354
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
355
+ var project = vbe . Object . VBProjects [ 0 ] ;
356
+ var module = project . VBComponents [ 0 ] . CodeModule ;
357
+ var mockHost = new Mock < IHostApplication > ( ) ;
358
+ mockHost . SetupAllProperties ( ) ;
359
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
360
+
361
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
362
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
363
+
364
+ var inspection = new ImplicitByRefParameterInspection ( parser . State ) ;
365
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
366
+
367
+ inspectionResults . First ( ) . QuickFixes . First ( ) . Fix ( ) ;
368
+
369
+ Assert . AreEqual ( expectedCode , module . Content ( ) ) ;
370
+ }
371
+
372
+ //http://chat.stackexchange.com/transcript/message/34001991#34001991
373
+ [ TestMethod ]
374
+ [ TestCategory ( "Inspections" ) ]
375
+ public void ImplicitByRefParameter_QuickFixWorks_LineContinuation ( )
376
+ {
377
+ const string inputCode =
378
+ @"Sub Foo( bar _
379
+ As Byte)
380
+ bar = 1
381
+ End Sub" ;
382
+
383
+ const string expectedCode =
384
+ @"Sub Foo( ByRef bar _
385
+ As Byte)
386
+ bar = 1
387
+ End Sub" ;
388
+
389
+ //Arrange
390
+ var builder = new MockVbeBuilder ( ) ;
391
+ IVBComponent component ;
392
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
393
+ var project = vbe . Object . VBProjects [ 0 ] ;
394
+ var module = project . VBComponents [ 0 ] . CodeModule ;
395
+ var mockHost = new Mock < IHostApplication > ( ) ;
396
+ mockHost . SetupAllProperties ( ) ;
397
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
398
+
399
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
400
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
401
+
402
+ var inspection = new ImplicitByRefParameterInspection ( parser . State ) ;
403
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
404
+
405
+ inspectionResults . First ( ) . QuickFixes . First ( ) . Fix ( ) ;
406
+
407
+ Assert . AreEqual ( expectedCode , module . Content ( ) ) ;
408
+ }
409
+
410
+ //http://chat.stackexchange.com/transcript/message/34001991#34001991
411
+ [ TestMethod ]
412
+ [ TestCategory ( "Inspections" ) ]
413
+ public void ImplicitByRefParameter_QuickFixWorks_LineContinuation_FirstLine ( )
414
+ {
415
+ const string inputCode =
416
+ @"Sub Foo( _
417
+ bar _
418
+ As Byte)
419
+ bar = 1
420
+ End Sub" ;
421
+
422
+ const string expectedCode =
423
+ @"Sub Foo( _
424
+ bar _
425
+ As Byte)
426
+ bar = 1
427
+ End Sub" ;
428
+
429
+ //Arrange
430
+ var builder = new MockVbeBuilder ( ) ;
431
+ IVBComponent component ;
432
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
433
+ var project = vbe . Object . VBProjects [ 0 ] ;
434
+ var module = project . VBComponents [ 0 ] . CodeModule ;
435
+ var mockHost = new Mock < IHostApplication > ( ) ;
436
+ mockHost . SetupAllProperties ( ) ;
437
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
438
+
439
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
440
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
441
+
442
+ var inspection = new ImplicitByRefParameterInspection ( parser . State ) ;
443
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
444
+
445
+ inspectionResults . First ( ) . QuickFixes . First ( ) . Fix ( ) ;
446
+
447
+ Assert . AreEqual ( expectedCode , module . Content ( ) ) ;
448
+ }
449
+
298
450
[ TestMethod ]
299
451
[ TestCategory ( "Inspections" ) ]
300
452
public void InspectionType ( )
0 commit comments