Пример #1
0
        public void IntegerDataType_ReturnsResult_ParameterInterfaceImplementation()
        {
            const string inputCode1 =
                @"Sub Foo(arg as Integer)
End Sub";

            const string inputCode2 =
                @"Implements IClass1

Sub IClass1_Foo(arg 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();

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IntegerDataTypeInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
Пример #2
0
        public void InspectionName()
        {
            const string inspectionName = "IntegerDataTypeInspection";
            var          inspection     = new IntegerDataTypeInspection(null);

            Assert.AreEqual(inspectionName, inspection.Name);
        }
Пример #3
0
        public void IntegerDataType_ReturnsResult_PropertyGetInterfaceImplementation()
        {
            const string inputCode1 =
                @"Property Get Foo() As Integer
End Property";

            const string inputCode2 =
                @"Implements IClass1

Property Get IClass1_Foo() As Integer
End Property";

            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 IntegerDataTypeInspection(state);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(1, inspectionResults.Count());
        }
Пример #4
0
        public void IntegerDataType_DoesNotReturnResult_LibraryProcedureParameter()
        {
            const string inputCode =
                @"Declare Sub Foo Lib ""lib.dll"" (arg As Integer)";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

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

            Assert.AreEqual(0, inspectionResults.Count());
        }
Пример #5
0
        public void IntegerDataType_ReturnsResult_Parameter()
        {
            const string inputCode =
                @"Sub Foo(arg as Integer)
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

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

            Assert.AreEqual(1, inspectionResults.Count());
        }
        public void IntegerDataType_QuickFixWorks_MultipleParameterInterfaceImplementation()
        {
            const string inputCode1 =
                @"Sub Foo(arg1 As Integer, arg2 as Integer)
End Sub";

            const string inputCode2 =
                @"Implements IClass1

Sub IClass1_Foo(arg1 As Integer, arg2 as Integer)
End Sub";

            const string expectedCode1 =
                @"Sub Foo(arg1 As Long, arg2 as Integer)
End Sub";

            const string expectedCode2 =
                @"Implements IClass1

Sub IClass1_Foo(arg1 As Long, arg2 as Integer)
End Sub";

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

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IntegerDataTypeInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                new ChangeIntegerToLongQuickFix(state).Fix(
                    inspectionResults.First(
                        result =>
                        ((VBAParser.ArgContext)result.Context).unrestrictedIdentifier()
                        .identifier()
                        .untypedIdentifier()
                        .identifierValue()
                        .GetText() == "arg1"));

                var project                 = vbe.Object.VBProjects[0];
                var interfaceComponent      = project.VBComponents[0];
                var implementationComponent = project.VBComponents[1];

                Assert.AreEqual(expectedCode1, state.GetRewriter(interfaceComponent).GetText(), "Wrong code in interface");
                Assert.AreEqual(expectedCode2, state.GetRewriter(implementationComponent).GetText(), "Wrong code in implementation");
            }
        }
Пример #7
0
        public void IntegerDataType_DoesNotReturnResult_LibraryFunctionParameter()
        {
            const string inputCode =
                @"Declare Function Foo Lib ""lib.dll"" (arg As Integer) As String";
            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IntegerDataTypeInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.AreEqual(0, inspectionResults.Count());
            }
        }
Пример #8
0
        public void IntegerDataType_Ignored_DoesNotReturnResult()
        {
            const string inputCode =
                @"'@Ignore IntegerDataType
Sub Foo(arg1 As Integer)
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

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

            Assert.IsFalse(inspectionResults.Any());
        }
Пример #9
0
        public void IntegerDataType_ReturnsResult_PropertyGet()
        {
            const string inputCode =
                @"Property Get Foo() As Integer
End Property";
            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IntegerDataTypeInspection(state);
                var inspectionResults = inspection.GetInspectionResults();

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
Пример #10
0
        public void IntegerDataType_ReturnsResult_Constant()
        {
            const string inputCode =
                @"Sub Foo()
    Const c as Integer = 0
End Sub";
            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IntegerDataTypeInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
        public void IntegerDataType_QuickFixWorks_PropertyGetInterfaceImplementationWithImplementationTypeHint()
        {
            const string inputCode1 =
                @"Property Get Foo() As Integer
End Property";

            const string inputCode2 =
                @"Implements IClass1

Property Get IClass1_Foo%()
End Property";

            const string expectedCode1 =
                @"Property Get Foo() As Long
End Property";

            const string expectedCode2 =
                @"Implements IClass1

Property Get IClass1_Foo&()
End Property";

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

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IntegerDataTypeInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

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

                var project                 = vbe.Object.VBProjects[0];
                var interfaceComponent      = project.VBComponents[0];
                var implementationComponent = project.VBComponents[1];

                Assert.AreEqual(expectedCode1, state.GetRewriter(interfaceComponent).GetText(), "Wrong code in interface");
                Assert.AreEqual(expectedCode2, state.GetRewriter(implementationComponent).GetText(), "Wrong code in implementation");
            }
        }
        public void IntegerDataType_QuickFixWorks_ParameterInterfaceImplementationWithDifferentName()
        {
            const string inputCode1 =
                @"Sub Foo(arg1 As Integer)
End Sub";

            const string inputCode2 =
                @"Implements IClass1

Sub IClass1_Foo(arg2 As Integer)
End Sub";

            const string expectedCode1 =
                @"Sub Foo(arg1 As Long)
End Sub";

            const string expectedCode2 =
                @"Implements IClass1

Sub IClass1_Foo(arg2 As Long)
End Sub";

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

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IntegerDataTypeInspection(state);
                var inspectionResults = inspection.GetInspectionResults();

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

                var project                 = vbe.Object.VBProjects[0];
                var interfaceComponent      = project.VBComponents[0];
                var implementationComponent = project.VBComponents[1];

                Assert.AreEqual(expectedCode1, state.GetRewriter(interfaceComponent).GetText(), "Wrong code in interface");
                Assert.AreEqual(expectedCode2, state.GetRewriter(implementationComponent).GetText(), "Wrong code in implementation");
            }
        }
Пример #13
0
        public void IntegerDataType_QuickFixWorks_PropertyGetWithTypeHint()
        {
            const string inputCode =
                @"Property Get Foo%()
End Property";

            const string expectedCode =
                @"Property Get Foo&()
End Property";

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

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

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

            Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText());
        }
        public void IntegerDataType_QuickFixWorks_Function()
        {
            const string inputCode =
                @"Function Foo() As Integer
End Function";

            const string expectedCode =
                @"Function Foo() As Long
End Function";

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

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IntegerDataTypeInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

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

                Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText());
            }
        }
Пример #15
0
        public void IntegerDataType_QuickFixWorks_UserDefinedTypeUntypedNameMember()
        {
            const string inputCode =
                @"Type T
    i() as Integer
End Type";

            const string expectedCode =
                @"Type T
    i() as Long
End Type";

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

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

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

            Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText());
        }
Пример #16
0
        public void InspectionType()
        {
            var inspection = new IntegerDataTypeInspection(null);

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