~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/UnitTests/Mono.TextEditor.Tests.DefaultEditActions/MiscActionsTest.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// EditActionsTest.cs
3
 
//  
4
 
// Author:
5
 
//       Mike KrĆ¼ger <mkrueger@novell.com>
6
 
// 
7
 
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
8
 
// 
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:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
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
25
 
// THE SOFTWARE.
26
 
 
27
 
using System;
28
 
using NUnit.Framework;
29
 
using Gtk;
30
 
 
31
 
namespace Mono.TextEditor.Tests.Actions
32
 
{
33
 
        [TestFixture()]
34
 
        public class MiscActionsTest : TextEditorTestBase
35
 
        {
36
 
                /// <summary>
37
 
                /// Bug 615191 - When using multiline selection to indent/outdent, the indenter selects too much
38
 
                /// </summary>
39
 
                [Test()]
40
 
                public void TestInsertTabBug615196_IndentCase ()
41
 
                {
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);
49
 
                        
50
 
                        Assert.AreEqual ("\n\t\t\n\t\t\n\n\n", data.Document.Text);
51
 
                }
52
 
                
53
 
                [Test()]
54
 
                public void TestRemoveTabBug615196_UnIndentCase ()
55
 
                {
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);
62
 
                        
63
 
                        Assert.AreEqual ("\n\n\n\t\t\n\n", data.Document.Text);
64
 
                }
65
 
        
66
 
                [Test()]
67
 
                public void TestGotoMatchingBracket ()
68
 
                {
69
 
                        var data = Create ("$(foo(bar))");
70
 
                        MiscActions.GotoMatchingBracket (data);
71
 
                        Check (data, "(foo(bar)$)");
72
 
                        MiscActions.GotoMatchingBracket (data);
73
 
                        Check (data, "$(foo(bar))");
74
 
                }
75
 
 
76
 
                [Test()]
77
 
                public void TestInsertNewLine ()
78
 
                {
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);
87
 
                }
88
 
 
89
 
                [Test()]
90
 
                public void TestUndo ()
91
 
                {
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);
97
 
                        Check (data, "foo$");
98
 
                }
99
 
 
100
 
                [Test()]
101
 
                public void TestRedo ()
102
 
                {
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$");
111
 
                }
112
 
        
113
 
                [Test()]
114
 
                public void TestInsertNewLineAtEnd ()
115
 
                {
116
 
                        var data = Create ("foo$bar");
117
 
                        MiscActions.InsertNewLineAtEnd (data);
118
 
                        Check (data, "foobar" + data.EolMarker + "$");
119
 
                }
120
 
 
121
 
                [Test()]
122
 
                public void TestInsertNewLinePreserveCaretPosition ()
123
 
                {
124
 
                        var data = Create ("foo$bar");
125
 
                        MiscActions.InsertNewLinePreserveCaretPosition (data);
126
 
                        Check (data, "foo$" + data.EolMarker + "bar");
127
 
                }
128
 
 
129
 
                [Test()]
130
 
                public void TestSwitchCaretMode ()
131
 
                {
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);
138
 
                }
139
 
 
140
 
                [Test()]
141
 
                public void TestMoveBlockDown ()
142
 
                {
143
 
                        var data = Create (@"aaaaaaaaa
144
 
bbbbbbbbbb
145
 
cccccccccc
146
 
dddddd$dddd
147
 
eeeeeeeeee
148
 
ffffffffff");
149
 
                        MiscActions.MoveBlockDown (data);
150
 
                        Check (data, @"aaaaaaaaa
151
 
bbbbbbbbbb
152
 
cccccccccc
153
 
eeeeeeeeee
154
 
dddddd$dddd
155
 
ffffffffff");
156
 
                }
157
 
 
158
 
                [Test()]
159
 
                public void TestMoveBlockDownSelection ()
160
 
                {
161
 
                        var data = Create (@"aaaaaaaaa
162
 
bbbbbbbbbb
163
 
ccc<-ccccccc
164
 
dddddd->$dddd
165
 
eeeeeeeeee
166
 
ffffffffff");
167
 
                        MiscActions.MoveBlockDown (data);
168
 
                        Check (data, @"aaaaaaaaa
169
 
bbbbbbbbbb
170
 
eeeeeeeeee
171
 
ccc<-ccccccc
172
 
dddddd->$dddd
173
 
ffffffffff");
174
 
                }
175
 
 
176
 
                [Test()]
177
 
                public void TestMoveBlockUp ()
178
 
                {
179
 
                        var data = Create (@"aaaaaaaaa
180
 
bbbbbbbbbb
181
 
cccccccccc
182
 
dddddd$dddd
183
 
eeeeeeeeee
184
 
ffffffffff");
185
 
                        MiscActions.MoveBlockUp (data);
186
 
                        Check (data, @"aaaaaaaaa
187
 
bbbbbbbbbb
188
 
dddddd$dddd
189
 
cccccccccc
190
 
eeeeeeeeee
191
 
ffffffffff");
192
 
                }
193
 
                
194
 
                [Test()]
195
 
                public void TestMoveBlockUpSelection ()
196
 
                {
197
 
                        var data = Create (@"aaaaaaaaa
198
 
bbbbbbbbbb
199
 
ccc<-ccccccc
200
 
dddddd->$dddd
201
 
eeeeeeeeee
202
 
ffffffffff");
203
 
                        MiscActions.MoveBlockUp (data);
204
 
                        Check (data, @"aaaaaaaaa
205
 
ccc<-ccccccc
206
 
dddddd->$dddd
207
 
bbbbbbbbbb
208
 
eeeeeeeeee
209
 
ffffffffff");
210
 
                }
211
 
 
212
 
                [Test()]
213
 
                public void TestDuplicateLines ()
214
 
                {
215
 
                        var data = Create (@"aaaaaaaaa
216
 
bbbbbbbbbb
217
 
cccccccccc
218
 
dddddd$dddd
219
 
eeeeeeeeee
220
 
ffffffffff");
221
 
                        MiscActions.DuplicateLine (data);
222
 
                        Check (data, @"aaaaaaaaa
223
 
bbbbbbbbbb
224
 
cccccccccc
225
 
dddddddddd
226
 
dddddd$dddd
227
 
eeeeeeeeee
228
 
ffffffffff");
229
 
                }
230
 
        }
231
 
}
232