Skip to content

Commit fa0e9f5

Browse files
committed
Fixed test to load DebugDeclarations, proving fixed #3284
1 parent cf766e3 commit fa0e9f5

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
lines changed

RubberduckTests/Mocks/MockParser.cs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public static class MockParser
2323
{
2424
public static RubberduckParserState ParseString(string inputCode, out QualifiedModuleName qualifiedModuleName)
2525
{
26-
2726
IVBComponent component;
2827
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component);
2928
qualifiedModuleName = new QualifiedModuleName(component);
@@ -35,7 +34,6 @@ public static RubberduckParserState ParseString(string inputCode, out QualifiedM
3534
Assert.Inconclusive("Parser Error: {0}");
3635
}
3736
return parser.State;
38-
3937
}
4038

4139
public static ParseCoordinator Create(IVBE vbe, string serializedDeclarationsPath = null)
@@ -113,16 +111,39 @@ public static ParseCoordinator Create(IVBE vbe, RubberduckParserState state, IAt
113111
parserStateManager,
114112
true);
115113
}
114+
115+
public static RubberduckParserState CreateAndParse(IVBE vbe, IInspectionListener listener, IEnumerable<string> testLibraries = null)
116+
{
117+
var parser = CreateWithLibraries(vbe, testLibraries: testLibraries);
118+
parser.Parse(new CancellationTokenSource());
119+
if (parser.State.Status >= ParserState.Error)
120+
{ Assert.Inconclusive("Parser Error"); }
116121

117-
public static RubberduckParserState CreateAndParse(IVBE vbe, string serializedDeclarationsPath = null)
122+
return parser.State;
123+
}
124+
125+
public static RubberduckParserState CreateAndParse(IVBE vbe, string serializedDeclarationsPath = null, IEnumerable<string> testLibraries = null)
118126
{
119-
var parser = Create(vbe);
127+
var parser = CreateWithLibraries(vbe, serializedDeclarationsPath, testLibraries);
120128
parser.Parse(new CancellationTokenSource());
121129
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
122130

123131
return parser.State;
124132
}
125133

134+
private static ParseCoordinator CreateWithLibraries(IVBE vbe, string serializedDeclarationsPath = null, IEnumerable<string> testLibraries = null)
135+
{
136+
var parser = Create(vbe, serializedDeclarationsPath);
137+
if (testLibraries != null)
138+
{
139+
foreach (var lib in testLibraries)
140+
{
141+
parser.State.AddTestLibrary(lib);
142+
}
143+
}
144+
return parser;
145+
}
146+
126147
private static readonly HashSet<DeclarationType> ProceduralTypes =
127148
new HashSet<DeclarationType>(new[]
128149
{
@@ -162,15 +183,5 @@ private static void AddTestLibrary(RubberduckParserState state, SerializableProj
162183
state.AddDeclaration(declaration);
163184
}
164185
}
165-
166-
public static RubberduckParserState CreateAndParse(IVBE vbe, IInspectionListener listener)
167-
{
168-
var parser = Create(vbe);
169-
parser.Parse(new CancellationTokenSource());
170-
if(parser.State.Status >= ParserState.Error)
171-
{ Assert.Inconclusive("Parser Error"); }
172-
173-
return parser.State;
174-
}
175186
}
176187
}

RubberduckTests/Refactoring/RenameTests.cs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,6 @@ public void RenameRefactoring_RefactorProperties_UpdatesReferences()
18141814
var oldName = "Column";
18151815
var refactoredName = "Rank";
18161816

