public void NotAlreadySpecified_QuickFixWorks() { const string inputCode = @""; const string expectedCode = @"Option Explicit "; //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 OptionExplicitInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); inspectionResults.First().QuickFixes.First().Fix(); Assert.AreEqual(expectedCode, module.Lines()); }
public void InspectionName() { const string inspectionName = "OptionExplicitInspection"; var inspection = new OptionExplicitInspection(null); Assert.AreEqual(inspectionName, inspection.Name); }
public void NotAlreadySpecified_ReturnsMultipleResults() { const string inputCode = @""; //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode) .AddComponent("Class2", 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 OptionExplicitInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(2, inspectionResults.Count()); }
public void OptionExplicit_NoIgnoreQuickFix() { //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, string.Empty) .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 OptionExplicitInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.IsFalse(inspectionResults.ElementAt(0).QuickFixes.Any(q => q is IgnoreOnceQuickFix)); }
public void OptionExplicit_NoIgnoreQuickFix() { IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleModule(string.Empty, ComponentType.ClassModule, out component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new OptionExplicitInspection(state); var inspectionResults = inspection.GetInspectionResults(); Assert.IsFalse(inspectionResults.ElementAt(0).QuickFixes.Any(q => q is IgnoreOnceQuickFix)); }
public void OptionExplicitInspectionTest() { var code = "Sub Foo()\n\nEnd Sub"; var parser = new Parser(_grammar); var node = parser.Parse("CodeInspectionTests", "TestModule", code, false); var projectNode = new ProjectNode("CodeInspectionTests", new[] { node }); var inspection = new OptionExplicitInspection(); var results = inspection.GetInspectionResults(projectNode); Assert.IsTrue(results.Any(result => result.GetType() == typeof(OptionExplicitInspectionResult))); }
public void AlreadySpecified_DoesNotReturnResult() { const string inputCode = @"Option Explicit"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new OptionExplicitInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; Assert.AreEqual(0, inspectionResults.Count()); }
public void AlreadySpecified_DoesNotReturnResult() { const string inputCode = @"Option Explicit"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new OptionExplicitInspection(state); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(0, inspectionResults.Count()); }
public void NotAlreadySpecified_QuickFixWorks() { const string inputCode = @""; const string expectedCode = @"Option Explicit "; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new OptionExplicitInspection(state); var inspectionResults = inspection.GetInspectionResults(); inspectionResults.First().QuickFixes.First().Fix(); Assert.AreEqual(expectedCode, component.CodeModule.Content()); }
public void NotAlreadySpecified_ReturnsMultipleResults() { const string inputCode = @""; var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected) .AddComponent("Class1", ComponentType.ClassModule, inputCode) .AddComponent("Class2", ComponentType.ClassModule, inputCode) .Build(); var vbe = builder.AddProject(project).Build(); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new OptionExplicitInspection(state); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(2, inspectionResults.Count()); }
public void NotAlreadySpecified_QuickFixWorks() { const string inputCode = ""; const string expectedCode = @"Option Explicit "; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new OptionExplicitInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; new OptionExplicitQuickFix(state).Fix(inspectionResults.First()); Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText()); }
public void PartiallySpecified_ReturnsResults() { const string inputCode1 = @""; const string inputCode2 = @"Option Explicit"; var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected) .AddComponent("Class1", ComponentType.ClassModule, inputCode1) .AddComponent("Class2", ComponentType.ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new OptionExplicitInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; Assert.AreEqual(1, inspectionResults.Count()); }
public void AlreadySpecified_DoesNotReturnResult() { const string inputCode = @"Option Explicit"; //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(new Mock <ISinks>().Object)); parser.Parse(new CancellationTokenSource()); if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); } var inspection = new OptionExplicitInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(0, inspectionResults.Count()); }
public void InspectionType() { var inspection = new OptionExplicitInspection(null); Assert.AreEqual(CodeInspectionType.CodeQualityIssues, inspection.InspectionType); }