Beispiel #1
0
        public void PastemultilineAtFirstColumnCorrection()
        {
            var indent = CreateEngine("class Foo\n{\n$\n}");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, CreateInvariantOptions(), FormattingOptionsFactory.CreateMono());
            var text = handler.FormatPlainText(indent.Offset, "void Bar ()\n{\n\tSystem.Console.WriteLine ();\n}", null);

            Assert.AreEqual("\tvoid Bar ()\n\t{\n\t\tSystem.Console.WriteLine ();\n\t}", text);
        }
Beispiel #2
0
        public void TestWindowsLineEnding()
        {
            var indent = CreateEngine("\r\nclass Foo\r\n{\r\n\tvoid Bar ()\r\n\t{\r\n\t\t$\r\n\t}\r\n}");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, CreateInvariantOptions(), FormattingOptionsFactory.CreateMono());
            var text = handler.FormatPlainText(indent.Offset, "Foo();\r\nBar();\r\nTest();", null);

            Assert.AreEqual("Foo();\n\t\tBar();\n\t\tTest();", text);
        }
Beispiel #3
0
        public void PasteVerbatimStringBug2()
        {
            var indent = CreateEngine("\nclass Foo\n{\n\tvoid Bar ()\n\t{\n\t\t$\n\t}\n}");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, CreateInvariantOptions(), FormattingOptionsFactory.CreateMono());
            var text = handler.FormatPlainText(indent.Offset, "if (true)\nConsole.WriteLine (@\"Hello\n World!\");\n", null);

            Assert.AreEqual("if (true)\n\t\t\tConsole.WriteLine (@\"Hello\n World!\");\n\t\t", text);
        }
Beispiel #4
0
        public void TestPasteBlankLines()
        {
            var indent = CreateEngine("class Foo\n{\n\tvoid Bar ()\n\t{\n\t\tSystem.Console.WriteLine ($);\n\t}\n}");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, CreateInvariantOptions(), FormattingOptionsFactory.CreateMono());
            var text = handler.FormatPlainText(indent.Offset, "\n\n\n", null);

            Assert.AreEqual("\n\n\n\t\t\t", text);
        }
Beispiel #5
0
        public void PasteVerbatimStringBug4()
        {
            var indent = CreateEngine("\nclass Foo\n{\n\tvoid Bar ()\n\t{\n$\n\t}\n}");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, CreateInvariantOptions(), FormattingOptionsFactory.CreateMono());

            var text = handler.FormatPlainText(indent.Offset, "var str1 = \n@\"hello\";", null);

            Assert.AreEqual("\t\tvar str1 = \n\t\t\t@\"hello\";", text);
        }
Beispiel #6
0
        public void TestBug16415()
        {
            var opt    = FormattingOptionsFactory.CreateMono();
            var indent = CreateEngine("class Foo\n{\n\tpublic static void Main (string[] args)\n\t{\n\t\tConsole.WriteLine ();$\n\t}\n}\n", opt);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, CreateInvariantOptions(), opt);
            var text = handler.FormatPlainText(indent.Offset, "// Line 1\n// Line 2\n// Line 3", null);

            Assert.AreEqual("// Line 1\n\t\t// Line 2\n\t\t// Line 3", text);
        }
Beispiel #7
0
        public void TestPasteToWindowsEol()
        {
            var indent = CreateEngine("$");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, new TextEditorOptions {
                EolMarker = "\r\n"
            }, FormattingOptionsFactory.CreateMono());
            var text = handler.FormatPlainText(indent.Offset, "namespace Foo\n{\n\tpublic static class FooExtensions\n\t{\n\t\tpublic static int ObjectExtension (this object value)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\n\t\tpublic static int IntExtension (this int value)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tpublic class Client\n\t{\n\t\tpublic void Method ()\n\t\t{\n\t\t\t0.ToString ();\n\t\t}\n\t}\n}", null);

            Assert.AreEqual("namespace Foo\r\n{\r\n\tpublic static class FooExtensions\r\n\t{\r\n\t\tpublic static int ObjectExtension (this object value)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tpublic static int IntExtension (this int value)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Client\r\n\t{\r\n\t\tpublic void Method ()\r\n\t\t{\r\n\t\t\t0.ToString ();\r\n\t\t}\r\n\t}\r\n}", text);
        }
        public void PasteVerbatimStringBug3()
        {
            SourceText        sourceText;
            var               indent  = CreateEngine("\nclass Foo\n{\n\tvoid Bar ()\n\t{\n$\n\t}\n}", out sourceText);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, FormattingOptionsFactory.CreateMono());

            var text = handler.FormatPlainText(sourceText, indent.Offset, "\t\tSystem.Console.WriteLine(@\"<evlevlle>\", out sourceText);\n", null);

            Assert.AreEqual("\t\tSystem.Console.WriteLine(@\"<evlevlle>\", out sourceText);\n\t\t", text);
        }
        public void TestPasteBlankLinesAndIndent()
        {
            SourceText sourceText;
            var        indent  = CreateEngine("class Foo\n{\n\tvoid Bar ()\n\t{\n\t\tSystem.Console.WriteLine ($);\n\t}\n}", out sourceText);
            var        options = FormattingOptionsFactory.CreateMono();
//			options.EmptyLineFormatting = EmptyLineFormatting.Indent;
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, options);
            var text = handler.FormatPlainText(sourceText, indent.Offset, "\n\n\n", null);

            Assert.AreEqual("\n\t\t\t\n\t\t\t\n\t\t\t", text);
        }
