Skip to content

Commit a4919ab

Browse files
committed
Emptz module inspection skeleton and tests.
1 parent c9763e5 commit a4919ab

File tree

4 files changed

+383
-0
lines changed

4 files changed

+383
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Rubberduck.Inspections.Abstract;
7+
using Rubberduck.Parsing.Inspections.Abstract;
8+
using Rubberduck.Parsing.Inspections.Resources;
9+
using Rubberduck.Parsing.VBA;
10+
11+
namespace Rubberduck.Inspections.Concrete
12+
{
13+
class EmptyModuleInspection : InspectionBase
14+
{
15+
public EmptyModuleInspection(RubberduckParserState state, CodeInspectionSeverity defaultSeverity = CodeInspectionSeverity.Hint)
16+
:base(state, defaultSeverity)
17+
{ }
18+
19+
public override CodeInspectionType InspectionType => CodeInspectionType.MaintainabilityAndReadabilityIssues;
20+
21+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
22+
{
23+
throw new NotImplementedException();
24+
}
25+
}
26+
}

Rubberduck.Inspections/Rubberduck.Inspections.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="Abstract\ParseTreeInspectionBase.cs" />
6363
<Compile Include="Concrete\ApplicationWorksheetFunctionInspection.cs" />
6464
<Compile Include="Concrete\AssignedByValParameterInspection.cs" />
65+
<Compile Include="Concrete\EmptyModuleInspection.cs" />
6566
<Compile Include="Concrete\EmptyBlockInspectionListenerBase.cs" />
6667
<Compile Include="Concrete\EmptyCaseBlockInspection.cs" />
6768
<Compile Include="Concrete\EmptyDoWhileBlockInspection.cs" />
Lines changed: 355 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,355 @@
1+
using System.Linq;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using Rubberduck.Inspections.Concrete;
4+
using Rubberduck.Parsing.Inspections.Resources;
5+
using Rubberduck.VBEditor.SafeComWrappers;
6+
using RubberduckTests.Mocks;
7+
8+
namespace RubberduckTests.Inspections
9+
{
10+
[TestClass]
11+
public class EmptyModuleInspectionTests
12+
{
13+
[TestMethod]
14+
[TestCategory("Inspections")]
15+
public void ModuleWithContentNotRepresentingFunctionality_ReturnsResult()
16+
{
17+
const string inputCode =
18+
@"Option Base 1
19+
Option Compare Binary
20+
Option Explicit
21+
Option Private Module
22+
23+
'Nothing to see here.
24+
25+
DefBool B: DefByte Y: DefInt I: DefLng L: DefLngLng N: DefLngPtr P: DefCur C: DefSng G: DefDbl D: DefDate T: DefStr E: DefObj O: DefVar V
26+
27+
'Here, neither! _
28+
";
29+
30+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
31+
using (var state = MockParser.CreateAndParse(vbe.Object))
32+
{
33+
34+
var inspection = new EmptyModuleInspection(state);
35+
var inspectionResults = inspection.GetInspectionResults();
36+
37+
Assert.AreEqual(1, inspectionResults.Count());
38+
}
39+
}
40+
41+
[TestMethod]
42+
[TestCategory("Inspections")]
43+
public void ClassWithContentNotRepresentingFunctionality_ReturnsResult()
44+
{
45+
const string inputCode =
46+
@"Option Base 1
47+
Option Compare Binary
48+
Option Explicit
49+
50+
'Nothing to see here.
51+
52+
DefBool B: DefByte Y: DefInt I: DefLng L: DefLngLng N: DefLngPtr P: DefCur C: DefSng G: DefDbl D: DefDate T: DefStr E: DefObj O: DefVar V
53+
54+
'Here, neither! _
55+
";
56+
57+
var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out _);
58+
using (var state = MockParser.CreateAndParse(vbe.Object))
59+
{
60+
61+
var inspection = new EmptyModuleInspection(state);
62+
var inspectionResults = inspection.GetInspectionResults();
63+
64+
Assert.AreEqual(1, inspectionResults.Count());
65+
}
66+
}
67+
68+
[TestMethod]
69+
[TestCategory("Inspections")]
70+
public void ModuleWithFunction_DoesNotReturnResult()
71+
{
72+
const string inputCode =
73+
@"Private Function Foo() As String
74+
End Function
75+
";
76+
77+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
78+
using (var state = MockParser.CreateAndParse(vbe.Object))
79+
{
80+
81+
var inspection = new EmptyModuleInspection(state);
82+
var inspectionResults = inspection.GetInspectionResults();
83+
84+
Assert.IsFalse(inspectionResults.Any());
85+
}
86+
}
87+
88+
[TestMethod]
89+
[TestCategory("Inspections")]
90+
public void ModuleWithProcedure_DoesNotReturnResult()
91+
{
92+
const string inputCode =
93+
@"Private Sub Foo()
94+
End Sub
95+
";
96+
97+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
98+
using (var state = MockParser.CreateAndParse(vbe.Object))
99+
{
100+
101+
var inspection = new EmptyModuleInspection(state);
102+
var inspectionResults = inspection.GetInspectionResults();
103+
104+
Assert.IsFalse(inspectionResults.Any());
105+
}
106+
}
107+
108+
[TestMethod]
109+
[TestCategory("Inspections")]
110+
public void ModuleWithPropertyGet_DoesNotReturnResult()
111+
{
112+
const string inputCode =
113+
@"Public Property Get Foo()
114+
End Property
115+
";
116+
117+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
118+
using (var state = MockParser.CreateAndParse(vbe.Object))
119+
{
120+
121+
var inspection = new EmptyModuleInspection(state);
122+
var inspectionResults = inspection.GetInspectionResults();
123+
124+
Assert.IsFalse(inspectionResults.Any());
125+
}
126+
}
127+
128+
[TestMethod]
129+
[TestCategory("Inspections")]
130+
public void ModuleWithPropertySet_DoesNotReturnResult()
131+
{
132+
const string inputCode =
133+
@"Public Property Set Foo(rhs As Variant)
134+
End Property
135+
";
136+
137+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
138+
using (var state = MockParser.CreateAndParse(vbe.Object))
139+
{
140+
141+
var inspection = new EmptyModuleInspection(state);
142+
var inspectionResults = inspection.GetInspectionResults();
143+
144+
Assert.IsFalse(inspectionResults.Any());
145+
}
146+
}
147+
148+
[TestMethod]
149+
[TestCategory("Inspections")]
150+
public void ModuleWithPropertyLet_DoesNotReturnResult()
151+
{
152+
const string inputCode =
153+
@"Public Property Let Foo(rhs As Variant)
154+
End Property
155+
";
156+
157+
var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.UserForm, out _);
158+
using (var state = MockParser.CreateAndParse(vbe.Object))
159+
{
160+
161+
var inspection = new EmptyModuleInspection(state);
162+
var inspectionResults = inspection.GetInspectionResults();
163+
164+
Assert.IsFalse(inspectionResults.Any());
165+
}
166+
}
167+
168+
[TestMethod]
169+
[TestCategory("Inspections")]
170+
public void ModuleWithEnum_DoesNotReturnResult()
171+
{
172+
const string inputCode =
173+
@"Private Enum Foo
174+
Bar
175+
End Enum
176+
";
177+
178+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
179+
using (var state = MockParser.CreateAndParse(vbe.Object))
180+
{
181+
182+
var inspection = new EmptyModuleInspection(state);
183+
var inspectionResults = inspection.GetInspectionResults();
184+
185+
Assert.IsFalse(inspectionResults.Any());
186+
}
187+
}
188+
189+
[TestMethod]
190+
[TestCategory("Inspections")]
191+
public void ModuleWithPrivateUDT_DoesNotReturnResult()
192+
{
193+
const string inputCode =
194+
@"Private Type Foo
195+
Bar As String
196+
End Type
197+
";
198+
199+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
200+
using (var state = MockParser.CreateAndParse(vbe.Object))
201+
{
202+
203+
var inspection = new EmptyModuleInspection(state);
204+
var inspectionResults = inspection.GetInspectionResults();
205+
206+
Assert.IsFalse(inspectionResults.Any());
207+
}
208+
}
209+
210+
[TestMethod]
211+
[TestCategory("Inspections")]
212+
public void ModuleWithPublicUDT_DoesNotReturnResult()
213+
{
214+
const string inputCode =
215+
@"Public Type Foo
216+
Bar As String
217+
End Type
218+
";
219+
220+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
221+
using (var state = MockParser.CreateAndParse(vbe.Object))
222+
{
223+
224+
var inspection = new EmptyModuleInspection(state);
225+
var inspectionResults = inspection.GetInspectionResults();
226+
227+
Assert.IsFalse(inspectionResults.Any());
228+
}
229+
}
230+
231+
[TestMethod]
232+
[TestCategory("Inspections")]
233+
public void ModuleWithInstanceVariable_DoesNotReturnResult()
234+
{
235+
const string inputCode =
236+
@"Private foo As String";
237+
238+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
239+
using (var state = MockParser.CreateAndParse(vbe.Object))
240+
{
241+
242+
var inspection = new EmptyModuleInspection(state);
243+
var inspectionResults = inspection.GetInspectionResults();
244+
245+
Assert.IsFalse(inspectionResults.Any());
246+
}
247+
}
248+
249+
[TestMethod]
250+
[TestCategory("Inspections")]
251+
public void ModuleWithConstant_DoesNotReturnResult()
252+
{
253+
const string inputCode =
254+
@"Private Const foo As String = """"";
255+
256+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
257+
using (var state = MockParser.CreateAndParse(vbe.Object))
258+
{
259+
260+
var inspection = new EmptyModuleInspection(state);
261+
var inspectionResults = inspection.GetInspectionResults();
262+
263+
Assert.IsFalse(inspectionResults.Any());
264+
}
265+
}
266+
267+
[TestMethod]
268+
[TestCategory("Inspections")]
269+
public void ModuleWithEvent_DoesNotReturnResult()
270+
{
271+
const string inputCode =
272+
@"Public Event Foo(bar As Variant)";
273+
274+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
275+
using (var state = MockParser.CreateAndParse(vbe.Object))
276+
{
277+
278+
var inspection = new EmptyModuleInspection(state);
279+
var inspectionResults = inspection.GetInspectionResults();
280+
281+
Assert.IsFalse(inspectionResults.Any());
282+
}
283+
}
284+
285+
[TestMethod]
286+
[TestCategory("Inspections")]
287+
public void EmptyDocumentModule_DoesNotReturnResult()
288+
{
289+
const string inputCode = "";
290+
291+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
292+
using (var state = MockParser.CreateAndParse(vbe.Object))
293+
{
294+
295+
var inspection = new EmptyModuleInspection(state);
296+
var inspectionResults = inspection.GetInspectionResults();
297+
298+
Assert.IsFalse(inspectionResults.Any());
299+
}
300+
}
301+
302+
[TestMethod]
303+
[TestCategory("Inspections")]
304+
public void EmptyUserForm_DoesNotReturnResult()
305+
{
306+
const string inputCode = "";
307+
308+
var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.Document, out _);
309+
using (var state = MockParser.CreateAndParse(vbe.Object))
310+
{
311+
312+
var inspection = new EmptyModuleInspection(state);
313+
var inspectionResults = inspection.GetInspectionResults();
314+
315+
Assert.IsFalse(inspectionResults.Any());
316+
}
317+
}
318+
319+
[TestMethod]
320+
[TestCategory("Inspections")]
321+
public void EmptyModule_Ignored_DoesNotReturnResult()
322+
{
323+
const string inputCode = "'@Ignore EmptyModule";
324+
325+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
326+
using (var state = MockParser.CreateAndParse(vbe.Object))
327+
{
328+
329+
var inspection = new EmptyModuleInspection(state);
330+
var inspectionResults = inspection.GetInspectionResults();
331+
332+
Assert.IsFalse(inspectionResults.Any());
333+
}
334+
}
335+
336+
337+
[TestMethod]
338+
[TestCategory("Inspections")]
339+
public void InspectionType()
340+
{
341+
var inspection = new EmptyModuleInspection(null);
342+
Assert.AreEqual(CodeInspectionType.MaintainabilityAndReadabilityIssues, inspection.InspectionType);
343+
}
344+
345+
[TestMethod]
346+
[TestCategory("Inspections")]
347+
public void InspectionName()
348+
{
349+
const string inspectionName = "EmptyModuleInspection";
350+
var inspection = new EmptyModuleInspection(null);
351+
352+
Assert.AreEqual(inspectionName, inspection.Name);
353+
}
354+
}
355+
}

RubberduckTests/RubberduckTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
<Compile Include="Inspections\ShadowedDeclarationInspectionTests.cs" />
128128
<Compile Include="Inspections\StopKeywordInspectionTests.cs" />
129129
<Compile Include="Inspections\OptionBaseZeroInspectionTests.cs" />
130+
<Compile Include="Inspections\EmptyModuleInspectionTests.cs" />
130131
<Compile Include="QuickFixes\AssignedByValParameterMakeLocalCopyQuickFixTests.cs" />
131132
<Compile Include="QuickFixes\ChangeProcedureToFunctionQuickFixTests.cs" />
132133
<Compile Include="QuickFixes\DeclareAsExplicitVariantQuickFixTests.cs" />

0 commit comments

Comments
 (0)