4
// Mike Krüger <mkrueger@novell.com>
6
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
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:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
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
30
using NUnit.Framework;
32
namespace Mono.TextEditor.Tests
35
public class SelectionTests
38
static TextSegment GetSelection (TextEditorData data, bool reverse)
40
int offset1 = data.Document.Text.IndexOf ('[');
41
int offset2 = data.Document.Text.IndexOf (']');
42
return new TextSegment (offset1, offset2 - offset1);
45
static void SetSelection (TextEditorData data, bool reverse)
47
var selection = GetSelection (data, reverse);
50
data.Caret.Offset = selection.Offset;
51
data.SelectionAnchor = selection.EndOffset;
52
data.ExtendSelectionTo (selection.Offset);
54
data.Caret.Offset = selection.EndOffset;
55
data.SelectionAnchor = selection.Offset;
56
data.ExtendSelectionTo (selection.EndOffset);
61
public void TestExtendSelectionTo ()
63
TextEditorData data = new Mono.TextEditor.TextEditorData ();
72
data.SelectionAnchor = 3;
73
DocumentLine line = data.Document.GetLine (3);
75
Assert.IsFalse (data.IsSomethingSelected);
76
data.ExtendSelectionTo (line.Offset + 3);
78
Assert.IsTrue (data.IsSomethingSelected);
80
Assert.AreEqual (3, data.SelectionRange.Offset);
81
Assert.AreEqual (line.Offset + 3, data.SelectionRange.EndOffset);
85
public void TestSelectedLines ()
87
TextEditorData data = new Mono.TextEditor.TextEditorData ();
95
SetSelection (data, false);
96
int lines = data.SelectedLines.Count ();
97
Assert.AreEqual (3, lines);
101
public void TestSelectedLinesReverse ()
103
TextEditorData data = new Mono.TextEditor.TextEditorData ();
111
SetSelection (data, true);
112
Assert.AreEqual (3, data.SelectedLines.Count ());
116
public void TestSelectedLinesCase2 ()
118
TextEditorData data = new Mono.TextEditor.TextEditorData ();
126
SetSelection (data, false);
127
Assert.AreEqual (3, data.SelectedLines.Count ());
131
public void TestSelectedLinesCase2Reverse ()
133
TextEditorData data = new Mono.TextEditor.TextEditorData ();
141
SetSelection (data, true);
142
Assert.AreEqual (3, data.SelectedLines.Count ());
146
public void TestSelectedLinesCase3 ()
148
TextEditorData data = new Mono.TextEditor.TextEditorData ();
156
SetSelection (data, false);
157
Assert.AreEqual (3, data.SelectedLines.Count ());
161
public void TestSelectedLinesCase3Reverse ()
163
TextEditorData data = new Mono.TextEditor.TextEditorData ();
171
SetSelection (data, true);
172
Assert.AreEqual (3, data.SelectedLines.Count ());
176
public void TestSetSelectedLines ()
178
TextEditorData data = new Mono.TextEditor.TextEditorData ();
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);