@@ -192,6 +192,63 @@ public void ParameterCanByByVal_ReturnsResult_SomeParams()
192
192
Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
193
193
}
194
194
195
+ [ TestMethod ]
196
+ [ TestCategory ( "Inspections" ) ]
197
+ public void GivenArrayParameter_ReturnsNoResult ( )
198
+ {
199
+ const string inputCode =
200
+ @"Sub Foo(ByRef arg1() As Variant)
201
+ End Sub" ;
202
+
203
+ //Arrange
204
+ var builder = new MockVbeBuilder ( ) ;
205
+ VBComponent component ;
206
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
207
+ var mockHost = new Mock < IHostApplication > ( ) ;
208
+ mockHost . SetupAllProperties ( ) ;
209
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object , new Mock < ISinks > ( ) . Object ) ) ;
210
+
211
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
212
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
213
+
214
+ var inspection = new ParameterCanBeByValInspection ( parser . State ) ;
215
+
216
+ var results = inspection . GetInspectionResults ( ) . ToList ( ) ;
217
+
218
+ Assert . AreEqual ( 0 , results . Count ) ;
219
+ }
220
+
221
+ [ TestMethod ]
222
+ [ TestCategory ( "Inspections" ) ]
223
+ public void ParameterCanByByVal_ReturnsResult_QuickFixWorks_SubNameStartsWithParamName ( )
224
+ {
225
+ const string inputCode =
226
+ @"Sub foo(f)
227
+ End Sub" ;
228
+
229
+ const string expectedCode =
230
+ @"Sub foo(ByVal f)
231
+ End Sub" ;
232
+
233
+ //Arrange
234
+ var builder = new MockVbeBuilder ( ) ;
235
+ VBComponent component ;
236
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
237
+ var project = vbe . Object . VBProjects . Item ( 0 ) ;
238
+ var module = project . VBComponents . Item ( 0 ) . CodeModule ;
239
+ var mockHost = new Mock < IHostApplication > ( ) ;
240
+ mockHost . SetupAllProperties ( ) ;
241
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object , new Mock < ISinks > ( ) . Object ) ) ;
242
+
243
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
244
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
245
+
246
+ var inspection = new ParameterCanBeByValInspection ( parser . State ) ;
247
+ inspection . GetInspectionResults ( ) . First ( ) . QuickFixes . First ( ) . Fix ( ) ;
248
+
249
+ Assert . AreEqual ( expectedCode , module . Lines ( ) ) ;
250
+ }
251
+
195
252
[ TestMethod ]
196
253
[ TestCategory ( "Inspections" ) ]
197
254
public void ParameterCanByByVal_ReturnsResult_QuickFixWorks_PassedByUnspecified ( )
@@ -256,16 +313,24 @@ public void ParameterCanByByVal_ReturnsResult_QuickFixWorks_PassedByRef()
256
313
257
314
[ TestMethod ]
258
315
[ TestCategory ( "Inspections" ) ]
259
- public void GivenArrayParameter_ReturnsNoResult ( )
316
+ public void ParameterCanByByVal_ReturnsResult_QuickFixWorks_PassedByUnspecified_MultilineParameter ( )
260
317
{
261
318
const string inputCode =
262
- @"Sub Foo(ByRef arg1() As Variant)
319
+ @"Sub Foo( _
320
+ arg1 As String)
321
+ End Sub" ;
322
+
323
+ const string expectedCode =
324
+ @"Sub Foo( _
325
+ ByVal arg1 As String)
263
326
End Sub" ;
264
327
265
328
//Arrange
266
329
var builder = new MockVbeBuilder ( ) ;
267
330
VBComponent component ;
268
331
var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
332
+ var project = vbe . Object . VBProjects . Item ( 0 ) ;
333
+ var module = project . VBComponents . Item ( 0 ) . CodeModule ;
269
334
var mockHost = new Mock < IHostApplication > ( ) ;
270
335
mockHost . SetupAllProperties ( ) ;
271
336
var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object , new Mock < ISinks > ( ) . Object ) ) ;
@@ -274,10 +339,42 @@ public void GivenArrayParameter_ReturnsNoResult()
274
339
if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
275
340
276
341
var inspection = new ParameterCanBeByValInspection ( parser . State ) ;
277
-
278
- var results = inspection . GetInspectionResults ( ) . ToList ( ) ;
342
+ inspection . GetInspectionResults ( ) . First ( ) . QuickFixes . First ( ) . Fix ( ) ;
279
343
280
- Assert . AreEqual ( 0 , results . Count ) ;
344
+ Assert . AreEqual ( expectedCode , module . Lines ( ) ) ;
345
+ }
346
+
347
+ [ TestMethod ]
348
+ [ TestCategory ( "Inspections" ) ]
349
+ public void ParameterCanByByVal_ReturnsResult_QuickFixWorks_PassedByRef_MultilineParameter ( )
350
+ {
351
+ const string inputCode =
352
+ @"Sub Foo(ByRef _
353
+ arg1 As String)
354
+ End Sub" ;
355
+
356
+ const string expectedCode =
357
+ @"Sub Foo(ByVal _
358
+ arg1 As String)
359
+ End Sub" ;
360
+
361
+ //Arrange
362
+ var builder = new MockVbeBuilder ( ) ;
363
+ VBComponent component ;
364
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
365
+ var project = vbe . Object . VBProjects . Item ( 0 ) ;
366
+ var module = project . VBComponents . Item ( 0 ) . CodeModule ;
367
+ var mockHost = new Mock < IHostApplication > ( ) ;
368
+ mockHost . SetupAllProperties ( ) ;
369
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object , new Mock < ISinks > ( ) . Object ) ) ;
370
+
371
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
372
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
373
+
374
+ var inspection = new ParameterCanBeByValInspection ( parser . State ) ;
375
+ inspection . GetInspectionResults ( ) . First ( ) . QuickFixes . First ( ) . Fix ( ) ;
376
+
377
+ Assert . AreEqual ( expectedCode , module . Lines ( ) ) ;
281
378
}
282
379
283
380
[ TestMethod ]
0 commit comments