Beispiel #1
0
        public void ObsoleteTypeHint_QuickFixWorks_Field_DecimalTypeHint()
        {
            const string inputCode =
                @"Public Foo@";

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

            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());
        }
Beispiel #2
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";

            //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());
        }
Beispiel #3
0
        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());
        }
        public void ObsoleteTypeHint_QuickFixWorks_Field_SingleTypeHint()
        {
            const string inputCode =
                @"Public Foo!";

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

            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());
        }