public void VariableNotAssigned_ReturnsResult() { const string inputCode = @"Sub Foo() Dim var1 As String End Sub"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var inspection = new VariableNotUsedInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(1, inspectionResults.Count()); }
public void UnassignedVariable_DoesNotReturnResult() { const string inputCode = @"Function Foo() As Boolean Dim var1 as String var1 = ""test"" Goo var1 End Function Sub Goo(ByVal arg1 As String) End Sub"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var inspection = new VariableNotUsedInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(0, inspectionResults.Count()); }
public void UnassignedVariable_ReturnsResult_QuickFixWorks() { const string inputCode = @"Sub Foo() Dim var1 As String End Sub"; const string expectedCode = @"Sub Foo() 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()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var inspection = new VariableNotUsedInspection(parser.State); inspection.GetInspectionResults().First().QuickFixes.First().Fix(); Assert.AreEqual(expectedCode, module.Lines()); }