|
12 | 12 | using Rubberduck.Common;
|
13 | 13 | using Rubberduck.Parsing;
|
14 | 14 | using Rubberduck.Parsing.Grammar;
|
| 15 | +using System; |
15 | 16 |
|
16 | 17 | namespace RubberduckTests.Symbols
|
17 | 18 | {
|
@@ -445,6 +446,45 @@ End Sub
|
445 | 446 | Assert.AreEqual(isConflict, conflicts.Where(cf => cf.IdentifierName.Equals(nameToCheck)).Any(), ConflictMessage(isConflict, nameToCheck, conflicts));
|
446 | 447 | }
|
447 | 448 |
|
| 449 | + |
| 450 | + //https://github.com/rubberduck-vba/Rubberduck/issues/4969 |
| 451 | + private const string projectOneModuleName = "projectOneModule"; |
| 452 | + private const string projectTwoModuleName = "projectTwoModule"; |
| 453 | + [TestCase(projectOneModuleName, 0)] //Duplicate module name found in a separate project |
| 454 | + [TestCase(projectTwoModuleName, 1)] //Duplicate module name found in the same project |
| 455 | + [Category("Resolver")] |
| 456 | + public void DeclarationFinder_NameConflictDetectionRespectsProjectScope(string proposedTestModuleName, int expectedCount) |
| 457 | + { |
| 458 | + |
| 459 | + string renameTargetModuleName = "TargetModule"; |
| 460 | + |
| 461 | + string moduleContent = $"Private Sub Foo(){Environment.NewLine}End Sub"; |
| 462 | + |
| 463 | + var projectOneContent = new TestComponentSpecification[] |
| 464 | + { |
| 465 | + new TestComponentSpecification(projectOneModuleName, moduleContent, ComponentType.StandardModule) |
| 466 | + }; |
| 467 | + |
| 468 | + var projectTwoContent = new TestComponentSpecification[] |
| 469 | + { |
| 470 | + new TestComponentSpecification(renameTargetModuleName, moduleContent, ComponentType.StandardModule), |
| 471 | + new TestComponentSpecification(projectTwoModuleName, moduleContent, ComponentType.StandardModule) |
| 472 | + }; |
| 473 | + |
| 474 | + var vbe = BuildProjects(new (string, IEnumerable<TestComponentSpecification>)[] |
| 475 | + {("ProjectOne", projectOneContent),("ProjectTwo", projectTwoContent)}); |
| 476 | + |
| 477 | + using(var parser = MockParser.CreateAndParse(vbe)) |
| 478 | + { |
| 479 | + var target = parser.DeclarationFinder.UserDeclarations(DeclarationType.ProceduralModule) |
| 480 | + .FirstOrDefault(item => item.IdentifierName.Equals(renameTargetModuleName)); |
| 481 | + |
| 482 | + var results = parser.DeclarationFinder.FindNewDeclarationNameConflicts(proposedTestModuleName, target); |
| 483 | + |
| 484 | + Assert.AreEqual(expectedCount, results.Count()); |
| 485 | + } |
| 486 | + } |
| 487 | + |
448 | 488 | private static string ConflictMessage(bool isConflict, string name, IEnumerable<Declaration> conflicts)
|
449 | 489 | {
|
450 | 490 | return isConflict ? $"Identifier '{name}' is a conflict but was not identified" : $"Identifier '{name}' was incorrectly found as a conflict";
|
@@ -498,14 +538,33 @@ private void AddTestComponent(AccessibilityTestsDataObject tdo, string moduleIde
|
498 | 538 | }
|
499 | 539 |
|
500 | 540 | private IVBE BuildProject(string projectName, List<TestComponentSpecification> testComponents)
|
| 541 | + { |
| 542 | + var projectDefs = new (string, IEnumerable<TestComponentSpecification>)[] { (projectName, testComponents) }; |
| 543 | + return BuildProjects(projectDefs); |
| 544 | + } |
| 545 | + |
| 546 | + private IVBE BuildProjects(IEnumerable<(string ProjectName, IEnumerable<TestComponentSpecification> TestComponents)> projectDefinitions) |
501 | 547 | {
|
502 | 548 | var builder = new MockVbeBuilder();
|
| 549 | + foreach (var projectDef in projectDefinitions) |
| 550 | + { |
| 551 | + builder = AddProject(builder, projectDef.ProjectName, projectDef.TestComponents); |
| 552 | + } |
| 553 | + return builder.Build().Object; |
| 554 | + } |
| 555 | + |
| 556 | + private MockVbeBuilder AddProject(MockVbeBuilder builder, string projectName, IEnumerable<TestComponentSpecification> testComponents) |
| 557 | + { |
503 | 558 | var enclosingProjectBuilder = builder.ProjectBuilder(projectName, ProjectProtection.Unprotected);
|
504 | 559 |
|
505 |
| - testComponents.ForEach(c => enclosingProjectBuilder.AddComponent(c.Name, c.ModuleType, c.Content)); |
| 560 | + foreach (var testComponent in testComponents) |
| 561 | + { |
| 562 | + enclosingProjectBuilder.AddComponent(testComponent.Name, testComponent.ModuleType, testComponent.Content); |
| 563 | + } |
| 564 | + |
506 | 565 | var enclosingProject = enclosingProjectBuilder.Build();
|
507 | 566 | builder.AddProject(enclosingProject);
|
508 |
| - return builder.Build().Object; |
| 567 | + return builder; |
509 | 568 | }
|
510 | 569 |
|
511 | 570 | private IVBComponent RetrieveComponent(AccessibilityTestsDataObject tdo, string componentName)
|
|
0 commit comments