public void InspectionName() { const string inspectionName = "BooleanAssignedInIfElseInspection"; var inspection = new BooleanAssignedInIfElseInspection(null); Assert.AreEqual(inspectionName, inspection.Name); }
public void InvertedCondition() { const string inputCode = @"Sub Foo() Dim d As Boolean If True Then d = False Else d = True EndIf End Sub"; const string expectedCode = @"Sub Foo() Dim d As Boolean d = Not (True) End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new BooleanAssignedInIfElseInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; new ReplaceIfElseWithConditionalStatementQuickFix(state).Fix(inspectionResults.First()); Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText()); } }
public void MultipleResults() { const string inputcode = @"Sub Foo() Dim d As Boolean If True Then d = True Else d = False EndIf If True Then d = False Else d = True EndIf End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputcode, out _); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new BooleanAssignedInIfElseInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var results = inspector.FindIssuesAsync(state, CancellationToken.None).Result; Assert.AreEqual(2, results.Count()); } }
public void ConditionalDoesNotContainElseBlock() { const string inputcode = @"Sub Foo() Dim d If True Then d = True EndIf End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputcode, out _); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new BooleanAssignedInIfElseInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var results = inspector.FindIssuesAsync(state, CancellationToken.None).Result; Assert.IsFalse(results.Any()); } }
public void BooleanAssignedInIfElseInspection_IgnoreQuickFixWorks() { const string inputCode = @"Sub Foo() Dim d As Boolean If True Then d = True Else d = False EndIf End Sub"; const string expectedCode = @"Sub Foo() Dim d As Boolean '@Ignore BooleanAssignedInIfElse If True Then d = True Else d = False EndIf End Sub"; var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected) .AddComponent("MyClass", ComponentType.ClassModule, inputCode) .Build(); var component = project.Object.VBComponents[0]; var vbe = builder.AddProject(project).Build(); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new BooleanAssignedInIfElseInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; new IgnoreOnceQuickFix(state, new[] { inspection }).Fix(inspectionResults.First()); Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText()); } }
public void AssignsTheSameValue() // worthy of an inspection in its own right { const string inputcode = @"Sub Foo() Dim d If True Then d = True Else d = True EndIf End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputcode, out _); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new BooleanAssignedInIfElseInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var results = inspector.FindIssuesAsync(state, CancellationToken.None).Result; Assert.IsFalse(results.Any()); } }