Ejemplo n.º 1
0
        public void GivenLeadingWhitespace_YieldsSameCodeString()
        {
            var original = "    MsgBox|".ToCodeString();

            var sut    = InitializeSut(original, original, out var module, out _);
            var actual = new TestCodeString(sut.Prettify(module.Object, original));

            Assert.AreEqual(original, actual);
        }
Ejemplo n.º 2
0
        public void GivenMultilineLogicalLine_TracksCaret()
        {
            var original = @"
MsgBox ""test"" & vbNewLine & _
       ""|"")".ToCodeString();

            var sut    = InitializeSut(original, original, out var module, out _);
            var actual = new TestCodeString(sut.Prettify(module.Object, original));

            Assert.AreEqual(original, actual);
        }
Ejemplo n.º 3
0
        public void GivenExtraWhitespace_PrettifiedCaretStillAtSameToken()
        {
            var original   = "MsgBox      (\"test|\")".ToCodeString();
            var prettified = "MsgBox (\"test\")".ToCodeString();
            var expected   = "MsgBox (\"test|\")".ToCodeString();

            var sut    = InitializeSut(original, prettified, out var module, out _);
            var actual = new TestCodeString(sut.Prettify(module.Object, original));

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public void GivenPrintToken_PrettifiedCaretIsAtLastCharacter()
        {
            var original   = "debug.? dosomething|".ToCodeString();
            var prettified = "Debug.Print DoSomething".ToCodeString();
            var expected   = "Debug.Print DoSomething|".ToCodeString();

            var sut    = InitializeSut(original, prettified, out var module, out _);
            var actual = new TestCodeString(sut.Prettify(module.Object, original));

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public void GivenTrailingWhitespace_IsTrimmedAndPrettifiedCaretIsAtLastCharacter()
        {
            var original   = "MsgBox |".ToCodeString();
            var prettified = "MsgBox".ToCodeString();
            var expected   = "MsgBox|".ToCodeString();

            var sut    = InitializeSut(original, prettified, out var module, out _);
            var actual = new TestCodeString(sut.Prettify(module.Object, original));

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public void GivenPartialMultilineInstruction_TracksCaret()
        {
            var original = @"
ExecuteStoredProcedure (""AddAppointmentCountForAClinic"", False,dbconfig.SQLConString, _
                | thisClinic.ClinicID ,".ToCodeString();

            var sut    = InitializeSut(original, original, out var module, out _);
            var actual = new TestCodeString(sut.Prettify(module.Object, original));

            Assert.AreEqual(original, actual);
        }
Ejemplo n.º 7
0
        private static TestCodeString Run(TestCodeString original, char input, bool isCtrlDown = false, bool isDeleteKey = false)
        {
            var sut  = InitializeSut(original, out var module, out var settings);
            var args = new AutoCompleteEventArgs(module.Object, input, isCtrlDown, isDeleteKey);

            if (sut.Handle(args, settings, out var result))
            {
                return(new TestCodeString(result));
            }

            return(null);
        }
Ejemplo n.º 8
0
        private bool Run(SelfClosingPair pair, CodeString original, Keys input, out TestCodeString testResult)
        {
            var sut = new SelfClosingPairCompletionService();

            if (sut.Execute(pair, original, input, out var result))
            {
                testResult = new TestCodeString(result);
                return(true);
            }

            testResult = null;
            return(false);
        }
Ejemplo n.º 9
0
        private static ICodePaneHandler InitializeSut(TestCodeString original, TestCodeString prettified, out Mock <ICodeModule> module, out Mock <ICodePane> pane)
        {
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("Module1", ComponentType.StandardModule, "");
            var vbe = builder.AddProject(project.Build()).Build();

            module = new Mock <ICodeModule>();
            pane   = new Mock <ICodePane>();
            pane.SetupProperty(m => m.Selection);
            module.Setup(m => m.DeleteLines(original.SnippetPosition.StartLine, original.SnippetPosition.LineCount));
            module.Setup(m => m.InsertLines(original.SnippetPosition.StartLine, original.Code));
            module.Setup(m => m.CodePane).Returns(pane.Object);
            module.Setup(m => m.GetLines(original.SnippetPosition)).Returns(prettified.Code);

            var sut = new CodePaneHandler(new ProjectsRepository(vbe.Object));

            return(sut);
        }
Ejemplo n.º 10
0
        private static SmartConcatenationHandler InitializeSut(TestCodeString original, TestCodeString prettified, out Mock <ICodeModule> module, out Mock <ICodePane> pane, out AutoCompleteSettings settings)
        {
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("Module1", ComponentType.StandardModule, "");
            var vbe = builder.AddProject(project.Build()).Build();

            module = new Mock <ICodeModule>();
            pane   = new Mock <ICodePane>();
            pane.SetupProperty(m => m.Selection);
            var paneSelection = new Selection(original.SnippetPosition.StartLine + original.CaretPosition.StartLine, original.CaretPosition.StartColumn + 1);

            pane.Object.Selection = paneSelection;

            module.Setup(m => m.DeleteLines(original.SnippetPosition.StartLine, original.SnippetPosition.LineCount));
            module.Setup(m => m.InsertLines(original.SnippetPosition.StartLine, original.Code));
            module.Setup(m => m.CodePane).Returns(pane.Object);
            for (var i = 0; i < original.SnippetPosition.LineCount; i++)
            {
                var index = i;
                module.Setup(m => m.GetLines(index + 1, 1)).Returns(original.Lines[index]);
            }
            module.Setup(m => m.GetLines(original.SnippetPosition)).Returns(prettified.Code);
            module.Setup(m => m.GetLines(paneSelection.StartLine, paneSelection.LineCount)).Returns(prettified.CaretLine);

            settings = new AutoCompleteSettings {
                IsEnabled = true
            };
            settings.SmartConcat.IsEnabled = true;
            settings.SmartConcat.ConcatVbNewLineModifier = ModifierKeySetting.CtrlKey;
            settings.SmartConcat.ConcatMaxLines          = AutoCompleteSettings.ConcatMaxLinesMaxValue;

            var handler = new CodePaneSourceCodeHandler(new ProjectsRepository(vbe.Object));
            var sut     = new SmartConcatenationHandler(handler);

            return(sut);
        }
 private static ExtractInterfaceModel RetrieveModel(TestCodeString codeString)
 => RetrieveModel(codeString.Code, codeString.CaretPosition.ToOneBased());
Ejemplo n.º 12
0
        public void SnippetPositionIsL1C1IfUnspecified()
        {
            var sut = new TestCodeString(TestCodeString.PseudoCaret.ToString(), new Selection());

            Assert.AreEqual(Selection.Home, sut.SnippetPosition);
        }
 public IDictionary <string, string> RefactoredCode(
     Func <EncapsulateFieldModel, EncapsulateFieldModel> presenterAction,
     TestCodeString codeString,
     params (string, string, ComponentType)[] otherModules)
Ejemplo n.º 14
0
 private static SmartConcatenationHandler InitializeSut(TestCodeString code, out Mock <ICodeModule> module, out AutoCompleteSettings settings)
 {
     return(InitializeSut(code, code, out module, out _, out settings));
 }