Skip to content

Commit 96b57ad

Browse files
Hosch250retailcoder
authored andcommitted
MultipleFolderAnnotationsInspectionTests (#1591)
1 parent dffdc13 commit 96b57ad

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System.Linq;
2+
using Microsoft.Vbe.Interop;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using Moq;
5+
using Rubberduck.Inspections;
6+
using Rubberduck.Parsing.VBA;
7+
using Rubberduck.VBEditor.VBEHost;
8+
using RubberduckTests.Mocks;
9+
10+
namespace RubberduckTests.Inspections
11+
{
12+
[TestClass]
13+
public class MultipleFolderAnnotationsInspectionTests
14+
{
15+
[TestMethod]
16+
[TestCategory("Inspections")]
17+
public void NoFolderAnnotation_NoResult()
18+
{
19+
const string inputCode =
20+
@"Public Sub Foo()
21+
Const const1 As Integer = 9
22+
End Sub";
23+
24+
//Arrange
25+
var builder = new MockVbeBuilder();
26+
VBComponent component;
27+
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
28+
var mockHost = new Mock<IHostApplication>();
29+
mockHost.SetupAllProperties();
30+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
31+
32+
parser.Parse();
33+
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
34+
35+
var inspection = new MultipleFolderAnnotationsInspection(parser.State);
36+
var inspectionResults = inspection.GetInspectionResults();
37+
38+
Assert.IsFalse(inspectionResults.Any());
39+
}
40+
41+
[TestMethod]
42+
[TestCategory("Inspections")]
43+
public void SingleFolderAnnotation_NoResult()
44+
{
45+
const string inputCode =
46+
@"'@Folder ""Foo""
47+
Public Sub Foo()
48+
Const const1 As Integer = 9
49+
End Sub";
50+
51+
//Arrange
52+
var builder = new MockVbeBuilder();
53+
VBComponent component;
54+
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
55+
var mockHost = new Mock<IHostApplication>();
56+
mockHost.SetupAllProperties();
57+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
58+
59+
parser.Parse();
60+
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
61+
62+
var inspection = new MultipleFolderAnnotationsInspection(parser.State);
63+
var inspectionResults = inspection.GetInspectionResults();
64+
65+
Assert.IsFalse(inspectionResults.Any());
66+
}
67+
68+
[TestMethod]
69+
[TestCategory("Inspections")]
70+
public void MultipleFolderAnnotations_ReturnsResult()
71+
{
72+
const string inputCode =
73+
@"'@Folder ""Foo.Bar""
74+
'@Folder ""Biz.Buz""
75+
Public Sub Foo()
76+
Const const1 As Integer = 9
77+
End Sub";
78+
79+
//Arrange
80+
var builder = new MockVbeBuilder();
81+
VBComponent component;
82+
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
83+
var mockHost = new Mock<IHostApplication>();
84+
mockHost.SetupAllProperties();
85+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
86+
87+
parser.Parse();
88+
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
89+
90+
var inspection = new ConstantNotUsedInspection(parser.State);
91+
var inspectionResults = inspection.GetInspectionResults();
92+
93+
Assert.AreEqual(1, inspectionResults.Count());
94+
}
95+
}
96+
}

RubberduckTests/RubberduckTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<Compile Include="Inspections\FunctionReturnValueNotUsedInspectionTests.cs" />
9797
<Compile Include="Inspections\GeneralInspectionTests.cs" />
9898
<Compile Include="Inspections\ImplicitActiveSheetReferenceInspectionTests.cs" />
99+
<Compile Include="Inspections\MultipleFolderAnnotationsInspectionTests.cs" />
99100
<Compile Include="Inspections\ObjectVariableNotSetInpsectionTests.cs" />
100101
<Compile Include="MockParser.cs" />
101102
<Compile Include="Inspections\MoveFieldCloserToUsageInspectionTests.cs" />

0 commit comments

Comments
 (0)