internal async Task <TextEditorExtensionTestCase> Create(string input, Ide.Editor.ITextEditorOptions options = null, bool createWithProject = false)
        {
            var sb = new StringBuilder();
            int caretIndex = -1, selectionStart = -1, selectionEnd = -1;
            var foldSegments = new List <IFoldSegment> ();
            var foldStack    = new Stack <Mono.TextEditor.FoldSegment> ();

            for (int i = 0; i < input.Length; i++)
            {
                var ch = input [i];
                switch (ch)
                {
                case '$':
                    caretIndex = sb.Length;
                    break;

                case '<':
                    if (i + 1 < input.Length)
                    {
                        if (input [i + 1] == '-')
                        {
                            selectionStart = sb.Length;
                            i++;
                            break;
                        }
                    }
                    goto default;

                case '-':
                    if (i + 1 < input.Length)
                    {
                        var next = input [i + 1];
                        if (next == '>')
                        {
                            selectionEnd = sb.Length;
                            i++;
                            break;
                        }
                        if (next == '[')
                        {
                            var segment = new Mono.TextEditor.FoldSegment("...", sb.Length, 0, FoldingType.Unknown);
                            segment.IsCollapsed = false;
                            foldStack.Push(segment);
                            i++;
                            break;
                        }
                    }
                    goto default;

                case '+':
                    if (i + 1 < input.Length)
                    {
                        var next = input [i + 1];
                        if (next == '[')
                        {
                            var segment = new Mono.TextEditor.FoldSegment("...", sb.Length, 0, FoldingType.Unknown);
                            segment.IsCollapsed = true;
                            foldStack.Push(segment);
                            i++;
                            break;
                        }
                    }
                    goto default;

                case ']':
                    if (foldStack.Count > 0)
                    {
                        var segment = foldStack.Pop();
                        segment.Length = sb.Length - segment.Offset;
                        foldSegments.Add(segment);
                        break;
                    }
                    goto default;

                default:
                    sb.Append(ch);
                    break;
                }
            }

            var testCase = await SetupTestCase(sb.ToString());

            var doc  = testCase.Document;
            var data = doc.Editor;

            data.Options = options ?? new CustomEditorOptions {
                DefaultEolMarker = eolMarker,
                IndentStyle      = IndentStyle.Smart,
            };

            if (caretIndex >= 0)
            {
                data.CaretOffset = caretIndex;
            }
            if (selectionStart >= 0)
            {
                if (caretIndex == selectionStart)
                {
                    data.SetSelection(selectionEnd, selectionStart);
                }
                else
                {
                    data.SetSelection(selectionStart, selectionEnd);
                    if (caretIndex < 0)
                    {
                        data.CaretOffset = selectionEnd;
                    }
                }
            }
            if (foldSegments.Count > 0)
            {
                data.SetFoldings(foldSegments);
            }
            return(testCase);
        }
Exemple #2
0
        internal static TestViewContent Create(string input, Ide.Editor.ITextEditorOptions options = null)
        {
            TestWorkbenchWindow tww = new TestWorkbenchWindow();
            var content             = new TestViewContent();

            content.Data.Options = options ?? new CustomEditorOptions {
                DefaultEolMarker = eolMarker,
                IndentStyle      = IndentStyle.Smart
            };
            tww.ViewContent       = content;
            content.ContentName   = "/a.cs";
            content.Data.MimeType = "text/x-csharp";

            var doc = new Document(tww);

            var sb = new StringBuilder();
            int caretIndex = -1, selectionStart = -1, selectionEnd = -1;
            var foldSegments = new List <IFoldSegment> ();
            var foldStack    = new Stack <Mono.TextEditor.FoldSegment> ();

            for (int i = 0; i < input.Length; i++)
            {
                var ch = input [i];
                switch (ch)
                {
                case '$':
                    caretIndex = sb.Length;
                    break;

                case '<':
                    if (i + 1 < input.Length)
                    {
                        if (input [i + 1] == '-')
                        {
                            selectionStart = sb.Length;
                            i++;
                            break;
                        }
                    }
                    goto default;

                case '-':
                    if (i + 1 < input.Length)
                    {
                        var next = input [i + 1];
                        if (next == '>')
                        {
                            selectionEnd = sb.Length;
                            i++;
                            break;
                        }
                        if (next == '[')
                        {
                            var segment = new Mono.TextEditor.FoldSegment("...", sb.Length, 0, FoldingType.Unknown);
                            segment.IsCollapsed = false;
                            foldStack.Push(segment);
                            i++;
                            break;
                        }
                    }
                    goto default;

                case '+':
                    if (i + 1 < input.Length)
                    {
                        var next = input [i + 1];
                        if (next == '[')
                        {
                            var segment = new Mono.TextEditor.FoldSegment("...", sb.Length, 0, FoldingType.Unknown);
                            segment.IsCollapsed = true;
                            foldStack.Push(segment);
                            i++;
                            break;
                        }
                    }
                    goto default;

                case ']':
                    if (foldStack.Count > 0)
                    {
                        var segment = foldStack.Pop();
                        segment.Length = sb.Length - segment.Offset;
                        foldSegments.Add(segment);
                        break;
                    }
                    goto default;

                default:
                    sb.Append(ch);
                    break;
                }
            }
            content.Data.Text = sb.ToString();

            if (caretIndex >= 0)
            {
                content.Data.CaretOffset = caretIndex;
            }
            if (selectionStart >= 0)
            {
                if (caretIndex == selectionStart)
                {
                    content.Data.SetSelection(selectionEnd, selectionStart);
                }
                else
                {
                    content.Data.SetSelection(selectionStart, selectionEnd);
                    if (caretIndex < 0)
                    {
                        content.Data.CaretOffset = selectionEnd;
                    }
                }
            }
            if (foldSegments.Count > 0)
            {
                content.Data.SetFoldings(foldSegments);
            }

            return(content);
        }