Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
326 changes: 326 additions & 0 deletions
326
RubberduckTests/Inspections/DefTypeStatementInspectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,326 @@ | ||
using NUnit.Framework; | ||
using Rubberduck.Parsing.Inspections.Resources; | ||
using Rubberduck.Inspections.Concrete; | ||
using RubberduckTests.Mocks; | ||
using System.Threading; | ||
using System.Linq; | ||
|
||
namespace RubberduckTests.Inspections | ||
{ | ||
[TestFixture] | ||
public class DefTypeStatementInspectionTests | ||
{ | ||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_InspectionType() | ||
{ | ||
var inspection = new DefTypeStatementInspection(null); | ||
const CodeInspectionType expectedInspection = CodeInspectionType.LanguageOpportunities; | ||
|
||
Assert.AreEqual(expectedInspection, inspection.InspectionType); | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_Bool() | ||
{ | ||
const string inputCode = | ||
@"DefBool A | ||
Public Function aFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_Byte() | ||
{ | ||
const string inputCode = | ||
@"DefByte B | ||
Public Function bFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_Integer() | ||
{ | ||
const string inputCode = | ||
@"DefInt C | ||
Public Function cFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_Long() | ||
{ | ||
const string inputCode = | ||
@"DefLng D | ||
Public Function dFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_Currency() | ||
{ | ||
const string inputCode = | ||
@"DefCur E | ||
Public Function eFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_Single() | ||
{ | ||
const string inputCode = | ||
@"DefSng F | ||
Public Function fFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_Double() | ||
{ | ||
const string inputCode = | ||
@"DefDbl G | ||
Public Function gFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_Date() | ||
{ | ||
const string inputCode = | ||
@"DefDate H | ||
Public Function hFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_String() | ||
{ | ||
const string inputCode = | ||
@"DefStr I | ||
Public Function iFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_Object() | ||
{ | ||
const string inputCode = | ||
@"DefObj J | ||
Public Function jFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_Variant() | ||
{ | ||
const string inputCode = | ||
@"DefVar K | ||
Public Function kFoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_SingleResultIgnored() | ||
{ | ||
const string inputCode = | ||
@"'@Ignore DefTypeStatement | ||
DefInt F | ||
Public Function FunctionWontBeFoundInResult() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(0, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_AllDefTypeAreFound() | ||
{ | ||
const string inputCode = | ||
@"DefBool A | ||
DefByte B | ||
DefInt C | ||
DefLng D | ||
DefCur E | ||
DefSng F | ||
DefDbl G | ||
DefDate H | ||
DefStr I | ||
DefObj J | ||
DefVar K | ||
Public Function Zoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(11, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("Inspections")] | ||
public void DefType_AllDefTypeAreIgnored() | ||
{ | ||
const string inputCode = | ||
@"'@Ignore DefTypeStatement | ||
DefBool A | ||
DefByte B | ||
DefInt C | ||
DefLng D | ||
DefCur E | ||
DefSng F | ||
DefDbl G | ||
DefDate H | ||
DefStr I | ||
DefObj J | ||
DefVar K | ||
Public Function Zoo() | ||
End Function"; | ||
|
||
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); | ||
using (var state = MockParser.CreateAndParse(vbe.Object)) | ||
{ | ||
var inspection = new DefTypeStatementInspection(state); | ||
var inspector = InspectionsHelper.GetInspector(inspection); | ||
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; | ||
|
||
Assert.AreEqual(0, inspectionResults.Count()); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters