void CheckOutput(TextEditorExtensionTestCase testCase, string output, CSharpTextEditorIndentation engine = null)
        {
            TextEditor data = testCase.Document.Editor;

            if (engine == null)
            {
                engine = new CSharpTextEditorIndentation();
            }
            engine.FixLineStart(data, CreateTracker(data), data.CaretLine);
            int idx = output.IndexOf('$');

            if (idx > 0)
            {
                output = output.Substring(0, idx) + output.Substring(idx + 1);
            }
            if (output != data.Text)
            {
                Console.WriteLine("expected:");
                Console.WriteLine(output.Replace("\t", "\\t").Replace(" ", "."));
                Console.WriteLine("was:");
                Console.WriteLine(data.Text.Replace("\t", "\\t").Replace(" ", "."));
            }
            Assert.AreEqual(output, data.Text);
            if (idx >= 0)
            {
                Assert.AreEqual(idx, data.CaretOffset, "Caret offset mismatch.");
            }
        }
Exemple #2
0
        public async Task TestBug58764()
        {
            DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket = true;
            var content = new TestViewContent();
            await content.Initialize(new FileDescriptor ("foo.xml", null, null));

            using (var testCase = await TextEditorExtensionTestCase.Create(content, null, false)) {
                var document = testCase.Document;
                var editor   = content.Editor;
                editor.MimeType = "text/xml";
                const string originalText = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ContentPage xmlns=""http://xamarin.com/schemas/2014/forms""
             xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
             x:Class=""XamlSamples.HelloXamlPage"">
             <Grid HeightRequest=
</ContentPage>";
                editor.Text = originalText;
                var offset = editor.Text.IndexOf("HeightRequest=", StringComparison.Ordinal) + "HeightRequest=".Length;
                editor.GetContent <ITextEditorImpl> ().CaretOffset = offset;
                //Reason why we use GetNativeWidget, and navigate to ExtensibleTextEditor child
                //and execute KeyPress on it instead something more abstract is...
                //EditSession key processing is done inside ExtensibleTextEditor.
                var extensibleEditor = editor.GetContent <SourceEditorView> ().TextEditor;
                extensibleEditor.OnIMProcessedKeyPressEvent((Gdk.Key) '"', '"', Gdk.ModifierType.None);
                extensibleEditor.OnIMProcessedKeyPressEvent(Gdk.Key.BackSpace, '\0', Gdk.ModifierType.None);
                extensibleEditor.OnIMProcessedKeyPressEvent((Gdk.Key) '"', '"', Gdk.ModifierType.None);
                Assert.AreEqual(originalText.Insert(offset, "\"\""), editor.Text);
            }
        }
Exemple #3
0
        public async Task Refactor_RenameClassNameAndFileName_ShouldNotPromptToReload()
        {
            FilePath directory = UnitTests.Util.CreateTmpDir("FileRenameShouldNotPromptToReload");
            FilePath fileName  = directory.Combine("test.cs");

            File.WriteAllText(fileName, "class Test {}");

            var window  = new TestWorkbenchWindow();
            var content = new TestViewContentWithDocumentReloadPresenter();

            window.ViewContent = content;
            var doc = new Document(window);

            using (var testCase = new TextEditorExtensionTestCase(doc, content, window, null, false)) {
                content.Document = doc;
                await content.Load(fileName);

                bool reloadWarningDisplayed = false;
                content.OnShowFileChangeWarning = multiple => {
                    reloadWarningDisplayed = true;
                };
                doc.Editor.Text = "class rename {}";
                doc.IsDirty     = true;             // Refactor leaves file unsaved in text editor.
                FilePath newFileName = fileName.ChangeName("renamed");
                FileService.RenameFile(fileName, newFileName);
                // Simulate DefaultWorkbench which updates the view content name when the FileService
                // fires the rename event.
                content.ContentName = newFileName;
                FileService.NotifyFileChanged(newFileName);

                Assert.IsFalse(reloadWarningDisplayed);
            }
        }
        static string ResolveExpression(TextEditorExtensionTestCase testCase, int offset)
        {
            var doc      = testCase.Document;
            var editor   = doc.Editor;
            var loc      = editor.OffsetToLocation(offset);
            var resolver = doc.GetContent <IDebuggerExpressionResolver> ();

            return(resolver.ResolveExpressionAsync(editor, doc, offset, default(System.Threading.CancellationToken)).Result.Text);
        }