Beispiel #10
0
        public void PasteVerbatimStringBug1()
        {
            var textEditorOptions = CreateInvariantOptions();

            textEditorOptions.EolMarker = "\r\n";
            var indent = CreateEngine("\r\nclass Foo\r\n{\r\n\tvoid Bar ()\r\n\t{\r\n\t\t$\r\n\t}\r\n}", FormattingOptionsFactory.CreateMono(), textEditorOptions);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, textEditorOptions, FormattingOptionsFactory.CreateMono());
            var text = handler.FormatPlainText(indent.Offset, "Console.WriteLine (@\"Hello World!\");\n", null);

            Assert.AreEqual("Console.WriteLine (@\"Hello World!\");\r\n\t\t", text);
        }
Beispiel #11
0
        public void TestWindowsLineEndingCase2()
        {
            var textEditorOptions = CreateInvariantOptions();

            textEditorOptions.EolMarker = "\r\n";
            var indent = CreateEngine("\r\nclass Foo\r\n{\r\n\tvoid Bar ()\r\n\t{\r\n\t\t$\r\n\t}\r\n}", FormattingOptionsFactory.CreateMono(), textEditorOptions);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, textEditorOptions, FormattingOptionsFactory.CreateMono());
            var text = handler.FormatPlainText(indent.Offset, "if (true)\r\nBar();\r\nTest();", null);

            Assert.AreEqual("if (true)\r\n\t\t\tBar();\r\n\t\tTest();", text);
        }
        public void TestWindowsLineEndingCase2()
        {
            var options = FormattingOptionsFactory.CreateMono();

            options = options.WithChangedOption(FormattingOptions.NewLine, LanguageNames.CSharp, "\r\n");
            SourceText        sourceText;
            var               indent  = CreateEngine("\r\nclass Foo\r\n{\r\n\tvoid Bar ()\r\n\t{\r\n\t\t$\r\n\t}\r\n}", out sourceText, options);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, options);
            var               text    = handler.FormatPlainText(sourceText, indent.Offset, "if (true)\r\nBar();\r\nTest();", null);

            Assert.AreEqual("if (true)\r\n\t\t\tBar();\r\n\t\tTest();", text);
        }
        public void PasteVerbatimStringBug1()
        {
            var textEditorOptions = FormattingOptionsFactory.CreateMono();

            textEditorOptions = textEditorOptions.WithChangedOption(FormattingOptions.NewLine, LanguageNames.CSharp, "\r\n");
            SourceText        sourceText;
            var               indent  = CreateEngine("\r\nclass Foo\r\n{\r\n\tvoid Bar ()\r\n\t{\r\n\t\t$\r\n\t}\r\n}", out sourceText, textEditorOptions);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, textEditorOptions);
            var               text    = handler.FormatPlainText(sourceText, indent.Offset, "Console.WriteLine (@\"Hello World!\", out sourceText);\n", null);

            Assert.AreEqual("Console.WriteLine (@\"Hello World!\", out sourceText);\r\n\t\t", text);
        }
Beispiel #14
0
        public void TestPasteComments()
        {
            var indent = CreateEngine(@"
class Foo
{
	$
}");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, CreateInvariantOptions(), FormattingOptionsFactory.CreateMono());
            var text = handler.FormatPlainText(indent.Offset, "// Foo\n\t// Foo 2\n\t// Foo 3", null);

            Assert.AreEqual("// Foo\n\t// Foo 2\n\t// Foo 3", text);
        }
        public void TestPasteToWindowsEol()
        {
            SourceText sourceText;
            var        indent  = CreateEngine("$", out sourceText);
            var        options = FormattingOptionsFactory.CreateMono();

            options = options.WithChangedOption(FormattingOptions.NewLine, LanguageNames.CSharp, "\r\n");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, options);
            var text = handler.FormatPlainText(sourceText, indent.Offset, "namespace Foo\n{\n\tpublic static class FooExtensions\n\t{\n\t\tpublic static int ObjectExtension (this object value)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\n\t\tpublic static int IntExtension (this int value)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tclass Client\n\t{\n\t\tpublic void Method ()\n\t\t{\n\t\t\t0.ToString ();\n\t\t}\n\t}\n}", null);

            Assert.AreEqual("namespace Foo\r\n{\r\n\tpublic static class FooExtensions\r\n\t{\r\n\t\tpublic static int ObjectExtension (this object value)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tpublic static int IntExtension (this int value)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n\r\n\tclass Client\r\n\t{\r\n\t\tpublic void Method ()\r\n\t\t{\r\n\t\t\t0.ToString ();\r\n\t\t}\r\n\t}\r\n}", text);
        }
