2
// VirtualSpacesTests.cs
5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using NUnit.Framework;
31
namespace Mono.TextEditor.Tests
34
public class VirtualSpacesTests : TextEditorTestBase
38
/// Bug 615196 - Pasting a chunk of text into the virtual whitespace fracks everything up
41
public void TestBug615196 ()
43
TextEditorData data = new Mono.TextEditor.TextEditorData ();
44
data.Options.IndentStyle = IndentStyle.Auto;
45
data.Document.Text = "\n\nHello World\n";
46
data.Caret.Offset = 1; // 2nd.Line
47
data.Caret.AllowCaretBehindLineEnd = true;
48
data.Caret.Column = DocumentLocation.MinColumn + 4;
49
Clipboard clipboard = Clipboard.Get (Mono.TextEditor.ClipboardActions.CopyOperation.CLIPBOARD_ATOM);
50
clipboard.Text = "Test";
52
ClipboardActions.Paste (data);
54
Assert.AreEqual ("\n Test\nHello World\n", data.Document.Text);
58
/// Bug 613770 - Backspace inconsistently deletes entire lines when using "virtual spaces"
61
public void TestBug613770 ()
63
TextEditorData data = new Mono.TextEditor.TextEditorData ();
64
data.Options.IndentStyle = IndentStyle.Auto;
65
data.Document.Text = "\n\n\n";
66
data.Caret.Offset = 1; // 2nd.Line
67
data.Caret.AllowCaretBehindLineEnd = true;
68
data.Caret.Column = DocumentLocation.MinColumn + 4;
69
DeleteActions.Backspace (data);
71
Assert.AreEqual ("\n \n\n", data.Document.Text);
75
public void TestReturnKeyBehavior ()
77
TextEditorData data = new Mono.TextEditor.TextEditorData ();
78
data.Options.IndentStyle = IndentStyle.Auto;
79
data.Document.Text = "\n\n\n";
80
data.Caret.Offset = 1; // 2nd.Line
81
data.Caret.AllowCaretBehindLineEnd = true;
82
data.Caret.Column = DocumentLocation.MinColumn + 4;
83
MiscActions.InsertNewLine (data);
85
Assert.AreEqual ("\n \n \n\n", data.Document.Text);
89
/// Bug 615624 - Pressing DOWN after RETURN moves cursor to beginning of blank lines instead of to the indent
92
public void TestBug615624 ()
94
TextEditorData data = new Mono.TextEditor.TextEditorData ();
95
data.Options.IndentStyle = IndentStyle.Auto;
96
data.Document.Text = "\n \n\n";
97
data.Caret.AllowCaretBehindLineEnd = true;
98
data.Caret.Offset = 2; // 2nd.Line
99
Assert.AreEqual (DocumentLocation.MinColumn + 1, data.Caret.Column);
100
TextDocument.RemoveTrailingWhitespaces (data, data.Document.GetLine (2));
101
Assert.AreEqual ("\n\n\n", data.Document.Text);
102
Assert.AreEqual (DocumentLocation.MinColumn + 1, data.Caret.Column);
106
public void TestCaretRightBehavior ()
108
TextEditorData data = new Mono.TextEditor.TextEditorData ();
109
data.Options.IndentStyle = IndentStyle.Auto;
110
data.Document.Text = "\n\n\n";
111
data.Caret.AllowCaretBehindLineEnd = true;
113
CaretMoveActions.Right (data);
114
Assert.AreEqual (2, data.Caret.Column);
115
CaretMoveActions.Right (data);
116
Assert.AreEqual (3, data.Caret.Column);
117
Assert.AreEqual ("\n\n\n", data.Document.Text);
121
public void TestCaretLeftBehavior ()
123
TextEditorData data = new Mono.TextEditor.TextEditorData ();
124
data.Options.IndentStyle = IndentStyle.Auto;
125
data.Document.Text = "\n\n\n";
126
data.Caret.AllowCaretBehindLineEnd = true;
127
data.Caret.Column = 4;
129
CaretMoveActions.Left (data);
130
Assert.AreEqual (3, data.Caret.Column);
131
CaretMoveActions.Left (data);
132
Assert.AreEqual (2, data.Caret.Column);
133
Assert.AreEqual ("\n\n\n", data.Document.Text);