public void UnassignedVariableUsage_IgnoreQuickFixWorks() { const string inputCode = @"Sub Foo() Dim b As Boolean Dim bb As Boolean bb = b End Sub"; const string expectedCode = @"Sub Foo() '@Ignore UnassignedVariableUsage Dim b As Boolean Dim bb As Boolean bb = b End Sub"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new UnassignedVariableUsageInspection(state); var inspectionResults = inspection.GetInspectionResults(); inspectionResults.First().QuickFixes.Single(s => s is IgnoreOnceQuickFix).Fix(); Assert.AreEqual(expectedCode, component.CodeModule.Content()); }
public void UnassignedVariableUsage_ReturnsSingleResult_MultipleReferences() { const string inputCode = @"Sub tester() Dim myarr() As Variant Dim i As Long ReDim myarr(1 To 10) For i = 1 To 10 DoSomething myarr(i) Next End Sub Sub DoSomething(ByVal foo As Variant) End Sub "; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new UnassignedVariableUsageInspection(state); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(1, inspectionResults.Count()); }
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 End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new UnassignedVariableUsageInspection(state); var inspectionResults = inspection.GetInspectionResults(); new RemoveUnassignedVariableUsageQuickFix(state).Fix(inspectionResults.First()); Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText()); } }
public void AnnotationListFollowedByCommentAddsAnnotationCorrectly() { const string inputCode = @" Public Function GetSomething() As Long '@Ignore VariableNotAssigned: Is followed by a comment. Dim foo As Long GetSomething = foo End Function "; const string expectedCode = @" Public Function GetSomething() As Long '@Ignore UnassignedVariableUsage, VariableNotAssigned: Is followed by a comment. Dim foo As Long GetSomething = foo End Function "; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new UnassignedVariableUsageInspection(state); var inspectionResults = inspection.GetInspectionResults(); inspectionResults.First().QuickFixes.Single(s => s is IgnoreOnceQuickFix).Fix(); Assert.AreEqual(expectedCode, component.CodeModule.Content()); }
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(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()); }
private IEnumerable <IInspectionResult> GetInspectionResults(string code, ComponentType componentType = ComponentType.ClassModule) { var vbe = MockVbeBuilder.BuildFromSingleModule(code, componentType, out _); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new UnassignedVariableUsageInspection(state); return(inspection.GetInspectionResults(CancellationToken.None)); } }
public void UnassignedVariableUsage_NoResultIfNoReferences() { const string inputCode = @"Sub DoSomething() Dim foo End Sub"; var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new UnassignedVariableUsageInspection(state); var inspectionResults = inspection.GetInspectionResults(); Assert.IsFalse(inspectionResults.Any()); }
public void UnassignedVariableUsage_ReturnsResult() { const string inputCode = @"Sub Foo() Dim b As Boolean Dim bb As Boolean bb = b End Sub"; var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new UnassignedVariableUsageInspection(state); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(1, inspectionResults.Count()); }
public void UnassignedVariableUsage_DoesNotReturnResult() { const string inputCode = @"Sub Foo() Dim b As Boolean Dim bb As Boolean b = True bb = b End Sub"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new UnassignedVariableUsageInspection(state); var inspectionResults = inspection.GetInspectionResults(); Assert.IsFalse(inspectionResults.Any()); }
public void UnassignedVariableUsage_IgnoreQuickFixWorks() { const string inputCode = @"Sub Foo() Dim b As Boolean Dim bb As Boolean bb = b End Sub"; const string expectedCode = @"Sub Foo() '@Ignore UnassignedVariableUsage Dim b As Boolean Dim bb As Boolean bb = b 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(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.Single(s => s is IgnoreOnceQuickFix).Fix(); Assert.AreEqual(expectedCode, module.Lines()); }
public void UnassignedVariableUsage_Ignored_DoesNotReturnResult() { const string inputCode = @"Sub Foo() '@Ignore UnassignedVariableUsage Dim b As Boolean Dim bb As Boolean bb = b End Sub"; var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out _); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new UnassignedVariableUsageInspection(state); var inspectionResults = inspection.GetInspectionResults(CancellationToken.None); Assert.IsFalse(inspectionResults.Any()); } }
public void UnassignedVariableUsage_ReturnsSingleResult_MultipleReferences() { const string inputCode = @"Sub tester() Dim myarr() As Variant Dim i As Long ReDim myarr(1 To 10) For i = LBound(myarr) To UBound(myarr) Next 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(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()); }