Exemple #5
0
        CSharpTextPasteHandler CreateTextPasteIndentEngine(TextEditorExtensionTestCase testCase, OptionSet optionSet)
        {
            var indent = testCase.GetContent <CSharpTextEditorIndentation> ();

            return(new CSharpTextPasteHandler(indent, optionSet)
            {
                InUnitTestMode = true
            });
        }
        public async Task TestProjectionCompletion()
        {
            var editor  = TextEditorFactory.CreateNewEditor();
            var options = new CustomEditorOptions(editor.Options);

            options.EditorTheme = "Tango";
            editor.Options      = options;
            editor.Text         = "12345678901234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var content    = new TestViewContent();
            await content.Initialize(new FileDescriptor ("Foo.cs", null, null));

            using (var testCase = await TextEditorExtensionTestCase.Create(content, null, false)) {
                var originalContext = testCase.Document.DocumentContext;
                var projectedEditor = projection.CreateProjectedEditor(originalContext);
                TestCompletionExtension orignalExtension;
                editor.SetExtensionChain(originalContext, new [] { orignalExtension = new TestCompletionExtension(editor)
                                                                   {
                                                                       CompletionWidget = new EmptyCompletionWidget(editor)
                                                                   } });
                TestCompletionExtension projectedExtension;
                projectedEditor.SetExtensionChain(originalContext, new [] { projectedExtension = new TestCompletionExtension(editor)
                                                                            {
                                                                                CompletionWidget = new EmptyCompletionWidget(projectedEditor)
                                                                            } });

                editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None);
                editor.CaretOffset = 1;

                var service = new CommandManager();
                service.LoadCommands("/MonoDevelop/Ide/Commands");
                service.DispatchCommand(TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter);
                Assert.IsFalse(orignalExtension.CompletionRun);
                Assert.IsTrue(projectedExtension.CompletionRun);

                editor.CaretOffset = 15;
                CompletionWindowManager.HideWindow();
                service.DispatchCommand(TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter);
                Assert.IsTrue(orignalExtension.CompletionRun);
            }
        }
        protected async Task <T> GatherDiagnostics <T> (string input, Func <Ide.Gui.Document, TaskCompletionSource <T>, Task> callback)
        {
            TextEditorExtensionTestCase testCase = null;

            try {
                var tuple = await GatherDiagnosticsNoDispose(input, callback);

                testCase = tuple.Item2;

                return(tuple.Item1);
            } finally {
                testCase?.Dispose();
            }
        }
Exemple #8
0
        public async Task TestVSTS615849()
        {
            DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket = true;

            var content = new TestViewContent();
            await content.Initialize(new FileDescriptor ("foo.xml", null, null));

            using (var testCase = await TextEditorExtensionTestCase.Create(content, null, false)) {
                var document = testCase.Document;
                var editor   = content.Editor;
                editor.MimeType = "text/xml";
                const string originalText = @"";
                editor.Text = originalText;

                var extensibleEditor = editor.GetContent <SourceEditorView> ().TextEditor;
                extensibleEditor.OnIMProcessedKeyPressEvent((Gdk.Key) '"', '"', Gdk.ModifierType.None);
                extensibleEditor.OnIMProcessedKeyPressEvent(Gdk.Key.Right, '\0', Gdk.ModifierType.None);
                extensibleEditor.OnIMProcessedKeyPressEvent(Gdk.Key.BackSpace, '\0', Gdk.ModifierType.None);
                Assert.AreEqual("\"", editor.Text);
            }
        }
Exemple #9
0
        public void TestProjectionUpdate()
        {
            var editor = TextEditorFactory.CreateNewEditor();

            editor.Text = "1234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var tww        = new TestWorkbenchWindow();
            var content    = new TestViewContent();

            tww.ViewContent = content;

            var originalContext = new Document(tww);

            using (var testCase = new TextEditorExtensionTestCase(originalContext, content, tww, null, false)) {
                var projectedEditor = projection.CreateProjectedEditor(originalContext);
                editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.All);
                editor.InsertText(1, "foo");
                Assert.AreEqual("__1foo2__34__56__78__90", projectedEditor.Text);

                Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(0).ProjectedOffset);
                Assert.AreEqual(2 + "foo".Length, projection.ProjectedSegments.ElementAt(0).Length);
                for (int i = 1; i < 5; i++)
                {
                    Assert.AreEqual(2 + i * 4 + "foo".Length, projection.ProjectedSegments.ElementAt(i).ProjectedOffset);
                    Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(i).Length);
                }
            }
        }