Beispiel #16
0
        public void PasteInTerminatedVerbatimString()
        {
            var opt = FormattingOptionsFactory.CreateMono();

            opt.IndentPreprocessorDirectives = false;

            var indent = CreateEngine(@"
var foo = @""hello$"";
", opt);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, CreateInvariantOptions(), opt);
            var text = handler.FormatPlainText(indent.Offset, "Hi \" + username;", null);

            Assert.AreEqual("Hi \"\" + username;", text);
        }
        public void PasteInTerminatedString()
        {
            var opt = FormattingOptionsFactory.CreateMono();
            //opt.IndentPreprocessorDirectives = false;

            SourceText        sourceText;
            var               indent  = CreateEngine(@"
var foo = ""hello$"";
", out sourceText, opt);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, opt);
            var               text    = handler.FormatPlainText(sourceText, indent.Offset, "Hi \" + username;", null);

            Assert.AreEqual("Hi \\\" + username;", text);
        }
Beispiel #18
0
        public void TestSimplePaste()
        {
            var indent = CreateEngine(@"
class Foo
{
	void Bar ()
	{
		System.Console.WriteLine ($);
	}
}");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, CreateInvariantOptions(), FormattingOptionsFactory.CreateMono());
            var text = handler.FormatPlainText(indent.Offset, "Foo", null);

            Assert.AreEqual("Foo", text);
        }
        public void TestPasteNewLineCase2()
        {
            SourceText        sourceText;
            var               indent  = CreateEngine(@"
class Foo
{
$	void Bar ()
	{
	}
}", out sourceText);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, FormattingOptionsFactory.CreateMono());
            var               text    = handler.FormatPlainText(sourceText, indent.Offset, "int i;\n", null);

            Assert.AreEqual("\tint i;\n", text);
        }
Beispiel #20
0
        public void PastePreProcessorDirectivesNoIndent()
        {
            var opt = FormattingOptionsFactory.CreateMono();

            opt.IndentPreprocessorDirectives = false;

            var indent = CreateEngine(@"
class Foo
{
$
}", opt);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, CreateInvariantOptions(), opt);
            var text = handler.FormatPlainText(indent.Offset, "#if DEBUG\n\tvoid Foo()\n\t{\n\t}\n#endif", null);

            Assert.AreEqual("#if DEBUG\n\tvoid Foo()\n\t{\n\t}\n#endif", text);
        }
Beispiel #21
0
        public void TestPasteNewLineCase2()
        {
            var indent = CreateEngine(@"
class Foo
{
$	void Bar ()
	{
	}
}");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, new TextEditorOptions {
                EolMarker = "\n"
            }, FormattingOptionsFactory.CreateMono());
            var text = handler.FormatPlainText(indent.Offset, "int i;\n", null);

            Assert.AreEqual("\tint i;\n", text);
        }
        public void PasteVerbatimString()
        {
            SourceText        sourceText;
            var               indent  = CreateEngine(@"
class Foo
{
void Bar ()
{
	
}
}", out sourceText);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, FormattingOptionsFactory.CreateMono());
            var               str     = "string str = @\"\n1\n\t2 \n\t\t3\n\";";
            var               text    = handler.FormatPlainText(sourceText, indent.Offset, str, null);

            Assert.AreEqual(str, text);
        }
        public void TestMultiLinePaste()
        {
            SourceText        sourceText;
            var               indent  = CreateEngine(@"
namespace FooBar
{
	class Foo
	{
		void Bar ()
		{
			System.Console.WriteLine ();
		}
		$
	}
}
", out sourceText);
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, FormattingOptionsFactory.CreateMono());

            var text = handler.FormatPlainText(sourceText, indent.Offset, "void Bar ()\n{\nSystem.Console.WriteLine ();\n}", null);

            Assert.AreEqual("void Bar ()\n\t\t{\n\t\t\tSystem.Console.WriteLine ();\n\t\t}", text);
        }
Beispiel #24
0
        public void TestMultiplePastes()
        {
            var indent = CreateEngine(@"
class Foo
{
	void Bar ()
	{
		System.Console.WriteLine ();
	}
	$
}


");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, new TextEditorOptions {
                EolMarker = "\n"
            }, FormattingOptionsFactory.CreateMono());

            for (int i = 0; i < 2; i++)
            {
                var text = handler.FormatPlainText(indent.Offset, "void Bar ()\n{\nSystem.Console.WriteLine ();\n}", null);
                Assert.AreEqual("void Bar ()\n\t{\n\t\tSystem.Console.WriteLine ();\n\t}", text);
            }
        }