1817-
var tdo = new RenameTestsDataObject(oldName, refactoredName );
18181817
var classInputOutput = new RenameTestModuleDefinition("MyClass", ComponentType.ClassModule)
18191818
{
18201819
Input = $@"Option Explicit
@@ -1824,7 +1823,7 @@ Private colValue As Long
18241823
Public Property Get {oldName}() As Long
18251824
{oldName} = colValue
18261825
End Property
1827-
Public Property Let |{oldName}(value As Long)
1826+
Public Property Let {FAUX_CURSOR}{oldName}(value As Long)
18281827
colValue = value
18291828
End Property
18301829
",
@@ -1850,7 +1849,8 @@ Dim instance As MyClass
18501849
instance.{oldName} = 97521
18511850
Debug.Print instance.{oldName};""is the value""
18521851
End Sub
1853-
", Expected = $@"Option Explicit
1852+
",
1853+
Expected = $@"Option Explicit
18541854
18551855
Public Sub useColValue()
18561856
Dim instance As MyClass
@@ -1860,8 +1860,24 @@ Dim instance As MyClass
18601860
End Sub
18611861
"
18621862
};
1863-
tdo.RefactorParamType = RefactorParams.Declaration;
1864-
PerformExpectedVersusActualRenameTests(tdo, classInputOutput, usageInputOutput);
1863+
1864+
var builder = new MockVbeBuilder();
1865+
var projectName = "Test";
1866+
var vbe = builder.ProjectBuilder(projectName, ProjectProtection.Unprotected)
1867+
.AddReference("VBA", MockVbeBuilder.LibraryPathVBA, major: 4, minor: 1, isBuiltIn: true)
1868+
.AddComponent("MyClass", ComponentType.ClassModule, classInputOutput.Input.Replace(FAUX_CURSOR, ""))
1869+
.AddComponent("Usage", ComponentType.StandardModule, usageInputOutput.Input)
1870+
.AddProjectToVbeBuilder()
1871+
.Build();
1872+
1873+
var tdo = new RenameTestsDataObject(oldName, refactoredName)
1874+
{
1875+
VBE = vbe.Object,
1876+
RefactorParamType = RefactorParams.Declaration,
1877+
SelectionModuleName = "MyClass",
1878+
ProjectName = projectName
1879+
};
1880+
PerformExpectedVersusActualRenameTests(tdo, classInputOutput, usageInputOutput, testLibraries: new[] { "VBA.4.2.xml" });
18651881
tdo.MsgBox.Verify(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxButtons>(), It.IsAny<MessageBoxIcon>()), Times.Never);
18661882
}
18671883
#endregion
@@ -2085,11 +2101,12 @@ private static void PerformExpectedVersusActualRenameTests(RenameTestsDataObject
20852101
, RenameTestModuleDefinition? inputOutput1
20862102
, RenameTestModuleDefinition? inputOutput2 = null
20872103
, RenameTestModuleDefinition? inputOutput3 = null
2088-
, RenameTestModuleDefinition? inputOutput4 = null)
2104+
, RenameTestModuleDefinition? inputOutput4 = null
2105+
, IEnumerable<string> testLibraries = null)
20892106
{
20902107
try
20912108
{
2092-
InitializeTestDataObject(tdo, inputOutput1, inputOutput2, inputOutput3, inputOutput4);
2109+
InitializeTestDataObject(tdo, inputOutput1, inputOutput2, inputOutput3, inputOutput4, testLibraries);
20932110
RunRenameRefactorScenario(tdo);
20942111
CheckRenameRefactorTestResults(tdo);
20952112
}
@@ -2103,7 +2120,8 @@ private static void InitializeTestDataObject(RenameTestsDataObject tdo
21032120
, RenameTestModuleDefinition? inputOutput1
21042121
, RenameTestModuleDefinition? inputOutput2 = null
21052122
, RenameTestModuleDefinition? inputOutput3 = null
2106-
, RenameTestModuleDefinition? inputOutput4 = null)
2123+
, RenameTestModuleDefinition? inputOutput4 = null
2124+
, IEnumerable<string> testLibraries = null)
21072125
{
21082126
var renameTMDs = new List<RenameTestModuleDefinition>();
21092127
bool cursorFound = false;
@@ -2144,7 +2162,7 @@ private static void InitializeTestDataObject(RenameTestsDataObject tdo
21442162
.Returns(tdo.MsgBoxReturn);
21452163

21462164
tdo.VBE = tdo.VBE ?? BuildProject(tdo.ProjectName, tdo.ModuleTestSetupDefs);
2147-
tdo.ParserState = MockParser.CreateAndParse(tdo.VBE);
2165+
tdo.ParserState = MockParser.CreateAndParse(tdo.VBE, testLibraries: testLibraries);
21482166

21492167
CreateQualifiedSelectionForTestCase(tdo);
21502168
tdo.RenameModel = new RenameModel(tdo.VBE, tdo.ParserState, tdo.QualifiedSelection) { NewName = tdo.NewName };
@@ -2269,7 +2287,6 @@ private static IVBE BuildProject(string projectName, List<RenameTestModuleDefini
22692287
{
22702288
var builder = new MockVbeBuilder();
22712289
var enclosingProjectBuilder = builder.ProjectBuilder(projectName, ProjectProtection.Unprotected);
2272-
22732290
foreach (var comp in testComponents)
22742291
{
22752292
if (comp.ModuleType == ComponentType.UserForm)

0 commit comments

Comments
 (0)