public void ObsoleteLetStatement_DoesNotReturnResult()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
    var2 = var1
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 ObsoleteLetStatementInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(0, inspectionResults.Count());
        }
        public void ObsoleteLetStatement_QuickFixWorks()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
    Let var2 = var1
End Sub";

            const string expectedCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
    var2 = var1
End Sub";

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

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

                new RemoveExplicitLetStatementQuickFix(state).Fix(inspectionResults.First());
                Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText());
            }
        }
コード例 #3
0
        public void InspectionName()
        {
            const string inspectionName = "ObsoleteLetStatementInspection";
            var          inspection     = new ObsoleteLetStatementInspection(null);

            Assert.AreEqual(inspectionName, inspection.Name);
        }
コード例 #4
0
        public void ObsoleteLetStatement_DoesNotReturnResult()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
    var2 = var1
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 ObsoleteLetStatementInspection(state);
            var inspector  = new Inspector(settings.Object, new IInspection[] { inspection });

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

            Assert.AreEqual(0, inspectionResults.Count());
        }
コード例 #5
0
        public void ObsoleteLetStatement_IgnoreQuickFixWorks()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
    Let var2 = var1
End Sub";

            const string expectedCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
'@Ignore ObsoleteLetStatement
    Let var2 = var1
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 ObsoleteLetStatementInspection(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());
        }
コード例 #6
0
        public void ObsoleteLetStatement_DoesNotReturnResult()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
    var2 = var1
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

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

            Assert.AreEqual(0, inspectionResults.Count());
        }
        public void ObsoleteLetStatement_QuickFixWorks()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
    Let var2 = var1
End Sub";

            const string expectedCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
    var2 = var1
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 ObsoleteLetStatementInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

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

            Assert.AreEqual(expectedCode, module.Lines());
        }
コード例 #8
0
        public void ObsoleteLetStatement_ReturnsResult_MultipleLets()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
    Let var2 = var1
    Let var1 = var2
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 ObsoleteLetStatementInspection(parser.State);
            var inspector  = new Inspector(settings.Object, new IInspection[] { inspection });

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

            Assert.AreEqual(2, inspectionResults.Count());
        }
コード例 #9
0
        public void ObsoleteLetStatement_IgnoreQuickFixWorks()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
    Let var2 = var1
End Sub";

            const string expectedCode =
                @"Public Sub Foo()
    Dim var1 As Integer
    Dim var2 As Integer
    
'@Ignore ObsoleteLetStatement
    Let var2 = var1
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 ObsoleteLetStatementInspection(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());
        }
コード例 #10
0
        public void InspectionType()
        {
            var inspection = new ObsoleteLetStatementInspection(null);

            Assert.AreEqual(CodeInspectionType.LanguageOpportunities, inspection.InspectionType);
        }
コード例 #11
0
        public void InspectionName()
        {
            var inspection = new ObsoleteLetStatementInspection(null);

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