Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Krüger <mkrueger@xamarin.com>2014-02-17 14:15:13 +0400
committerMike Krüger <mkrueger@xamarin.com>2014-02-17 14:15:13 +0400
commit487298b272e36dcb64a21f6e2c57770120002fb4 (patch)
treef4e0ad050c9114b4ba112381d4012686747bc6bd /main/tests
parent98431952f0cfeb6e827167b7057f0c5a6d25415f (diff)
[CSharpBinding] Fixed on the fly formatter bug.
Diffstat (limited to 'main/tests')
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs80
1 files changed, 72 insertions, 8 deletions
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs
index 953946823d..e024ac162f 100644
--- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/OnTheFlyFormatterTests.cs
@@ -58,14 +58,41 @@ namespace MonoDevelop.CSharpBinding
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 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);
@@ -77,6 +104,8 @@ namespace MonoDevelop.CSharpBinding
content.Contents.Add (ext);
doc.UpdateParseDocument ();
+ if (selectionStart >= 0 && selectionEnd >= 0)
+ content.GetTextEditorData ().SetSelection (selectionStart, selectionEnd);
return ext;
}
@@ -288,6 +317,41 @@ class Foo
var newText = content.Text;
Assert.AreEqual ("@\"\\dev\null {0}\"", newText);
}
+
+ /// <summary>
+ /// Bug 17765 - Format selection adding extra leading whitespace on function
+ /// </summary>
+ [Test]
+ public void TestBug17765 ()
+ {
+ TestViewContent content;
+ var ext = Setup (@"
+namespace FormatSelectionTest
+{
+ public class EmptyClass
+ {
+ <-public EmptyClass ()
+ {
+ }->
}
+}", out content);
+
+ OnTheFlyFormatter.Format (ext.document, ext.document.Editor.SelectionRange.Offset, ext.document.Editor.SelectionRange.EndOffset);
+
+
+ Assert.AreEqual (@"
+namespace FormatSelectionTest
+{
+ public class EmptyClass
+ {
+ public EmptyClass ()
+ {
+ }
+ }
+}", ext.document.Editor.Text);
+ }
+
+ }
+
}