@@ -503,6 +503,7 @@ Private Sub abc_Foo(ByRef arg1 As Integer)
503
503
var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
504
504
. AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode1 )
505
505
. AddComponent ( "Class2" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
506
+ . AddComponent ( "Class3" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
506
507
. Build ( ) ;
507
508
var vbe = builder . AddProject ( project ) . Build ( ) ;
508
509
@@ -538,6 +539,7 @@ Private Sub abc_Foo(ByVal arg1 As Integer)
538
539
var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
539
540
. AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode1 )
540
541
. AddComponent ( "Class2" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
542
+ . AddComponent ( "Class3" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
541
543
. Build ( ) ;
542
544
var vbe = builder . AddProject ( project ) . Build ( ) ;
543
545
@@ -574,6 +576,7 @@ Private Sub abc_Foo(ByRef arg1 As Integer)
574
576
var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
575
577
. AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode1 )
576
578
. AddComponent ( "Class2" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
579
+ . AddComponent ( "Class3" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
577
580
. Build ( ) ;
578
581
var vbe = builder . AddProject ( project ) . Build ( ) ;
579
582
@@ -610,6 +613,7 @@ Private Sub abc_Foo(ByRef arg1 As Integer, ByRef arg2 As Integer)
610
613
var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
611
614
. AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode1 )
612
615
. AddComponent ( "Class2" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
616
+ . AddComponent ( "Class3" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
613
617
. Build ( ) ;
614
618
var vbe = builder . AddProject ( project ) . Build ( ) ;
615
619
@@ -851,6 +855,70 @@ Private Sub IClass1_DoSomething(ByVal a As Integer, ByRef b As Integer)
851
855
Assert . AreEqual ( expectedCode3 , module3 . Lines ( ) ) ;
852
856
}
853
857
858
+ [ TestMethod ]
859
+ [ TestCategory ( "Inspections" ) ]
860
+ public void ParameterCanBeByVal_EVentMember_MultipleParams_OneCanBeByVal_QuickFixWorks ( )
861
+ {
862
+ //Input
863
+ const string inputCode1 =
864
+ @"Public Event Foo(ByRef a As Integer, ByRef b As Integer)" ;
865
+ const string inputCode2 =
866
+ @"Private WithEvents abc As Class1
867
+
868
+ Private Sub abc_Foo(ByRef a As Integer, ByRef b As Integer)
869
+ a = 42
870
+ End Sub" ;
871
+ const string inputCode3 =
872
+ @"Private WithEvents abc As Class1
873
+
874
+ Private Sub abc_Foo(ByRef a As Integer, ByRef b As Integer)
875
+ End Sub" ;
876
+
877
+ //Expected
878
+ const string expectedCode1 =
879
+ @"Public Event Foo(ByRef a As Integer, ByVal b As Integer)" ;
880
+ const string expectedCode2 =
881
+ @"Private WithEvents abc As Class1
882
+
883
+ Private Sub abc_Foo(ByRef a As Integer, ByVal b As Integer)
884
+ a = 42
885
+ End Sub" ;
886
+ const string expectedCode3 =
887
+ @"Private WithEvents abc As Class1
888
+
889
+ Private Sub abc_Foo(ByRef a As Integer, ByVal b As Integer)
890
+ End Sub" ;
891
+
892
+ //Arrange
893
+ var builder = new MockVbeBuilder ( ) ;
894
+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
895
+ . AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode1 )
896
+ . AddComponent ( "Class2" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
897
+ . AddComponent ( "Class3" , vbext_ComponentType . vbext_ct_ClassModule , inputCode3 )
898
+ . Build ( ) ;
899
+
900
+ var module1 = project . Object . VBComponents . Item ( "Class1" ) . CodeModule ;
901
+ var module2 = project . Object . VBComponents . Item ( "Class2" ) . CodeModule ;
902
+ var module3 = project . Object . VBComponents . Item ( "Class3" ) . CodeModule ;
903
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
904
+
905
+ var mockHost = new Mock < IHostApplication > ( ) ;
906
+ mockHost . SetupAllProperties ( ) ;
907
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object , new Mock < ISinks > ( ) . Object ) ) ;
908
+
909
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
910
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
911
+
912
+ var inspection = new ParameterCanBeByValInspection ( parser . State ) ;
913
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
914
+
915
+ inspectionResults . Single ( ) . QuickFixes . Single ( s => s is PassParameterByValueQuickFix ) . Fix ( ) ;
916
+
917
+ Assert . AreEqual ( expectedCode1 , module1 . Lines ( ) ) ;
918
+ Assert . AreEqual ( expectedCode2 , module2 . Lines ( ) ) ;
919
+ Assert . AreEqual ( expectedCode3 , module3 . Lines ( ) ) ;
920
+ }
921
+
854
922
[ TestMethod ]
855
923
[ TestCategory ( "Inspections" ) ]
856
924
public void ParameterCanBeByVal_IgnoreQuickFixWorks ( )
0 commit comments