Esempio n. 1
0
        public void ObsoleteTypeHint_QuickFixWorks_Variable_StringTypeHint()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim buzz$
End Sub";

            const string expectedCode =
                @"Public Sub Foo()
    Dim buzz As String
End Sub";

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

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

            foreach (var inspectionResult in inspectionResults)
            {
                inspectionResult.QuickFixes.First().Fix();
            }

            Assert.AreEqual(expectedCode, component.CodeModule.Content());
        }
Esempio n. 2
0
        public void InspectionName()
        {
            const string inspectionName = "ObsoleteTypeHintInspection";
            var          inspection     = new ObsoleteTypeHintInspection(null);

            Assert.AreEqual(inspectionName, inspection.Name);
        }
Esempio n. 3
0
        public void ObsoleteTypeHint_QuickFixWorks_Field_StringTypeHint()
        {
            const string inputCode =
                @"Public Foo$";

            const string expectedCode =
                @"Public Foo As String";

            //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(new Mock <ISinks>().Object));

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

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

            foreach (var inspectionResult in inspectionResults)
            {
                inspectionResult.QuickFixes.First().Fix();
            }

            Assert.AreEqual(expectedCode, module.Lines());
        }
Esempio n. 4
0
        public void ObsoleteCallStatement_StringValueDoesNotReturnsResult()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim bar As String
    bar = ""Public baz$""
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 ObsoleteTypeHintInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(0, inspectionResults.Count());
        }
Esempio n. 5
0
        public void ObsoleteTypeHint_FieldWithDoubleTypeHintReturnsResult()
        {
            const string inputCode =
                @"Public Foo#";

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

            Assert.AreEqual(1, inspectionResults.Count());
        }
Esempio n. 6
0
        public void ObsoleteTypeHint_QuickFixWorks_PropertyGet_StringTypeHint()
        {
            const string inputCode =
                @"Public Property Get Foo$(ByVal fizz As Integer)
    Foo = ""test""
End Property";

            const string expectedCode =
                @"Public Property Get Foo(ByVal fizz As Integer) As String
    Foo = ""test""
End Property";

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

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

            foreach (var inspectionResult in inspectionResults)
            {
                inspectionResult.QuickFixes.First().Fix();
            }

            Assert.AreEqual(expectedCode, component.CodeModule.Content());
        }
Esempio n. 7
0
        public void ObsoleteTypeHint_QuickFixWorks_PropertyGet_StringTypeHint()
        {
            const string inputCode =
                @"Public Property Get Foo$(ByVal fizz As Integer)
    Foo = ""test""
End Property";

            const string expectedCode =
                @"Public Property Get Foo(ByVal fizz As Integer) As String
    Foo = ""test""
End Property";

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

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

                var fix = new RemoveTypeHintsQuickFix(state);
                foreach (var result in inspectionResults)
                {
                    fix.Fix(result);
                }

                Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText());
            }
        }
Esempio n. 8
0
        public void ObsoleteTypeHint_IgnoreQuickFixWorks()
        {
            const string inputCode =
                @"Public Function Foo$(ByVal fizz As Integer)
    Foo = ""test""
End Function";

            const string expectedCode =
                @"'@Ignore ObsoleteTypeHint
Public Function Foo$(ByVal fizz As Integer)
    Foo = ""test""
End Function";

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

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

                var fix = new IgnoreOnceQuickFix(state, new[] { inspection });
                foreach (var result in inspectionResults)
                {
                    fix.Fix(result);
                }

                Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText());
            }
        }