Exemple #10
0
            public static async Task <TestCase> Create(string text, bool tabsToSpaces = false)
            {
                var test   = new TestCase();
                var sb     = new StringBuilder();
                int offset = 0;

                for (int i = 0; i < text.Length; i++)
                {
                    var ch = text [i];
                    if (ch == '$')
                    {
                        offset = i;
                        continue;
                    }
                    sb.Append(ch);
                }

                var content = new TestViewContent();
                await content.Initialize(new FileDescriptor ("/a.json", null, null));

                content.Editor.MimeType = "application/json";

                content.Editor.Text = sb.ToString();

                test.testCase = await TextEditorExtensionTestCase.Create(content, null, false);

                test.testCase.Document.Editor.Options = new CustomEditorOptions {
                    TabsToSpaces = tabsToSpaces,
                    TabSize      = 4
                };

                var csi    = new JSonIndentEngine(content.Editor);
                var result = new CacheIndentEngine(csi);

                result.Update(content.Editor, offset);
                test.Engine = result;

                return(test);
            }
Exemple #11
0
        public void TestProjectionHighlighting()
        {
            var editor  = TextEditorFactory.CreateNewEditor();
            var options = new CustomEditorOptions(editor.Options);

            options.EditorTheme = "Tango";
            editor.Options      = options;
            editor.Text         = "1234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var tww        = new TestWorkbenchWindow();
            var content    = new TestViewContent();

            tww.ViewContent = content;

            var originalContext = new Document(tww);

            using (var testCase = new TextEditorExtensionTestCase(originalContext, content, tww, null, false)) {
                var projectedEditor = projection.CreateProjectedEditor(originalContext);
                projectedEditor.SemanticHighlighting = new TestSemanticHighlighting(projectedEditor, originalContext);
                editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None);

                var markup = editor.GetMarkup(0, editor.Length, new MarkupOptions(MarkupFormat.Pango));
                var color  = "#3363a4";
                Assert.AreEqual("<span foreground=\"" + color + "\">1</span><span foreground=\"#222222\">234</span><span foreground=\"" + color + "\">5</span><span foreground=\"#222222\">678</span><span foreground=\"" + color + "\">9</span><span foreground=\"#222222\">0</span>", markup);
            }
        }
        public async Task TestProjectionUpdate()
        {
            var editor = TextEditorFactory.CreateNewEditor();

            editor.Text = "1234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var content    = new TestViewContent();
            await content.Initialize(new FileDescriptor ("Foo.cs", null, null));

            using (var testCase = await TextEditorExtensionTestCase.Create(content, null, false)) {
                var originalContext = testCase.Document.DocumentContext;
                var projectedEditor = projection.CreateProjectedEditor(originalContext);
                editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.All);
                editor.InsertText(1, "foo");
                Assert.AreEqual("__1foo2__34__56__78__90", projectedEditor.Text);

                Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(0).ProjectedOffset);
                Assert.AreEqual(2 + "foo".Length, projection.ProjectedSegments.ElementAt(0).Length);
                for (int i = 1; i < 5; i++)
                {
                    Assert.AreEqual(2 + i * 4 + "foo".Length, projection.ProjectedSegments.ElementAt(i).ProjectedOffset);
                    Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(i).Length);
                }
            }
        }
        public void TestVSTS615849()
        {
            DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket = true;

            var tww     = new TestWorkbenchWindow();
            var content = new TestViewContent();

            tww.ViewContent = content;

            var document = new Document(tww);

            using (var testCase = new TextEditorExtensionTestCase(document, content, tww, null, false)) {
                var editor = TextEditorFactory.CreateNewEditor(document);
                editor.MimeType = "text/xml";
                const string originalText = @"";
                editor.Text = originalText;

                var extensibleEditor = editor.GetContent <SourceEditorView> ().TextEditor;
                extensibleEditor.OnIMProcessedKeyPressEvent((Gdk.Key) '"', '"', Gdk.ModifierType.None);
                extensibleEditor.OnIMProcessedKeyPressEvent(Gdk.Key.Right, '\0', Gdk.ModifierType.None);
                extensibleEditor.OnIMProcessedKeyPressEvent(Gdk.Key.BackSpace, '\0', Gdk.ModifierType.None);
                Assert.AreEqual("\"", editor.Text);
            }
        }