|
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,44 @@ 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, ExpectedResult = 0)] //Duplicate module name found in a separate project |
| 454 | + [TestCase(projectTwoModuleName, ExpectedResult = 1)] //Duplicate module name found in the same project |
| 455 | + [Category("Resolver")] |
| 456 | + public int DeclarationFinder_RenameCodeModule_RespectsProjectScope(string proposedTestModuleName) |
| 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.AllDeclarations |
| 480 | + .FirstOrDefault(item => item.IdentifierName.Equals(renameTargetModuleName)); |
| 481 | + |
| 482 | + var results = parser.DeclarationFinder.FindNewDeclarationNameConflicts(proposedTestModuleName, target); |
| 483 | + return results.Count(); |
| 484 | + } |
| 485 | + } |
| 486 | + |
448 | 487 | private static string ConflictMessage(bool isConflict, string name, IEnumerable<Declaration> conflicts)
|
449 | 488 | {
|
450 | 489 | return isConflict ? $"Identifier '{name}' is a conflict but was not identified" : $"Identifier '{name}' was incorrectly found as a conflict";
|
@@ -498,14 +537,33 @@ private void AddTestComponent(AccessibilityTestsDataObject tdo, string moduleIde
|
498 | 537 | }
|
499 | 538 |
|
500 | 539 | private IVBE BuildProject(string projectName, List<TestComponentSpecification> testComponents)
|
| 540 | + { |
| 541 | + var projectDefs = new (string, IEnumerable<TestComponentSpecification>)[] { (projectName, testComponents) }; |
| 542 | + return BuildProjects(projectDefs); |
| 543 | + } |
| 544 | + |
| 545 | + private IVBE BuildProjects(IEnumerable<(string ProjectName, IEnumerable<TestComponentSpecification> TestComponents)> projectDefinitions) |
501 | 546 | {
|
502 | 547 | var builder = new MockVbeBuilder();
|
| 548 | + foreach (var projectDef in projectDefinitions) |
| 549 | + { |
| 550 | + builder = AddProject(builder, projectDef.ProjectName, projectDef.TestComponents); |
| 551 | + } |
| 552 | + return builder.Build().Object; |
| 553 | + } |
| 554 | + |
| 555 | + private MockVbeBuilder AddProject(MockVbeBuilder builder, string projectName, IEnumerable<TestComponentSpecification> testComponents) |
| 556 | + { |
503 | 557 | var enclosingProjectBuilder = builder.ProjectBuilder(projectName, ProjectProtection.Unprotected);
|
504 | 558 |
|
505 |
| - testComponents.ForEach(c => enclosingProjectBuilder.AddComponent(c.Name, c.ModuleType, c.Content)); |
| 559 | + foreach (var testComponent in testComponents) |
| 560 | + { |
| 561 | + enclosingProjectBuilder.AddComponent(testComponent.Name, testComponent.ModuleType, testComponent.Content); |
| 562 | + } |
| 563 | + |
506 | 564 | var enclosingProject = enclosingProjectBuilder.Build();
|
507 | 565 | builder.AddProject(enclosingProject);
|
508 |
| - return builder.Build().Object; |
| 566 | + return builder; |
509 | 567 | }
|
510 | 568 |
|
511 | 569 | private IVBComponent RetrieveComponent(AccessibilityTestsDataObject tdo, string componentName)
|
|
0 commit comments