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

« back to all changes in this revision

Viewing changes to tests/UnitTests/Mono.TextEditor.Tests/SmartIndentModeTests.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
 
// SmartInsertModeTests.cs
3
 
//  
4
 
// Author:
5
 
//       Mike Krüger <mkrueger@xamarin.com>
6
 
// 
7
 
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.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
 
using System;
27
 
using System.Collections.Generic;
28
 
using NUnit.Framework;
29
 
using System.Linq;
30
 
 
31
 
namespace Mono.TextEditor.Tests
32
 
{
33
 
        [TestFixture()]
34
 
        public class SmartIndentModeTests
35
 
        {
36
 
                internal readonly static IIndentationTracker IndentTracker = new TestIndentTracker ();
37
 
 
38
 
                internal class TestIndentTracker : IIndentationTracker
39
 
                {
40
 
                        string indentString;
41
 
 
42
 
                        public TestIndentTracker (string indentString = "\t\t")
43
 
                        {
44
 
                                this.indentString = indentString;
45
 
                        }
46
 
                        
47
 
                        #region IIndentationTracker implementation
48
 
                        public string GetIndentationString (int offset)
49
 
                        {
50
 
                                return indentString;
51
 
                        }
52
 
 
53
 
                        public string GetIndentationString (int lineNumber, int column)
54
 
                        {
55
 
                                return indentString;
56
 
                        }
57
 
 
58
 
                        public int GetVirtualIndentationColumn (int offset)
59
 
                        {
60
 
                                return indentString.Length + 1;
61
 
                        }
62
 
 
63
 
                        public int GetVirtualIndentationColumn (int lineNumber, int column)
64
 
                        {
65
 
                                return indentString.Length + 1;
66
 
                        }
67
 
                        #endregion
68
 
                }
69
 
 
70
 
                TextEditorData CreateData ()
71
 
                {
72
 
                        var data = new TextEditorData ();
73
 
                        data.IndentationTracker = IndentTracker;
74
 
                        data.Options.IndentStyle = IndentStyle.Smart;
75
 
                        return data;
76
 
                }
77
 
 
78
 
                [Test()]
79
 
                public void TestIndentNewLine ()
80
 
                {
81
 
                        var data = CreateData ();
82
 
                        data.Document.Text = "\n\n\n";
83
 
                        data.Caret.Offset = data.Document.GetLine (2).Offset;
84
 
                        
85
 
                        MiscActions.InsertNewLine (data);
86
 
                        
87
 
                        Assert.AreEqual ("\n\n\t\t\n\n", data.Document.Text);
88
 
                        Assert.AreEqual (data.Document.GetLine (3).Offset + 2, data.Caret.Offset);
89
 
                }
90
 
 
91
 
                [Test()]
92
 
                public void TestLineEndBehavior ()
93
 
                {
94
 
                        var data = CreateData ();
95
 
                        data.Document.Text = "\n\n\n";
96
 
                        data.Caret.Offset = data.Document.GetLine (2).Offset;
97
 
 
98
 
                        CaretMoveActions.LineEnd (data);
99
 
                        
100
 
                        Assert.AreEqual ("\n\n\n", data.Document.Text);
101
 
                        Assert.AreEqual (data.Document.GetLine (2).Offset, data.Caret.Offset);
102
 
                }
103
 
 
104
 
                [Test()]
105
 
                public void TestDesiredColumnCaretDown ()
106
 
                {
107
 
                        var data = CreateData ();
108
 
                        data.Document.Text = "12345\n\n12345\n";
109
 
                        data.Caret.Column = 4;
110
 
                        Assert.AreEqual (4, data.Caret.DesiredColumn);
111
 
 
112
 
                        CaretMoveActions.Down (data);
113
 
                        Assert.AreEqual (1, data.Caret.Column);
114
 
                        CaretMoveActions.Down (data);
115
 
                        
116
 
                        Assert.AreEqual (4, data.Caret.Column);
117
 
                        Assert.AreEqual (4, data.Caret.DesiredColumn);
118
 
                }
119
 
 
120
 
                [Test()]
121
 
                public void TestDesiredColumnCaretUp ()
122
 
                {
123
 
                        var data = CreateData ();
124
 
                        data.Document.Text = "12345\n\n12345\n";
125
 
                        data.Caret.Line = 3;
126
 
                        data.Caret.Column = 4;
127
 
                        Assert.AreEqual (4, data.Caret.DesiredColumn);
128
 
 
129
 
                        CaretMoveActions.Up (data);
130
 
                        Assert.AreEqual (1, data.Caret.Column);
131
 
                        CaretMoveActions.Up (data);
132
 
                        
133
 
                        Assert.AreEqual (4, data.Caret.Column);
134
 
                        Assert.AreEqual (4, data.Caret.DesiredColumn);
135
 
                }
136
 
 
137
 
                [Test()]
138
 
                public void TestCaretRightBehavior ()
139
 
                {
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);
146
 
                }
147
 
        }
148
 
}
149