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

« back to all changes in this revision

Viewing changes to tests/UnitTests/Mono.TextEditor.Tests/SelectionTests.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
 
// SelectionTests.cs
2
 
//
3
 
// Author:
4
 
//   Mike Krüger <mkrueger@novell.com>
5
 
//
6
 
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
7
 
//
8
 
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
 
// of this software and associated documentation files (the "Software"), to deal
10
 
// in the Software without restriction, including without limitation the rights
11
 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 
// copies of the Software, and to permit persons to whom the Software is
13
 
// furnished to do so, subject to the following conditions:
14
 
//
15
 
// The above copyright notice and this permission notice shall be included in
16
 
// all copies or substantial portions of the Software.
17
 
//
18
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 
// THE SOFTWARE.
25
 
//
26
 
//
27
 
 
28
 
using System;
29
 
using System.Linq;
30
 
using NUnit.Framework;
31
 
 
32
 
namespace Mono.TextEditor.Tests
33
 
{
34
 
        [TestFixture()]
35
 
        public class SelectionTests
36
 
        {
37
 
                
38
 
                static TextSegment GetSelection (TextEditorData data, bool reverse)
39
 
                {
40
 
                        int offset1 = data.Document.Text.IndexOf ('[');
41
 
                        int offset2 = data.Document.Text.IndexOf (']');
42
 
                        return new TextSegment (offset1, offset2 - offset1);
43
 
                }
44
 
 
45
 
                static void SetSelection (TextEditorData data, bool reverse)
46
 
                {
47
 
                        var selection = GetSelection (data, reverse);
48
 
                        
49
 
                        if (reverse) {
50
 
                                data.Caret.Offset = selection.Offset;
51
 
                                data.SelectionAnchor = selection.EndOffset;
52
 
                                data.ExtendSelectionTo (selection.Offset);
53
 
                        } else {
54
 
                                data.Caret.Offset = selection.EndOffset;
55
 
                                data.SelectionAnchor = selection.Offset;
56
 
                                data.ExtendSelectionTo (selection.EndOffset);
57
 
                        }
58
 
                }
59
 
                
60
 
                [Test()]
61
 
                public void TestExtendSelectionTo ()
62
 
                {
63
 
                        TextEditorData data = new Mono.TextEditor.TextEditorData  ();
64
 
data.Document.Text = 
65
 
@"123456789
66
 
123456789
67
 
123456789
68
 
123456789
69
 
123456789
70
 
123456789";
71
 
                        
72
 
                        data.SelectionAnchor = 3;
73
 
                        DocumentLine line = data.Document.GetLine (3);
74
 
                        
75
 
                        Assert.IsFalse (data.IsSomethingSelected);
76
 
                        data.ExtendSelectionTo (line.Offset + 3);
77
 
                        
78
 
                        Assert.IsTrue (data.IsSomethingSelected);
79
 
                        
80
 
                        Assert.AreEqual (3, data.SelectionRange.Offset);
81
 
                        Assert.AreEqual (line.Offset + 3, data.SelectionRange.EndOffset);
82
 
                }
83
 
                
84
 
                [Test()]
85
 
                public void TestSelectedLines ()
86
 
                {
87
 
                        TextEditorData data = new Mono.TextEditor.TextEditorData  ();
88
 
data.Document.Text = 
89
 
@"123456789
90
 
123[456789
91
 
123456789
92
 
1234]56789
93
 
123456789
94
 
123456789";
95
 
                        SetSelection (data, false);
96
 
                        int lines = data.SelectedLines.Count ();
97
 
                        Assert.AreEqual (3, lines);
98
 
                }
99
 
                
100
 
                [Test()]
101
 
                public void TestSelectedLinesReverse ()
102
 
                {
103
 
                        TextEditorData data = new Mono.TextEditor.TextEditorData  ();
104
 
data.Document.Text = 
105
 
@"123456789
106
 
123[456789
107
 
123456789
108
 
1234]56789
109
 
123456789
110
 
123456789";
111
 
                        SetSelection (data, true);
112
 
                        Assert.AreEqual (3, data.SelectedLines.Count ());
113
 
                }
114
 
                
115
 
                [Test()]
116
 
                public void TestSelectedLinesCase2 ()
117
 
                {
118
 
                        TextEditorData data = new Mono.TextEditor.TextEditorData  ();
119
 
data.Document.Text = 
120
 
@"123456789
121
 
123[456789
122
 
123456789
123
 
123456789
124
 
]123456789
125
 
123456789";
126
 
                        SetSelection (data, false);
127
 
                        Assert.AreEqual (3, data.SelectedLines.Count ());
128
 
                }
129
 
                
130
 
                [Test()]
131
 
                public void TestSelectedLinesCase2Reverse ()
132
 
                {
133
 
                        TextEditorData data = new Mono.TextEditor.TextEditorData  ();
134
 
data.Document.Text = 
135
 
@"123456789
136
 
123[456789
137
 
123456789
138
 
123456789
139
 
]123456789
140
 
123456789";
141
 
                        SetSelection (data, true);
142
 
                        Assert.AreEqual (3, data.SelectedLines.Count ());
143
 
                }
144
 
                
145
 
                [Test()]
146
 
                public void TestSelectedLinesCase3 ()
147
 
                {
148
 
                        TextEditorData data = new Mono.TextEditor.TextEditorData  ();
149
 
data.Document.Text = 
150
 
@"123456789
151
 
[123456789
152
 
123456789
153
 
123]456789
154
 
123456789
155
 
123456789";
156
 
                        SetSelection (data, false);
157
 
                        Assert.AreEqual (3, data.SelectedLines.Count ());
158
 
                }
159
 
                
160
 
                [Test()]
161
 
                public void TestSelectedLinesCase3Reverse ()
162
 
                {
163
 
                        TextEditorData data = new Mono.TextEditor.TextEditorData  ();
164
 
data.Document.Text = 
165
 
@"123456789
166
 
[123456789
167
 
123456789
168
 
123]456789
169
 
123456789
170
 
123456789";
171
 
                        SetSelection (data, true);
172
 
                        Assert.AreEqual (3, data.SelectedLines.Count ());
173
 
                }
174
 
                
175
 
                [Test()]
176
 
                public void TestSetSelectedLines ()
177
 
                {
178
 
                        TextEditorData data = new Mono.TextEditor.TextEditorData  ();
179
 
data.Document.Text = 
180
 
@"1
181
 
2
182
 
3
183
 
";
184
 
                        data.SetSelectLines (1, 4);
185
 
                        Assert.AreEqual (0, data.SelectionAnchor);
186
 
                        Assert.AreEqual (0, data.SelectionRange.Offset);
187
 
                        Assert.AreEqual (data.Document.TextLength, data.SelectionRange.EndOffset);
188
 
                }
189
 
        }
190
 
}