2
// SmartInsertModeTests.cs
5
// Mike Krüger <mkrueger@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.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
27
using System.Collections.Generic;
28
using NUnit.Framework;
31
namespace Mono.TextEditor.Tests
34
public class SmartIndentModeTests
36
internal readonly static IIndentationTracker IndentTracker = new TestIndentTracker ();
38
internal class TestIndentTracker : IIndentationTracker
42
public TestIndentTracker (string indentString = "\t\t")
44
this.indentString = indentString;
47
#region IIndentationTracker implementation
48
public string GetIndentationString (int offset)
53
public string GetIndentationString (int lineNumber, int column)
58
public int GetVirtualIndentationColumn (int offset)
60
return indentString.Length + 1;
63
public int GetVirtualIndentationColumn (int lineNumber, int column)
65
return indentString.Length + 1;
70
TextEditorData CreateData ()
72
var data = new TextEditorData ();
73
data.IndentationTracker = IndentTracker;
74
data.Options.IndentStyle = IndentStyle.Smart;
79
public void TestIndentNewLine ()
81
var data = CreateData ();
82
data.Document.Text = "\n\n\n";
83
data.Caret.Offset = data.Document.GetLine (2).Offset;
85
MiscActions.InsertNewLine (data);
87
Assert.AreEqual ("\n\n\t\t\n\n", data.Document.Text);
88
Assert.AreEqual (data.Document.GetLine (3).Offset + 2, data.Caret.Offset);
92
public void TestLineEndBehavior ()
94
var data = CreateData ();
95
data.Document.Text = "\n\n\n";
96
data.Caret.Offset = data.Document.GetLine (2).Offset;
98
CaretMoveActions.LineEnd (data);
100
Assert.AreEqual ("\n\n\n", data.Document.Text);
101
Assert.AreEqual (data.Document.GetLine (2).Offset, data.Caret.Offset);
105
public void TestDesiredColumnCaretDown ()
107
var data = CreateData ();
108
data.Document.Text = "12345\n\n12345\n";
109
data.Caret.Column = 4;
110
Assert.AreEqual (4, data.Caret.DesiredColumn);
112
CaretMoveActions.Down (data);
113
Assert.AreEqual (1, data.Caret.Column);
114
CaretMoveActions.Down (data);
116
Assert.AreEqual (4, data.Caret.Column);
117
Assert.AreEqual (4, data.Caret.DesiredColumn);
121
public void TestDesiredColumnCaretUp ()
123
var data = CreateData ();
124
data.Document.Text = "12345\n\n12345\n";
126
data.Caret.Column = 4;
127
Assert.AreEqual (4, data.Caret.DesiredColumn);
129
CaretMoveActions.Up (data);
130
Assert.AreEqual (1, data.Caret.Column);
131
CaretMoveActions.Up (data);
133
Assert.AreEqual (4, data.Caret.Column);
134
Assert.AreEqual (4, data.Caret.DesiredColumn);
138
public void TestCaretRightBehavior ()
140
var data = CreateData ();
141
data.Document.Text = "\n\n\n";
142
CaretMoveActions.Right (data);
143
Assert.AreEqual (new DocumentLocation (2, 1), data.Caret.Location);
144
CaretMoveActions.Right (data);
145
Assert.AreEqual (new DocumentLocation (3, 1), data.Caret.Location);