@@ -215,7 +215,7 @@ End Sub
215
215
End Sub
216
216
217
217
Public Sub Goo()
218
- Foo arg2:=""test44"", arg1:=3
218
+ Foo arg2:=""test44"", arg1:=3
219
219
End Sub
220
220
" ;
221
221
@@ -248,6 +248,59 @@ End Sub
248
248
Assert . AreEqual ( expectedCode , module . Lines ( ) ) ;
249
249
}
250
250
251
+ [ TestMethod ]
252
+ public void RemoveParametersRefactoring_CallerArgNameContainsOtherArgName ( )
253
+ {
254
+ //Input
255
+ const string inputCode =
256
+ @"Sub foo(a, b, c)
257
+
258
+ End Sub
259
+
260
+ Sub goo()
261
+ foo asd, sdf, s
262
+ End Sub" ;
263
+ var selection = new Selection ( 1 , 23 , 1 , 27 ) ;
264
+
265
+ //Expectation
266
+ const string expectedCode =
267
+ @"Sub foo(a, b)
268
+
269
+ End Sub
270
+
271
+ Sub goo()
272
+ foo asd, sdf
273
+ End Sub" ;
274
+
275
+ //Arrange
276
+ var builder = new MockVbeBuilder ( ) ;
277
+ VBComponent component ;
278
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component , selection ) ;
279
+ var module = component . CodeModule ;
280
+ var mockHost = new Mock < IHostApplication > ( ) ;
281
+ mockHost . SetupAllProperties ( ) ;
282
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
283
+
284
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
285
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
286
+
287
+ var qualifiedSelection = new QualifiedSelection ( new QualifiedModuleName ( component ) , selection ) ;
288
+
289
+ //Specify Param(s) to remove
290
+ var model = new RemoveParametersModel ( parser . State , qualifiedSelection , null ) ;
291
+ model . Parameters [ 2 ] . IsRemoved = true ;
292
+
293
+ //SetupFactory
294
+ var factory = SetupFactory ( model ) ;
295
+
296
+ //Act
297
+ var refactoring = new RemoveParametersRefactoring ( vbe . Object , factory . Object ) ;
298
+ refactoring . Refactor ( qualifiedSelection ) ;
299
+
300
+ //Assert
301
+ Assert . AreEqual ( expectedCode , module . Lines ( ) ) ;
302
+ }
303
+
251
304
[ TestMethod ]
252
305
public void RemoveParametersRefactoring_RemoveLastFromFunction ( )
253
306
{
@@ -354,7 +407,7 @@ End Sub
354
407
End Function
355
408
356
409
Private Sub Goo(ByVal arg1 As Integer, ByVal arg2 As String)
357
- Foo
410
+ Foo
358
411
End Sub
359
412
" ;
360
413
@@ -406,7 +459,7 @@ Private Sub goo()
406
459
End Sub
407
460
408
461
Private Sub goo()
409
- foo 1, 2, 5, 7
462
+ foo 1, 2, 5, 7
410
463
End Sub" ;
411
464
412
465
//Arrange
@@ -589,7 +642,7 @@ End Sub
589
642
End Sub
590
643
591
644
Private Sub Bar()
592
- Foo ""Hello""
645
+ Foo ""Hello""
593
646
End Sub
594
647
" ;
595
648
@@ -642,9 +695,9 @@ End Sub
642
695
End Sub
643
696
644
697
Private Sub Bar()
645
- Foo 10
698
+ Foo 10
646
699
End Sub
647
- " ; //note: The IDE strips out the extra whitespace, you can't see it but there's a space after "Foo 10 "
700
+ " ;
648
701
649
702
//Arrange
650
703
var builder = new MockVbeBuilder ( ) ;
@@ -707,9 +760,9 @@ Public Sub Goo(ByVal arg1 As Integer, _
707
760
ByVal arg5 As Integer, _
708
761
ByVal arg6 As Integer)
709
762
710
- Foo ""test""
763
+ Foo ""test""
711
764
End Sub
712
- " ; //note: The IDE strips out the extra whitespace, you can't see it but there are several spaces after " ParamArrayTest ""test"" "
765
+ " ;
713
766
714
767
//Arrange
715
768
var builder = new MockVbeBuilder ( ) ;
@@ -945,6 +998,59 @@ Private Sub Goo(ByVal arg1 As Integer)
945
998
Assert . AreEqual ( expectedCode , module . Lines ( ) ) ;
946
999
}
947
1000
1001
+ [ TestMethod ]
1002
+ public void RemoveParametersRefactoring_RemoveOptionalParam ( )
1003
+ {
1004
+ //Input
1005
+ const string inputCode =
1006
+ @"Private Sub Foo(ByVal arg1 As Integer, Optional ByVal arg2 As String)
1007
+ End Sub
1008
+
1009
+ Private Sub Goo(ByVal arg1 As Integer)
1010
+ Foo arg1
1011
+ Foo 1, ""test""
1012
+ End Sub" ;
1013
+ var selection = new Selection ( 1 , 23 , 1 , 27 ) ;
1014
+
1015
+ //Expectation
1016
+ const string expectedCode =
1017
+ @"Private Sub Foo(ByVal arg1 As Integer)
1018
+ End Sub
1019
+
1020
+ Private Sub Goo(ByVal arg1 As Integer)
1021
+ Foo arg1
1022
+ Foo 1
1023
+ End Sub" ;
1024
+
1025
+ //Arrange
1026
+ var builder = new MockVbeBuilder ( ) ;
1027
+ VBComponent component ;
1028
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component , selection ) ;
1029
+ var module = component . CodeModule ;
1030
+ var mockHost = new Mock < IHostApplication > ( ) ;
1031
+ mockHost . SetupAllProperties ( ) ;
1032
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
1033
+
1034
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
1035
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
1036
+
1037
+ var qualifiedSelection = new QualifiedSelection ( new QualifiedModuleName ( component ) , selection ) ;
1038
+
1039
+ //Specify Params to remove
1040
+ var model = new RemoveParametersModel ( parser . State , qualifiedSelection , null ) ;
1041
+ model . Parameters [ 1 ] . IsRemoved = true ;
1042
+
1043
+ //SetupFactory
1044
+ var factory = SetupFactory ( model ) ;
1045
+
1046
+ //Act
1047
+ var refactoring = new RemoveParametersRefactoring ( vbe . Object , factory . Object ) ;
1048
+ refactoring . Refactor ( qualifiedSelection ) ;
1049
+
1050
+ //Assert
1051
+ Assert . AreEqual ( expectedCode , module . Lines ( ) ) ;
1052
+ }
1053
+
948
1054
[ TestMethod ]
949
1055
public void RemoveParametersRefactoring_SignatureOnMultipleLines ( )
950
1056
{
@@ -1150,7 +1256,7 @@ End Sub
1150
1256
1151
1257
Private Sub Goo(ByVal arg1 as Integer, ByVal arg2 As String, ByVal arg3 As Date)
1152
1258
1153
- Foo arg2, arg3
1259
+ Foo arg2, arg3
1154
1260
1155
1261
End Sub
1156
1262
" ; // note: IDE removes excess spaces
0 commit comments