-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1996 from Hosch250/tests
Get test for ImplicitActiveSheetReference inspection working
- Loading branch information
Showing
8 changed files
with
1,085 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
138 changes: 138 additions & 0 deletions
138
RubberduckTests/Inspections/UnassignedVariableUsageInspectionTests.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,138 @@ | ||
using System.Linq; | ||
using System.Threading; | ||
using Microsoft.Vbe.Interop; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using Rubberduck.Inspections; | ||
using Rubberduck.Parsing; | ||
using Rubberduck.Parsing.VBA; | ||
using Rubberduck.VBEditor.Extensions; | ||
using Rubberduck.VBEditor.VBEHost; | ||
using RubberduckTests.Mocks; | ||
|
||
namespace RubberduckTests.Inspections | ||
{ | ||
[TestClass] | ||
public class UnassignedVariableUsageInspectionTests | ||
{ | ||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void UnassignedVariableUsage_ReturnsResult() | ||
{ | ||
const string inputCode = | ||
@"Sub Foo() | ||
Dim b As Boolean | ||
Dim bb As Boolean | ||
bb = b | ||
End Sub"; | ||
|
||
//Arrange | ||
var builder = new MockVbeBuilder(); | ||
var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none) | ||
.AddComponent("MyClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode) | ||
.Build(); | ||
var vbe = builder.AddProject(project).Build(); | ||
|
||
var mockHost = new Mock<IHostApplication>(); | ||
mockHost.SetupAllProperties(); | ||
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object)); | ||
|
||
parser.Parse(new CancellationTokenSource()); | ||
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); } | ||
|
||
var inspection = new UnassignedVariableUsageInspection(parser.State); | ||
var inspectionResults = inspection.GetInspectionResults(); | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void UnassignedVariableUsage_DoesNotReturnResult() | ||
{ | ||
const string inputCode = | ||
@"Sub Foo() | ||
Dim b As Boolean | ||
Dim bb As Boolean | ||
b = True | ||
bb = b | ||
End Sub"; | ||
|
||
//Arrange | ||
var builder = new MockVbeBuilder(); | ||
var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none) | ||
.AddComponent("MyClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode) | ||
.Build(); | ||
var vbe = builder.AddProject(project).Build(); | ||
|
||
var mockHost = new Mock<IHostApplication>(); | ||
mockHost.SetupAllProperties(); | ||
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object)); | ||
|
||
parser.Parse(new CancellationTokenSource()); | ||
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); } | ||
|
||
var inspection = new UnassignedVariableUsageInspection(parser.State); | ||
var inspectionResults = inspection.GetInspectionResults(); | ||
|
||
Assert.IsFalse(inspectionResults.Any()); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void UnassignedVariableUsage_QuickFixWorks() | ||
{ | ||
const string inputCode = | ||
@"Sub Foo() | ||
Dim b As Boolean | ||
Dim bb As Boolean | ||
bb = b | ||
End Sub"; | ||
|
||
const string expectedCode = | ||
@"Sub Foo() | ||
Dim b As Boolean | ||
Dim bb As Boolean | ||
TODOTODO = TODO | ||
End Sub"; | ||
|
||
//Arrange | ||
var builder = new MockVbeBuilder(); | ||
VBComponent component; | ||
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); | ||
var project = vbe.Object.VBProjects.Item(0); | ||
var module = project.VBComponents.Item(0).CodeModule; | ||
var mockHost = new Mock<IHostApplication>(); | ||
mockHost.SetupAllProperties(); | ||
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object)); | ||
|
||
parser.Parse(new CancellationTokenSource()); | ||
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); } | ||
|
||
var inspection = new UnassignedVariableUsageInspection(parser.State); | ||
var inspectionResults = inspection.GetInspectionResults(); | ||
|
||
inspectionResults.First().QuickFixes.First().Fix(); | ||
|
||
Assert.AreEqual(expectedCode, module.Lines()); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void InspectionType() | ||
{ | ||
var inspection = new UnassignedVariableUsageInspection(null); | ||
Assert.AreEqual(CodeInspectionType.CodeQualityIssues, inspection.InspectionType); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void InspectionName() | ||
{ | ||
const string inspectionName = "UnassignedVariableUsageInspection"; | ||
var inspection = new UnassignedVariableUsageInspection(null); | ||
|
||
Assert.AreEqual(inspectionName, inspection.Name); | ||
} | ||
} | ||
} |
Oops, something went wrong.