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.Actions
34
public class MiscActionsTest : TextEditorTestBase
37
/// Bug 615191 - When using multiline selection to indent/outdent, the indenter selects too much
40
public void TestInsertTabBug615196_IndentCase ()
42
TextEditorData data = new Mono.TextEditor.TextEditorData ();
43
data.Options = new TextEditorOptions () { IndentStyle = IndentStyle.Smart };
44
data.Document.Text = "\n\n\n\n\n";
45
data.Caret.Offset = data.Document.GetLine (2).Offset; // 2nd.Line
46
data.MainSelection = new Selection (2, 1, 4, 1);
47
MiscActions.InsertTab (data);
48
MiscActions.InsertTab (data);
50
Assert.AreEqual ("\n\t\t\n\t\t\n\n\n", data.Document.Text);
54
public void TestRemoveTabBug615196_UnIndentCase ()
56
TextEditorData data = new Mono.TextEditor.TextEditorData ();
57
data.Document.Text = "\n\t\t\n\t\t\n\t\t\n\n";
58
data.Caret.Offset = data.Document.GetLine (2).Offset; // 2nd.Line
59
data.MainSelection = new Selection (2, 1, 4, 1);
60
MiscActions.RemoveTab (data);
61
MiscActions.RemoveTab (data);
63
Assert.AreEqual ("\n\n\n\t\t\n\n", data.Document.Text);
67
public void TestGotoMatchingBracket ()
69
var data = Create ("$(foo(bar))");
70
MiscActions.GotoMatchingBracket (data);
71
Check (data, "(foo(bar)$)");
72
MiscActions.GotoMatchingBracket (data);
73
Check (data, "$(foo(bar))");
77
public void TestInsertNewLine ()
79
TextEditorData data = new Mono.TextEditor.TextEditorData ();
80
data.Document.Text = "Hello World!";
81
data.Caret.Location = new DocumentLocation (1, "Hello".Length + 1);
82
MiscActions.InsertNewLine (data);
83
Assert.AreEqual (2, data.Document.LineCount);
84
Assert.AreEqual (2, data.Caret.Line);
85
Assert.AreEqual (1, data.Caret.Column);
86
Assert.AreEqual ("Hello" + Environment.NewLine + " World!", data.Document.Text);
90
public void TestUndo ()
92
// Undo/Redo subsystem is tested separately, this only checks if the action is working.
93
var data = Create ("foo$");
94
data.InsertAtCaret ("bar");
95
Check (data, "foobar$");
96
MiscActions.Undo (data);
101
public void TestRedo ()
103
// Undo/Redo subsystem is tested separately, this only checks if the action is working.
104
var data = Create ("foo$");
105
data.InsertAtCaret ("bar");
106
Check (data, "foobar$");
107
MiscActions.Undo (data);
108
Check (data, "foo$");
109
MiscActions.Redo (data);
110
Check (data, "foobar$");
114
public void TestInsertNewLineAtEnd ()
116
var data = Create ("foo$bar");
117
MiscActions.InsertNewLineAtEnd (data);
118
Check (data, "foobar" + data.EolMarker + "$");
122
public void TestInsertNewLinePreserveCaretPosition ()
124
var data = Create ("foo$bar");
125
MiscActions.InsertNewLinePreserveCaretPosition (data);
126
Check (data, "foo$" + data.EolMarker + "bar");
130
public void TestSwitchCaretMode ()
132
var data = Create ("foo$bar");
133
Assert.IsTrue (data.Caret.IsInInsertMode);
134
MiscActions.SwitchCaretMode (data);
135
Assert.IsFalse (data.Caret.IsInInsertMode);
136
MiscActions.SwitchCaretMode (data);
137
Assert.IsTrue (data.Caret.IsInInsertMode);
141
public void TestMoveBlockDown ()
143
var data = Create (@"aaaaaaaaa
149
MiscActions.MoveBlockDown (data);
150
Check (data, @"aaaaaaaaa
159
public void TestMoveBlockDownSelection ()
161
var data = Create (@"aaaaaaaaa
167
MiscActions.MoveBlockDown (data);
168
Check (data, @"aaaaaaaaa
177
public void TestMoveBlockUp ()
179
var data = Create (@"aaaaaaaaa
185
MiscActions.MoveBlockUp (data);
186
Check (data, @"aaaaaaaaa
195
public void TestMoveBlockUpSelection ()
197
var data = Create (@"aaaaaaaaa
203
MiscActions.MoveBlockUp (data);
204
Check (data, @"aaaaaaaaa
213
public void TestDuplicateLines ()
215
var data = Create (@"aaaaaaaaa
221
MiscActions.DuplicateLine (data);
222
Check (data, @"aaaaaaaaa