Beispiel #1
0
        public void InspectionName()
        {
            const string inspectionName = "ImplicitByRefParameterInspection";
            var          inspection     = new ImplicitByRefParameterInspection(null);

            Assert.AreEqual(inspectionName, inspection.Name);
        }
Beispiel #2
0
        public void ImplicitByRefParameter_DoesNotReturnResult_ByRef()
        {
            const string inputCode =
                @"Sub Foo(ByRef arg1 As Integer)
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 ImplicitByRefParameterInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(0, inspectionResults.Count());
        }
Beispiel #3
0
        public void ImplicitByRefParameter_QuickFixWorks_PassByRef()
        {
            const string inputCode =
                @"Sub Foo(arg1 As Integer)
End Sub";

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

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

            Assert.AreEqual(expectedCode, module.Lines());
        }
        public void ImplicitByRefParameter_ReturnsResult_SomePassedByRefImplicitely()
        {
            const string inputCode =
                @"Sub Foo(ByVal arg1 As Integer, arg2 As Date)
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(new Mock <ISinks>().Object));

            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var inspection        = new ImplicitByRefParameterInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(1, inspectionResults.Count());
        }
        public void ImplicitByRefParameter_Ignored_DoesNotReturnResult()
        {
            const string inputCode =
                @"'@Ignore ImplicitByRefParameter
Sub Foo(arg1 As Integer)
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(new Mock <ISinks>().Object));

            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var inspection        = new ImplicitByRefParameterInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.IsFalse(inspectionResults.Any());
        }
        public void ImplicitByRefParameter_QuickFixWorks_LineContinuation_FirstLine()
        {
            const string inputCode =
                @"Sub Foo( _
        bar _
        As Byte)
    bar = 1
End Sub";

            const string expectedCode =
                @"Sub Foo( _
        ByRef bar _
        As Byte)
    bar = 1
End Sub";

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

            var inspection        = new ImplicitByRefParameterInspection(state);
            var inspectionResults = inspection.GetInspectionResults();

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

            Assert.AreEqual(expectedCode, component.CodeModule.Content());
        }
        public void ImplicitByRefParameter_ReturnsResult_InterfaceImplementation()
        {
            //Input
            const string inputCode1 =
                @"Sub Foo(arg1 As Integer)
End Sub";
            const string inputCode2 =
                @"Implements IClass1

Sub IClass1_Foo(arg1 As Integer)
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("IClass1", ComponentType.ClassModule, inputCode1)
                          .AddComponent("Class1", ComponentType.ClassModule, inputCode2)
                          .Build();
            var vbe = builder.AddProject(project).Build();

            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new ImplicitByRefParameterInspection(state);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(1, inspectionResults.Count());
        }
        public void ImplicitByRefParameterInspectionTest()
        {
            var code        = "Private Sub Foo(bar As Integer)\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 ImplicitByRefParameterInspection();
            var results    = inspection.GetInspectionResults(projectNode);

            Assert.IsTrue(results.Any(result => result.GetType() == typeof(ImplicitByRefParameterInspectionResult)));
        }
        public void ImplicitByRefParameter_DoesNotReturnResult_ParamArray()
        {
            const string inputCode =
                @"Sub Foo(ParamArray arg1 As Integer)
End Sub";

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

            var inspection        = new ImplicitByRefParameterInspection(state);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.IsFalse(inspectionResults.Any());
        }
        public void ImplicitByRefParameter_ReturnsResult_MultipleParams()
        {
            const string inputCode =
                @"Sub Foo(arg1 As Integer, arg2 As Date)
End Sub";

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

            var inspection        = new ImplicitByRefParameterInspection(state);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(2, inspectionResults.Count());
        }
        public void ImplicitByRefParameter_IgnoredQuickFixWorks()
        {
            const string inputCode =
                @"Sub Foo(arg1 As Integer)
End Sub";

            const string expectedCode =
                @"'@Ignore ImplicitByRefParameter
Sub Foo(arg1 As Integer)
End Sub";

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

            var inspection        = new ImplicitByRefParameterInspection(state);
            var inspectionResults = inspection.GetInspectionResults();

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

            Assert.AreEqual(expectedCode, component.CodeModule.Content());
        }
Beispiel #12
0
        public void ImplicitByRefParameter_ReturnsResult_InterfaceImplementation()
        {
            //Input
            const string inputCode1 =
                @"Sub Foo(arg1 As Integer)
End Sub";
            const string inputCode2 =
                @"Implements IClass1

Sub IClass1_Foo(arg1 As Integer)
End Sub";

            //Arrange
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none)
                          .AddComponent("IClass1", vbext_ComponentType.vbext_ct_ClassModule, inputCode1)
                          .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode2)
                          .Build();
            var vbe = builder.AddProject(project).Build();

            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 ImplicitByRefParameterInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(1, inspectionResults.Count());
        }
Beispiel #13
0
        public void InspectionType()
        {
            var inspection = new ImplicitByRefParameterInspection(null);

            Assert.AreEqual(CodeInspectionType.CodeQualityIssues, inspection.InspectionType);
        }