Esempio n. 9
0
        public void ObsoleteTypeHint_IgnoreQuickFixWorks()
        {
            const string inputCode =
                @"Public Function Foo$(ByVal fizz As Integer)
    Foo = ""test""
End Function";

            const string expectedCode =
                @"'@Ignore ObsoleteTypeHint
Public Function Foo$(ByVal fizz As Integer)
    Foo = ""test""
End Function";

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

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

            foreach (var inspectionResult in inspectionResults)
            {
                inspectionResult.QuickFixes.Single(s => s is IgnoreOnceQuickFix).Fix();
            }

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

            const string expectedCode =
                @"Public Sub Foo()
    Const buzz As String = """"
End Sub";

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

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

            var fix = new RemoveTypeHintsQuickFix(state);

            foreach (var result in inspectionResults)
            {
                fix.Fix(result);
            }

            Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText());
        }
Esempio n. 11
0
        public void ObsoleteTypeHint_Ignored_DoesNotReturnResult()
        {
            const string inputCode =
                @"'@Ignore ObsoleteTypeHint
Public Function Foo$(ByVal bar As Boolean)
End Function";

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

            Assert.IsFalse(inspectionResults.Any());
        }
Esempio n. 12
0
        public void ObsoleteCallStatement_VariableReturnsResult()
        {
            const string inputCode =
                @"Public Function Foo() As Boolean
    Dim buzz$
    Foo = True
End Function";

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

            Assert.AreEqual(1, inspectionResults.Count());
        }
Esempio n. 13
0
        public void ObsoleteTypeHint_FieldWithStringTypeHintReturnsResult()
        {
            const string inputCode =
                @"Public Foo$";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

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

            Assert.AreEqual(1, inspectionResults.Count());
        }
Esempio n. 14
0
        public void ObsoleteTypeHint_ParameterReturnsResult()
        {
            const string inputCode =
                @"Public Function Foo(ByVal bar$) As Boolean
End Function";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

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

            Assert.AreEqual(1, inspectionResults.Count());
        }
Esempio n. 15
0
        public void ObsoleteTypeHint_Ignored_DoesNotReturnResult()
        {
            const string inputCode =
                @"'@Ignore ObsoleteTypeHint
Public Function Foo$(ByVal bar As Boolean)
End Function";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

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

            Assert.IsFalse(inspectionResults.Any());
        }
        public void ObsoleteCallStatement_QuickFixWorks_FunctionReferencesAreUpdated_ParentIsNotChanged_StringTypeHint()
        {
            const string inputCode =
                @"Public Function Foo(ByVal bar as Boolean) As String
    Foo$ = ""test""
End Function

Public Sub Buzz()
    Dim bat As String
    bat$ = Foo$()
End Sub";

            const string expectedCode =
                @"Public Function Foo(ByVal bar as Boolean) As String
    Foo = ""test""
End Function

Public Sub Buzz()
    Dim bat As String
    bat = Foo()
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 ObsoleteTypeHintInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            foreach (var inspectionResult in inspectionResults)
            {
                inspectionResult.QuickFixes.First().Fix();
            }

            Assert.AreEqual(expectedCode, module.Lines());
        }
Esempio n. 17
0
        public void ObsoleteTypeHint_FieldsReturnMultipleResults()
        {
            const string inputCode =
                @"Public Foo$
Public Bar$";

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

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

            Assert.AreEqual(2, inspectionResults.Count());
        }
Esempio n. 18
0
        public void ObsoleteTypeHint_PropertyGetReturnsResult()
        {
            const string inputCode =
                @"Public Property Get Foo$(ByVal bar As Boolean)
End Property";

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

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

            Assert.AreEqual(1, inspectionResults.Count());
        }
Esempio n. 19
0
        public void ObsoleteTypeHint_FunctionReturnsResult()
        {
            const string inputCode =
                @"Public Function Foo$(ByVal bar As Boolean)
End Function";
            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

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

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
Esempio n. 20
0
        public void ObsoleteTypeHint_StringValueDoesNotReturnsResult()
        {
            const string inputCode =
                @"Public Sub Foo()
    Dim bar As String
    bar = ""Public baz$""
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

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

            Assert.AreEqual(0, inspectionResults.Count());
        }
Esempio n. 21
0
        public void ObsoleteTypeHint_VariableReturnsResult()
        {
            const string inputCode =
                @"Public Function Foo() As Boolean
    Dim buzz$
    Foo = True
End Function";

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

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

            Assert.AreEqual(1, inspectionResults.Count());
        }
Esempio n. 22
0
        public void ObsoleteTypeHint_ConstantReturnsResult()
        {
            const string inputCode =
                @"Public Function Foo() As Boolean
    Const buzz$ = 0
    Foo = True
End Function";
            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

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

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
        public void ObsoleteCallStatement_QuickFixWorks_PropertyGet_StringTypeHint()
        {
            const string inputCode =
                @"Public Property Get Foo$(ByVal fizz As Integer)
    Foo = ""test""
End Property";

            const string expectedCode =
                @"Public Property Get Foo(ByVal fizz As Integer) As String
    Foo = ""test""
End Property";

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

            foreach (var inspectionResult in inspectionResults)
            {
                inspectionResult.QuickFixes.First().Fix();
            }

            Assert.AreEqual(expectedCode, module.Lines());
        }
Esempio n. 24
0
        public void ObsoleteTypeHint_QuickFixWorks_Field_DecimalTypeHint()
        {
            const string inputCode =
                @"Public Foo@";

            const string expectedCode =
                @"Public Foo As Decimal";

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

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

                var fix = new RemoveTypeHintsQuickFix(state);
                foreach (var result in inspectionResults)
                {
                    fix.Fix(result);
                }

                Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText());
            }
        }
Esempio n. 25
0
        public void InspectionType()
        {
            var inspection = new ObsoleteTypeHintInspection(null);

            Assert.AreEqual(CodeInspectionType.LanguageOpportunities, inspection.InspectionType);
        }
        public void InspectionName()
        {
            var inspection = new ObsoleteTypeHintInspection(null);

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