@@ -218,6 +218,95 @@ public void GivenArrayParameter_ReturnsNoResult()
218218 Assert . AreEqual ( 0 , results . Count ) ;
219219 }
220220
221+ [ TestMethod ]
222+ [ TestCategory ( "Inspections" ) ]
223+ public void ParameterCanBeByVal_ReturnsResult_PassedToByRefProc_NoAssignment ( )
224+ {
225+ const string inputCode =
226+ @"Sub DoSomething(foo As Integer)
227+ DoSomethingElse foo
228+ End Sub
229+
230+ Sub DoSomethingElse(ByVal bar As Integer)
231+ End Sub" ;
232+
233+ //Arrange
234+ var builder = new MockVbeBuilder ( ) ;
235+ VBComponent component ;
236+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
237+ var mockHost = new Mock < IHostApplication > ( ) ;
238+ mockHost . SetupAllProperties ( ) ;
239+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object , new Mock < ISinks > ( ) . Object ) ) ;
240+
241+ parser . Parse ( new CancellationTokenSource ( ) ) ;
242+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
243+
244+ var inspection = new ParameterCanBeByValInspection ( parser . State ) ;
245+ var inspectionResults = inspection . GetInspectionResults ( ) ;
246+
247+ Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
248+ }
249+
250+ [ TestMethod ]
251+ [ TestCategory ( "Inspections" ) ]
252+ public void ParameterCanBeByVal_DoesNotReturnResult_PassedToByRefProc_WithAssignment ( )
253+ {
254+ const string inputCode =
255+ @"Sub DoSomething(foo As Integer)
256+ DoSomethingElse foo
257+ End Sub
258+
259+ Sub DoSomethingElse(ByRef bar As Integer)
260+ bar = 42
261+ End Sub" ;
262+
263+ //Arrange
264+ var builder = new MockVbeBuilder ( ) ;
265+ VBComponent component ;
266+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
267+ var mockHost = new Mock < IHostApplication > ( ) ;
268+ mockHost . SetupAllProperties ( ) ;
269+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object , new Mock < ISinks > ( ) . Object ) ) ;
270+
271+ parser . Parse ( new CancellationTokenSource ( ) ) ;
272+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
273+
274+ var inspection = new ParameterCanBeByValInspection ( parser . State ) ;
275+ var inspectionResults = inspection . GetInspectionResults ( ) ;
276+
277+ Assert . IsFalse ( inspectionResults . Any ( ) ) ;
278+ }
279+
280+ [ TestMethod ]
281+ [ TestCategory ( "Inspections" ) ]
282+ public void ParameterCanBeByVal_ReturnsResult_PassedToByValProc_WithAssignment ( )
283+ {
284+ const string inputCode =
285+ @"Sub DoSomething(foo As Integer)
286+ DoSomethingElse foo
287+ End Sub
288+
289+ Sub DoSomethingElse(ByVal bar As Integer)
290+ bar = 42
291+ End Sub" ;
292+
293+ //Arrange
294+ var builder = new MockVbeBuilder ( ) ;
295+ VBComponent component ;
296+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
297+ var mockHost = new Mock < IHostApplication > ( ) ;
298+ mockHost . SetupAllProperties ( ) ;
299+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object , new Mock < ISinks > ( ) . Object ) ) ;
300+
301+ parser . Parse ( new CancellationTokenSource ( ) ) ;
302+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
303+
304+ var inspection = new ParameterCanBeByValInspection ( parser . State ) ;
305+ var inspectionResults = inspection . GetInspectionResults ( ) ;
306+
307+ Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
308+ }
309+
221310 [ TestMethod ]
222311 [ TestCategory ( "Inspections" ) ]
223312 public void ParameterCanBeByVal_Ignored_DoesNotReturnResult ( )
0 commit comments