|
10 | 10 | using Rubberduck.VBEditor;
|
11 | 11 | using Antlr4.Runtime;
|
12 | 12 | using Rubberduck.Common;
|
| 13 | +using Rubberduck.Parsing; |
| 14 | +using Rubberduck.Parsing.Grammar; |
13 | 15 |
|
14 | 16 | namespace RubberduckTests.Symbols
|
15 | 17 | {
|
@@ -1212,6 +1214,44 @@ Dim sht As WorkSheet
|
1212 | 1214 | }
|
1213 | 1215 | }
|
1214 | 1216 |
|
| 1217 | + [Test] |
| 1218 | + [Category("Resolver")] |
| 1219 | + public void FindParameterFromArgument_WorksWithMultipleScopes() |
| 1220 | + { |
| 1221 | + var module1 = |
| 1222 | +@"Public Sub Foo(arg As Variant) |
| 1223 | +End Sub"; |
| 1224 | + |
| 1225 | + var module2 = |
| 1226 | +@"Private Sub Foo(expected As Variant) |
| 1227 | +End Sub |
| 1228 | +
|
| 1229 | +Public Sub Bar() |
| 1230 | + Dim fooBar As Variant |
| 1231 | + Foo fooBar |
| 1232 | +End Sub |
| 1233 | +"; |
| 1234 | + var vbe = new MockVbeBuilder() |
| 1235 | + .ProjectBuilder("UnderTest", ProjectProtection.Unprotected) |
| 1236 | + .AddComponent("Module1", ComponentType.StandardModule, module1, new Selection(1, 1)) |
| 1237 | + .AddComponent("Module2", ComponentType.StandardModule, module2, new Selection(1, 1)) |
| 1238 | + .AddProjectToVbeBuilder() |
| 1239 | + .Build(); |
| 1240 | + |
| 1241 | + using (var state = MockParser.CreateAndParse(vbe.Object)) |
| 1242 | + { |
| 1243 | + var declarations = state.DeclarationFinder.AllDeclarations.ToList(); |
| 1244 | + var expected = declarations.FirstOrDefault(decl => decl.IdentifierName.Equals("expected")); |
| 1245 | + |
| 1246 | + var enclosing = declarations.FirstOrDefault(decl => decl.IdentifierName.Equals("Bar")); |
| 1247 | + var context = enclosing?.Context.GetDescendent<VBAParser.ArgumentExpressionContext>(); |
| 1248 | + var actual = state.DeclarationFinder.FindParameterFromArgument(context, enclosing); |
| 1249 | + |
| 1250 | + Assert.AreEqual(expected, actual); |
| 1251 | + } |
| 1252 | + } |
| 1253 | + |
| 1254 | + |
1215 | 1255 | [Category("Resolver")]
|
1216 | 1256 | [Category("Interfaces")]
|
1217 | 1257 | [Test]
|
|
0 commit comments