Skip to content

Commit 5b0c6c7

Browse files
authored
Merge pull request #3810 from Vogel612/rename-refactoring
Categorized, tweaked, and added refactor/rename tests.
2 parents 7484e34 + fa0e9f5 commit 5b0c6c7

File tree

10 files changed

+315
-113
lines changed

10 files changed

+315
-113
lines changed

RubberduckTests/Grammar/AnnotationTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public void InterfaceAnnotation_TypeIsInterface()
106106
Assert.AreEqual(AnnotationType.Interface, annotation.AnnotationType);
107107
}
108108

109+
[Category("Grammar")]
110+
[Category("Annotations")]
109111
[Test]
110112
public void DescriptionAnnotation_TypeIsDescription()
111113
{

RubberduckTests/IoCContainer/IoCRegistrationTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace RubberduckTests.IoCContainer
1414
public class IoCRegistrationTests
1515
{
1616
[Test]
17+
[Category("IoC_Registration")]
1718
public void RegistrationOfRubberduckIoCContainerWithSC_NoException()
1819
{
1920
var vbeBuilder = new MockVbeBuilder();
@@ -36,6 +37,7 @@ public void RegistrationOfRubberduckIoCContainerWithSC_NoException()
3637
}
3738

3839
[Test]
40+
[Category("IoC_Registration")]
3941
public void RegistrationOfRubberduckIoCContainerWithoutSC_NoException()
4042
{
4143
var vbeBuilder = new MockVbeBuilder();

RubberduckTests/IoCContainer/IoCResolvingTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace RubberduckTests.IoCContainer
1717
public class IoCResolvingTests
1818
{
1919
[Test]
20+
[Category("IoC_Registration")]
2021
public void ResolveInspections_NoException()
2122
{
2223
var vbeBuilder = new MockVbeBuilder();
@@ -53,6 +54,7 @@ public void ResolveInspections_NoException()
5354
}
5455

5556
[Test]
57+
[Category("IoC_Registration")]
5658
public void ResolveRubberduckParserState_NoException()
5759
{
5860
var vbeBuilder = new MockVbeBuilder();

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: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ End Sub"
416416
//below can only be tested if implemented (and tested) within Excel.
417417

418418
[Test, Ignore("")]
419+
[Category("Refactorings")]
420+
[Category("Rename")]
419421
public void RenameRefactoring_RenameControlFromEventHandler()
420422
{
421423
var tdo = new RenameTestsDataObject(selection: "cmdBtn1", newName: "cmdBigButton");
@@ -449,6 +451,8 @@ End Sub"
449451
}
450452

451453
[Test, Ignore("")]
454+
[Category("Refactorings")]
455+
[Category("Rename")]
452456
public void RenameRefactoring_RenameControlFromEventHandlerNameCollision()
453457
{
454458
var tdo = new RenameTestsDataObject(selection: "cmdBtn1", newName: "cmdBigButton");
@@ -484,6 +488,8 @@ End Sub"
484488
}
485489

486490
[Test, Ignore("")]
491+
[Category("Refactorings")]
492+
[Category("Rename")]
487493
public void RenameRefactoring_RenameControlRenameInReference()
488494
{
489495
var tdo = new RenameTestsDataObject(selection: "cmdBtn1", newName: "cmdBigButton");
@@ -519,6 +525,8 @@ End Sub"
519525
}
520526

521527
[Test, Ignore("")]
528+
[Category("Refactorings")]
529+
[Category("Rename")]
522530
public void RenameRefactoring_RenameControlFromEventHandlerReference()
523531
{
524532
var tdo = new RenameTestsDataObject(selection: "cmdBtn1", newName: "cmdBigButton");
@@ -554,6 +562,8 @@ End Sub"
554562
}
555563

556564
[Test, Ignore("")]
565+
[Category("Refactorings")]
566+
[Category("Rename")]
557567
public void RenameRefactoring_RenameControlHandlesUnderscoresInNewName()
558568
{
559569
var tdo = new RenameTestsDataObject(selection: "bigButton_ClickAgain", newName: "bigButton_ClickAgain_AndAgain");
@@ -571,6 +581,8 @@ End Sub"
571581
}
572582

573583
[Test, Ignore("")]
584+
[Category("Refactorings")]
585+
[Category("Rename")]
574586
public void RenameRefactoring_RenameControlSimilarNames()
575587
{
576588
var tdo = new RenameTestsDataObject(selection: "bigButton", newName: "smallButton");
@@ -1793,6 +1805,83 @@ End Sub"
17931805
tdo.MsgBox.Verify(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxButtons>(), It.IsAny<MessageBoxIcon>()), Times.Never);
17941806
}
17951807
#endregion
1808+
#region Property Tests
1809+
[Test]
1810+
[Category("Refactorings")]
1811+
[Category("Rename")]
1812+
public void RenameRefactoring_RefactorProperties_UpdatesReferences()
1813+
{
1814+
var oldName = "Column";
1815+
var refactoredName = "Rank";
1816+
1817+
var classInputOutput = new RenameTestModuleDefinition("MyClass", ComponentType.ClassModule)
1818+
{
1819+
Input = $@"Option Explicit
1820+
1821+
Private colValue As Long
1822+
1823+
Public Property Get {oldName}() As Long
1824+
{oldName} = colValue
1825+
End Property
1826+
Public Property Let {FAUX_CURSOR}{oldName}(value As Long)
1827+
colValue = value
1828+
End Property
1829+
",
1830+
Expected = $@"Option Explicit
1831+
1832+
Private colValue As Long
1833+
1834+
Public Property Get {refactoredName}() As Long
1835+
{refactoredName} = colValue
1836+
End Property
1837+
Public Property Let {refactoredName}(value As Long)
1838+
colValue = value
1839+
End Property
1840+
"
1841+
};
1842+
var usageInputOutput = new RenameTestModuleDefinition("Usage", ComponentType.StandardModule)
1843+
{
1844+
Input = $@"Option Explicit
1845+
1846+
Public Sub useColValue()
1847+
Dim instance As MyClass
1848+
Set instance = New MyClass
1849+
instance.{oldName} = 97521
1850+
Debug.Print instance.{oldName};""is the value""
1851+
End Sub
1852+
",
1853+
Expected = $@"Option Explicit
1854+
1855+
Public Sub useColValue()
1856+
Dim instance As MyClass
1857+
Set instance = New MyClass
1858+
instance.{refactoredName} = 97521
1859+
Debug.Print instance.{refactoredName};""is the value""
1860+
End Sub
1861+
"
1862+
};
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" });
1881+
tdo.MsgBox.Verify(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxButtons>(), It.IsAny<MessageBoxIcon>()), Times.Never);
1882+
}
1883+
#endregion
1884+
17961885
#region Other Tests
17971886

17981887
[Test]
@@ -2012,11 +2101,12 @@ private static void PerformExpectedVersusActualRenameTests(RenameTestsDataObject
20122101
, RenameTestModuleDefinition? inputOutput1
20132102
, RenameTestModuleDefinition? inputOutput2 = null
20142103
, RenameTestModuleDefinition? inputOutput3 = null
2015-
, RenameTestModuleDefinition? inputOutput4 = null)
2104+
, RenameTestModuleDefinition? inputOutput4 = null
2105+
, IEnumerable<string> testLibraries = null)
20162106
{
20172107
try
20182108
{
2019-
InitializeTestDataObject(tdo, inputOutput1, inputOutput2, inputOutput3, inputOutput4);
2109+
InitializeTestDataObject(tdo, inputOutput1, inputOutput2, inputOutput3, inputOutput4, testLibraries);
20202110
RunRenameRefactorScenario(tdo);
20212111
CheckRenameRefactorTestResults(tdo);
20222112
}
@@ -2030,7 +2120,8 @@ private static void InitializeTestDataObject(RenameTestsDataObject tdo
20302120
, RenameTestModuleDefinition? inputOutput1
20312121
, RenameTestModuleDefinition? inputOutput2 = null
20322122
, RenameTestModuleDefinition? inputOutput3 = null
2033-
, RenameTestModuleDefinition? inputOutput4 = null)
2123+
, RenameTestModuleDefinition? inputOutput4 = null
2124+
, IEnumerable<string> testLibraries = null)
20342125
{
20352126
var renameTMDs = new List<RenameTestModuleDefinition>();
20362127
bool cursorFound = false;
@@ -2071,7 +2162,7 @@ private static void InitializeTestDataObject(RenameTestsDataObject tdo
20712162
.Returns(tdo.MsgBoxReturn);
20722163

20732164
tdo.VBE = tdo.VBE ?? BuildProject(tdo.ProjectName, tdo.ModuleTestSetupDefs);
2074-
tdo.ParserState = MockParser.CreateAndParse(tdo.VBE);
2165+
tdo.ParserState = MockParser.CreateAndParse(tdo.VBE, testLibraries: testLibraries);
20752166

20762167
CreateQualifiedSelectionForTestCase(tdo);
20772168
tdo.RenameModel = new RenameModel(tdo.VBE, tdo.ParserState, tdo.QualifiedSelection) { NewName = tdo.NewName };
@@ -2196,7 +2287,6 @@ private static IVBE BuildProject(string projectName, List<RenameTestModuleDefini
21962287
{
21972288
var builder = new MockVbeBuilder();
21982289
var enclosingProjectBuilder = builder.ProjectBuilder(projectName, ProjectProtection.Unprotected);
2199-
22002290
foreach (var comp in testComponents)
22012291
{
22022292
if (comp.ModuleType == ComponentType.UserForm)

RubberduckTests/Settings/HotkeyFactoryTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace RubberduckTests.Settings
1111
public class HotkeyFactoryTests
1212
{
1313
[Test]
14+
[Category("Hotkeys")]
1415
public void CreatingHotkeyReturnsNullWhenNoSettingProvided()
1516
{
1617
var factory = new HotkeyFactory(null);
@@ -21,6 +22,7 @@ public void CreatingHotkeyReturnsNullWhenNoSettingProvided()
2122
}
2223

2324
[Test]
25+
[Category("Hotkeys")]
2426
public void CreatingHotkeyReturnsNullWhenNoMatchingCommandExists()
2527
{
2628
var mockCommand = new Mock<CommandBase>(null).Object;
@@ -33,6 +35,7 @@ public void CreatingHotkeyReturnsNullWhenNoMatchingCommandExists()
3335
}
3436

3537
[Test]
38+
[Category("Hotkeys")]
3639
public void CreatingHotkeyReturnsCorrectResult()
3740
{
3841
var mockCommand = new Mock<CommandBase>(null).Object;

RubberduckTests/VBEditor/ComSafeManagerTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace RubberduckTests.VBEditor
66
[TestFixture()]
77
public class ComSafeManagerTests
88
{
9-
[Test()]
9+
[Test]
10+
[Category("COM")]
1011
public void ComSafeReturnedOnSecondIvokationOfGetCurrentComSafeIsTheSame()
1112
{
1213
ComSafeManager.DisposeAndResetComSafe(); //Resetting to get a claen start.
@@ -17,7 +18,8 @@ public void ComSafeReturnedOnSecondIvokationOfGetCurrentComSafeIsTheSame()
1718
Assert.AreSame(comSafe1, comSafe2);
1819
}
1920

20-
[Test()]
21+
[Test]
22+
[Category("COM")]
2123
public void AfterCallingResetComSafeGetCurrentComSafeReturnsDifferentSafe()
2224
{
2325
ComSafeManager.DisposeAndResetComSafe(); //Resetting to get a claen start.

0 commit comments

Comments
 (0)