Skip to content

Commit b93d619

Browse files
committed
Add tests for ObsoleteCallingConventionInspection
1 parent ea88406 commit b93d619

File tree

3 files changed

+122
-5
lines changed

3 files changed

+122
-5
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCallingConventionInspection.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
63
using Antlr4.Runtime;
74
using Rubberduck.Inspections.Abstract;
8-
using Rubberduck.Inspections.Concrete;
95
using Rubberduck.Inspections.Results;
106
using Rubberduck.Parsing;
117
using Rubberduck.Parsing.Grammar;
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using System.Linq;
2+
using System.Threading;
3+
using NUnit.Framework;
4+
using Rubberduck.Inspections.Inspections.Concrete;
5+
using RubberduckTests.Mocks;
6+
7+
namespace RubberduckTests.Inspections
8+
{
9+
[TestFixture]
10+
public class ObsoleteCallingConventionInspectionTests
11+
{
12+
[Test]
13+
[Category("Inspections")]
14+
public void ObsoleteCallingConvention_ReturnsResult()
15+
{
16+
const string inputCode =
17+
@"Private Declare Sub Beep CDecl Lib ""kernel32"" (dwFreq As Any, dwDuration As Any)";
18+
19+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
20+
using (var state = MockParser.CreateAndParse(vbe.Object))
21+
{
22+
23+
var inspection = new ObsoleteCallingConventionInspection(state);
24+
var inspector = InspectionsHelper.GetInspector(inspection);
25+
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;
26+
27+
Assert.AreEqual(1, inspectionResults.Count());
28+
}
29+
}
30+
31+
[Test]
32+
[Category("Inspections")]
33+
public void ObsoleteCallingConvention_DoesNotReturnResult()
34+
{
35+
const string inputCode =
36+
@"Private Declare Sub Beep Lib ""kernel32"" (dwFreq As Any, dwDuration As Any)";
37+
38+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
39+
using (var state = MockParser.CreateAndParse(vbe.Object))
40+
{
41+
42+
var inspection = new ObsoleteCallingConventionInspection(state);
43+
var inspector = InspectionsHelper.GetInspector(inspection);
44+
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;
45+
46+
Assert.AreEqual(0, inspectionResults.Count());
47+
}
48+
}
49+
50+
[Test]
51+
[Category("Inspections")]
52+
public void ObsoleteCallingConvention_ReturnsMultipleResults()
53+
{
54+
const string inputCode =
55+
@"Private Declare Sub Beep CDecl Lib ""kernel32"" (dwFreq As Any, dwDuration As Any)
56+
Private Declare Sub Sleep CDecl Lib ""kernel32"" (ByVal dwMilliseconds As Long)";
57+
58+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
59+
using (var state = MockParser.CreateAndParse(vbe.Object))
60+
{
61+
62+
var inspection = new ObsoleteCallingConventionInspection(state);
63+
var inspector = InspectionsHelper.GetInspector(inspection);
64+
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;
65+
66+
Assert.AreEqual(2, inspectionResults.Count());
67+
}
68+
}
69+
70+
[Test]
71+
[Category("Inspections")]
72+
public void ObsoleteCallingConvention_ReturnsResults_SomeObsoleteCallingConventions()
73+
{
74+
const string inputCode =
75+
@"Private Declare Sub Beep CDecl Lib ""kernel32"" (dwFreq As Any, dwDuration As Any)
76+
Private Declare Sub Sleep Lib ""kernel32"" (ByVal dwMilliseconds As Long)";
77+
78+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
79+
using (var state = MockParser.CreateAndParse(vbe.Object))
80+
{
81+
82+
var inspection = new ObsoleteCallingConventionInspection(state);
83+
var inspector = InspectionsHelper.GetInspector(inspection);
84+
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;
85+
86+
Assert.AreEqual(1, inspectionResults.Count());
87+
}
88+
}
89+
90+
[Test]
91+
[Category("Inspections")]
92+
public void ObsoleteCallingConvention_Ignored_DoesNotReturnResult()
93+
{
94+
const string inputCode =
95+
@"'@Ignore ObsoleteCallingConvention
96+
Private Declare Sub Beep CDecl Lib ""kernel32"" (dwFreq As Any, dwDuration As Any)";
97+
98+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
99+
using (var state = MockParser.CreateAndParse(vbe.Object))
100+
{
101+
102+
var inspection = new ObsoleteCallingConventionInspection(state);
103+
var inspector = InspectionsHelper.GetInspector(inspection);
104+
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;
105+
106+
Assert.IsFalse(inspectionResults.Any());
107+
}
108+
}
109+
110+
[Test]
111+
[Category("Inspections")]
112+
public void InspectionName()
113+
{
114+
const string inspectionName = "ObsoleteCallingConventionInspection";
115+
var inspection = new ObsoleteCallingConventionInspection(null);
116+
117+
Assert.AreEqual(inspectionName, inspection.Name);
118+
}
119+
}
120+
}

RubberduckTests/RubberduckTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<Compile Include="CodeAnalysis\CodeMetrics\LineCountTests.cs" />
107107
<Compile Include="CodeExplorer\CodeExplorerTests.cs" />
108108
<Compile Include="FlagSanityTests.cs" />
109+
<Compile Include="Inspections\ObsoleteCallingConventionInspectionTests.cs" />
109110
<Compile Include="Mocks\MockAddInBuilder.cs" />
110111
<Compile Include="Inspections\ObsoleteMemberUsageInspectionTests.cs" />
111112
<Compile Include="Mocks\MockVbeEvents.cs" />

0 commit comments

Comments
 (0)