@@ -334,7 +334,7 @@ Sub Foo(arg1 As String)
334
334
}
335
335
336
336
[ TestMethod ]
337
- public void ParameterCanBeByVal_InterfaceMember ( )
337
+ public void ParameterCanBeByVal_InterfaceMember_SingleParam ( )
338
338
{
339
339
//Input
340
340
const string inputCode1 =
@@ -351,6 +351,43 @@ Private Sub IClass1_DoSomething(ByRef a As Integer)
351
351
var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
352
352
. AddComponent ( "IClass1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode1 )
353
353
. AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
354
+ . AddComponent ( "Class2" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
355
+ . Build ( ) ;
356
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
357
+
358
+ var mockHost = new Mock < IHostApplication > ( ) ;
359
+ mockHost . SetupAllProperties ( ) ;
360
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object , new Mock < ISinks > ( ) . Object ) ) ;
361
+
362
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
363
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
364
+
365
+ var inspection = new ParameterCanBeByValInspection ( parser . State ) ;
366
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
367
+
368
+ Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
369
+ }
370
+
371
+ [ TestMethod ]
372
+ public void ParameterCanBeByVal_InterfaceMember_SingleParamUsedByRef ( )
373
+ {
374
+ //Input
375
+ const string inputCode1 =
376
+ @"Public Sub DoSomething(ByRef a As Integer)
377
+ End Sub" ;
378
+ const string inputCode2 =
379
+ @"Implements IClass1
380
+
381
+ Private Sub IClass1_DoSomething(ByRef a As Integer)
382
+ a = 42
383
+ End Sub" ;
384
+
385
+ //Arrange
386
+ var builder = new MockVbeBuilder ( ) ;
387
+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
388
+ . AddComponent ( "IClass1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode1 )
389
+ . AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
390
+ . AddComponent ( "Class2" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
354
391
. Build ( ) ;
355
392
var vbe = builder . AddProject ( project ) . Build ( ) ;
356
393
@@ -366,7 +403,48 @@ Private Sub IClass1_DoSomething(ByRef a As Integer)
366
403
367
404
Assert . IsFalse ( inspectionResults . Any ( ) ) ;
368
405
}
369
-
406
+
407
+ [ TestMethod ]
408
+ public void ParameterCanBeByVal_InterfaceMember_MultipleParams_OneCanBeByVal ( )
409
+ {
410
+ //Input
411
+ const string inputCode1 =
412
+ @"Public Sub DoSomething(ByRef a As Integer, ByRef b As Integer)
413
+ End Sub" ;
414
+ const string inputCode2 =
415
+ @"Implements IClass1
416
+
417
+ Private Sub IClass1_DoSomething(ByRef a As Integer, ByRef b As Integer)
418
+ b = 42
419
+ End Sub" ;
420
+ const string inputCode3 =
421
+ @"Implements IClass1
422
+
423
+ Private Sub IClass1_DoSomething(ByRef a As Integer, ByRef b As Integer)
424
+ End Sub" ;
425
+
426
+ //Arrange
427
+ var builder = new MockVbeBuilder ( ) ;
428
+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
429
+ . AddComponent ( "IClass1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode1 )
430
+ . AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
431
+ . AddComponent ( "Class2" , vbext_ComponentType . vbext_ct_ClassModule , inputCode3 )
432
+ . Build ( ) ;
433
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
434
+
435
+ var mockHost = new Mock < IHostApplication > ( ) ;
436
+ mockHost . SetupAllProperties ( ) ;
437
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object , 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 ParameterCanBeByValInspection ( parser . State ) ;
443
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
444
+
445
+ Assert . AreEqual ( "a" , inspectionResults . Single ( ) . Target . IdentifierName ) ;
446
+ }
447
+
370
448
[ TestMethod ]
371
449
public void ParameterCanBeByVal_Event ( )
372
450
{
0 commit comments