public async Task TestVSTS634797()
        {
            using (var testCase = await Create(@"
class Foo 
{
    void Bar()
    {
        $    int a;
    }
}
", createWithProject: true)) {
                var indent = new CSharpTextEditorIndentation();
                indent.Initialize(testCase.Document.Editor, testCase.Document);
                var offset = testCase.Document.Editor.CaretOffset;
                indent.SafeUpdateIndentEngine(offset);
                var pasteHandler = new CSharpTextPasteHandler(indent, null);
                await pasteHandler.PostFomatPastedText(offset, "	int a;".Length);

                CheckOutput(testCase, @"
class Foo 
{
    void Bar()
    {
        int a;
    }
}
", indent);
            }
        }
        public async Task TestVSTS567503()
        {
            using (var testCase = await Create(@"
class Foo 
{
	/// <exception cref="""">$
	void Bar ()
	{
	}
}
", createWithProject: true)) {
                var indent = new CSharpTextEditorIndentation();
                indent.Initialize(testCase.Document.Editor, testCase.Document);
                indent.KeyPress(KeyDescriptor.FromGtk((Gdk.Key) '>', '>', Gdk.ModifierType.None));

                CheckOutput(testCase, @"
class Foo 
{
	/// <exception cref="""">$</exception>
	void Bar ()
	{
	}
}
", indent);
            }
        }
Beispiel #3
0
        public void TestBug17766()
        {
            var data   = Create(@"
class Foo 
{
	$void Bar ()
	{
	}
}
");
            var engine = new CSharpTextEditorIndentation();

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

            tww.ViewContent     = content;
            content.ContentName = "a.cs";
            engine.Initialize(new Document(tww));
            MiscActions.RemoveTab(data);
            engine.KeyPress(Gdk.Key.Tab, '\t', Gdk.ModifierType.ShiftMask);
            CheckOutput(data, @"
class Foo 
{
$void Bar ()
	{
	}
}
", engine);
        }
Beispiel #4
0
        static CSharpTextEditorIndentation Setup(string input, out TestViewContent content)
        {
            TestWorkbenchWindow tww = new TestWorkbenchWindow();

            content = new TestViewContent();
            content.Data.Options.IndentStyle = IndentStyle.Auto;
            tww.ViewContent     = content;
            content.ContentName = "a.cs";
            content.GetTextEditorData().Document.MimeType = "text/x-csharp";

            Document doc = new Document(tww);

            var text   = input;
            int endPos = text.IndexOf('$');

            if (endPos >= 0)
            {
                text = text.Substring(0, endPos) + text.Substring(endPos + 1);
            }

            content.Text           = text;
            content.CursorPosition = System.Math.Max(0, endPos);


            var compExt = new CSharpCompletionTextEditorExtension();

            compExt.Initialize(doc);
            content.Contents.Add(compExt);

            var ext = new CSharpTextEditorIndentation();

            CSharpTextEditorIndentation.OnTheFlyFormatting = true;
            ext.Initialize(doc);
            content.Contents.Add(ext);

            doc.UpdateParseDocument();
            return(ext);
        }
        public async Task TestIssue5951()
        {
            using (var data = await Create(@"
using System;

namespace MyLibrary
{
	public class MyClass
	{
		public MyClass()
		{
		}
$
	}
}")) {
                data.Document.Editor.Options = new CustomEditorOptions(data.Document.Editor.Options)
                {
                    IndentStyle = IndentStyle.Smart,
                    RemoveTrailingWhitespaces = false
                };
                var indent = new CSharpTextEditorIndentation();
                indent.Initialize(data.Document.Editor, data.Document);
                indent.KeyPress(KeyDescriptor.FromGtk(Gdk.Key.Return, '\n', Gdk.ModifierType.None));
                CheckOutput(data, @"
using System;

namespace MyLibrary
{
	public class MyClass
	{
		public MyClass()
		{
		}
		$
	}
}", indent);
            }
        }
        static async Task Simulate(string input, Action <TestViewContent, CSharpTextEditorIndentation> act)
        {
            TestWorkbenchWindow tww = new TestWorkbenchWindow();
            var content             = new TestViewContent();

            content.Data.Options = new CustomEditorOptions {
                IndentStyle = IndentStyle.Auto
            };

            tww.ViewContent       = content;
            content.ContentName   = "/a.cs";
            content.Data.MimeType = "text/x-csharp";

            var doc = new Document(tww);

            var sb = new StringBuilder();
            int cursorPosition = 0, selectionStart = -1, selectionEnd = -1;

            for (int i = 0; i < input.Length; i++)
            {
                var ch = input [i];
                switch (ch)
                {
                case '$':
                    cursorPosition = 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;
                        }
                    }
                    goto default;

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

            var project = Services.ProjectService.CreateProject("C#");

            project.Name     = "test";
            project.FileName = "test.csproj";
            project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile));
            project.Policies.Set(Projects.Policies.PolicyService.InvariantPolicies.Get <CSharpFormattingPolicy> (), CSharpFormatter.MimeType);

            var solution = new MonoDevelop.Projects.Solution();

            solution.AddConfiguration("", true);
            solution.DefaultSolutionFolder.AddItem(project);
            using (var monitor = new ProgressMonitor())
                await TypeSystemService.Load(solution, monitor);
            content.Project = project;
            doc.SetProject(project);

            var compExt = new CSharpCompletionTextEditorExtension();

            compExt.Initialize(doc.Editor, doc);
            content.Contents.Add(compExt);

            var ext = new CSharpTextEditorIndentation();

            CSharpTextEditorIndentation.OnTheFlyFormatting = true;
            ext.Initialize(doc.Editor, doc);
            content.Contents.Add(ext);

            await doc.UpdateParseDocument();

            if (selectionStart >= 0 && selectionEnd >= 0)
            {
                content.GetTextEditorData().SetSelection(selectionStart, selectionEnd);
            }
            try {
                act(content, ext);
            } finally {
                TypeSystemService.Unload(solution);
            }
        }
Beispiel #7
0
        static CSharpTextEditorIndentation Setup(string input, out TestViewContent content)
        {
            TestWorkbenchWindow tww = new TestWorkbenchWindow();

            content = new TestViewContent();
            content.Data.Options.IndentStyle = IndentStyle.Auto;
            tww.ViewContent     = content;
            content.ContentName = "a.cs";
            content.GetTextEditorData().Document.MimeType = "text/x-csharp";

            Document doc = new Document(tww);

            var sb = new StringBuilder();
            int cursorPosition = 0, selectionStart = -1, selectionEnd = -1;

            for (int i = 0; i < input.Length; i++)
            {
                var ch = input [i];
                switch (ch)
                {
                case '$':
                    cursorPosition = 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;
                        }
                    }
                    goto default;

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

            var compExt = new CSharpCompletionTextEditorExtension();

            compExt.Initialize(doc);
            content.Contents.Add(compExt);

            var ext = new CSharpTextEditorIndentation();

            CSharpTextEditorIndentation.OnTheFlyFormatting = true;
            ext.Initialize(doc);
            content.Contents.Add(ext);

            doc.UpdateParseDocument();
            if (selectionStart >= 0 && selectionEnd >= 0)
            {
                content.GetTextEditorData().SetSelection(selectionStart, selectionEnd);
            }
            return(ext);
        }