Ejemplo n.º 1
0
        public void NotEmptyStringLiteral_DoesNotReturnResult()
        {
            const string inputCode =
                @"Public Sub Foo(ByRef arg1 As String)
    arg1 = ""test""
End Sub";

            //Arrange
            var settings = new Mock <IGeneralConfigService>();
            var config   = GetTestConfig();

            settings.Setup(x => x.LoadConfiguration()).Returns(config);

            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 EmptyStringLiteralInspection(parser.State);
            var inspector  = new Inspector(settings.Object, new IInspection[] { inspection });

            var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;

            Assert.AreEqual(0, inspectionResults.Count());
        }
Ejemplo n.º 2
0
        public void InspectionName()
        {
            const string inspectionName = "EmptyStringLiteralInspection";
            var          inspection     = new EmptyStringLiteralInspection(null);

            Assert.AreEqual(inspectionName, inspection.Name);
        }
        public void EmptyStringLiteral_QuickFixWorks()
        {
            const string inputCode =
                @"Public Sub Foo(ByRef arg1 As String)
    arg1 = """"
End Sub";

            const string expectedCode =
                @"Public Sub Foo(ByRef arg1 As String)
    arg1 = vbNullString
End Sub";

            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new EmptyStringLiteralInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                new ReplaceEmptyStringLiteralStatementQuickFix(state).Fix(inspectionResults.First());

                Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText());
            }
        }
        public void ProviderCallsNotifierOnFailureToRewrite()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim str As String
    str = """"
End Sub";

            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component);

            var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object);
            using (state)
            {
                var inspection        = new EmptyStringLiteralInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;
                var inspectionResult  = inspectionResults.First();

                var failureNotifierMock = new Mock <IQuickFixFailureNotifier>();
                var quickFixProvider    = new QuickFixProvider(rewritingManager, failureNotifierMock.Object, new IQuickFix[] { new ReplaceEmptyStringLiteralStatementQuickFix() });
                var quickFix            = quickFixProvider.QuickFixes(inspectionResult).First();

                //Make rewrite fail.
                component.CodeModule.InsertLines(1, "'afejfaofef");

                quickFixProvider.Fix(quickFix, inspectionResult);

                failureNotifierMock.Verify(m => m.NotifyQuickFixExecutionFailure(RewriteSessionState.StaleParseTree));
            }
        }
        public void EmptyStringLiteral_IgnoreQuickFixWorks()
        {
            const string inputCode =
                @"Public Sub Foo(ByRef arg1 As String)
    arg1 = """"
End Sub";

            const string expectedCode =
                @"Public Sub Foo(ByRef arg1 As String)
'@Ignore EmptyStringLiteral
    arg1 = """"
End Sub";

            var settings = new Mock <IGeneralConfigService>();
            var config   = GetTestConfig();

            settings.Setup(x => x.LoadConfiguration()).Returns(config);

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var inspection = new EmptyStringLiteralInspection(state);
            var inspector  = new Inspector(settings.Object, new IInspection[] { inspection });

            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            inspectionResults.First().QuickFixes.Single(s => s is IgnoreOnceQuickFix).Fix();

            Assert.AreEqual(expectedCode, component.CodeModule.Content());
        }
        public void EmptyStringLiteral_ReturnsResult_PassToProcedure()
        {
            const string inputCode =
                @"Public Sub Bar()
    Foo """"
End Sub

Public Sub Foo(ByRef arg1 As String)
End Sub";

            var settings = new Mock <IGeneralConfigService>();
            var config   = GetTestConfig();

            settings.Setup(x => x.LoadConfiguration()).Returns(config);

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var inspection = new EmptyStringLiteralInspection(state);
            var inspector  = new Inspector(settings.Object, new IInspection[] { inspection });

            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(1, inspectionResults.Count());
        }
Ejemplo n.º 7
0
        public void NotEmptyStringLiteral_DoesNotReturnResult()
        {
            const string inputCode =
                @"Public Sub Foo(ByRef arg1 As String)
    arg1 = ""test""
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 EmptyStringLiteralInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(0, inspectionResults.Count());
        }
Ejemplo n.º 8
0
        public void NotEmptyStringLiteral_DoesNotReturnResult()
        {
            const string inputCode =
                @"Public Sub Foo(ByRef arg1 As String)
    arg1 = ""test""
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new EmptyStringLiteralInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(0, inspectionResults.Count());
        }
        public void ObsoleteCommentSyntax_DoesNotReturnResult_OtherParseInspectionFires()
        {
            const string inputCode = @"
Sub foo()
    Dim i As String
    i = """"
End Sub";
            var          vbe       = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var          state     = MockParser.CreateAndParse(vbe.Object);

            var inspection = new ObsoleteCommentSyntaxInspection(state);
            var emptyStringLiteralInspection = new EmptyStringLiteralInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection, emptyStringLiteralInspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(0, inspectionResults.Count(r => r.Inspection is ObsoleteCommentSyntaxInspection));
        }
Ejemplo n.º 10
0
        public void EmptyStringLiteral_IgnoreQuickFixWorks()
        {
            const string inputCode =
                @"Public Sub Foo(ByRef arg1 As String)
    arg1 = """"
End Sub";

            const string expectedCode =
                @"Public Sub Foo(ByRef arg1 As String)
'@Ignore EmptyStringLiteral
    arg1 = """"
End Sub";

            //Arrange
            var settings = new Mock <IGeneralConfigService>();
            var config   = GetTestConfig();

            settings.Setup(x => x.LoadConfiguration()).Returns(config);

            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 EmptyStringLiteralInspection(parser.State);
            var inspector  = new Inspector(settings.Object, new IInspection[] { inspection });

            var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;

            inspectionResults.First().QuickFixes.Single(s => s is IgnoreOnceQuickFix).Fix();

            Assert.AreEqual(expectedCode, module.Lines());
        }
Ejemplo n.º 11
0
        public void ProviderKnowsAboutInspection()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim str As String
    str = """"
End Sub";

            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new EmptyStringLiteralInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            var quickFixProvider = new QuickFixProvider(state, new IQuickFix[] { new ReplaceEmptyStringLiteralStatementQuickFix(state) });

            Assert.AreEqual(1, quickFixProvider.QuickFixes(inspectionResults.First()).Count());
        }
Ejemplo n.º 12
0
        public void EmptyStringLiteral_ReturnsResult_PassToProcedure()
        {
            const string inputCode =
                @"Public Sub Bar()
    Foo """"
End Sub

Public Sub Foo(ByRef arg1 As String)
End Sub";
            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new EmptyStringLiteralInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
Ejemplo n.º 13
0
        public void EmptyStringLiteral_QuickFixWorks()
        {
            const string inputCode =
                @"Public Sub Foo(ByRef arg1 As String)
    arg1 = """"
End Sub";

            const string expectedCode =
                @"Public Sub Foo(ByRef arg1 As String)
    arg1 = vbNullString
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 EmptyStringLiteralInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            inspectionResults.First().QuickFixes.First().Fix();

            Assert.AreEqual(expectedCode, module.Lines());
        }
Ejemplo n.º 14
0
        public void InspectionType()
        {
            var inspection = new EmptyStringLiteralInspection(null);

            Assert.AreEqual(CodeInspectionType.LanguageOpportunities, inspection.InspectionType);
        }
Ejemplo n.º 15
0
        public void InspectionName()
        {
            var inspection = new EmptyStringLiteralInspection(null);

            Assert.AreEqual(nameof(EmptyStringLiteralInspection), inspection.Name);
        }