1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
// Test.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//
using System;
using NUnit.Framework;
namespace Mono.TextEditor.Tests.Actions
{
[TestFixture()]
public class InsertTabTests : TextEditorTestBase
{
public static TextEditorData Create (string input, bool reverse)
{
TextEditorData data = new Mono.TextEditor.TextEditorData ();
int offset1 = input.IndexOf ('[');
int offset2 = input.IndexOf (']');
var selection = new TextSegment (offset1, offset2 - offset1 - 1);
data.Text = input.Substring (0, offset1) + input.Substring (offset1 + 1, (offset2 - offset1) - 1) + input.Substring (offset2 + 1);
if (reverse) {
data.Caret.Offset = selection.Offset;
data.SelectionAnchor = selection.EndOffset;
data.ExtendSelectionTo (selection.Offset);
} else {
data.Caret.Offset = selection.EndOffset;
data.SelectionAnchor = selection.Offset;
data.ExtendSelectionTo (selection.EndOffset);
}
return data;
}
public static void Check (TextEditorData data, string output, bool reverse)
{
int offset1 = output.IndexOf ('[');
int offset2 = output.IndexOf (']');
string expected = output.Substring (0, offset1) + output.Substring (offset1 + 1, (offset2 - offset1) - 1) + output.Substring (offset2 + 1);
offset2--;
Assert.AreEqual (expected, data.Text);
Assert.AreEqual (data.OffsetToLocation (reverse ? offset2 : offset1), data.MainSelection.Anchor);
Assert.AreEqual (data.OffsetToLocation (reverse ? offset1 : offset2), data.MainSelection.Lead);
}
[TestCase(false)]
[TestCase(true)]
public void TestInsertTabLine (bool reverse)
{
var data = Create (@"123456789
123[456789
123d456789
123]456789
123456789
123456789", reverse);
MiscActions.InsertTab (data);
Check (data, @"123456789
123[456789
123d456789
123]456789
123456789
123456789", reverse);
}
[TestCase(false)]
[TestCase(true)]
public void TestInsertTabLineCase2 (bool reverse)
{
var data = Create (@"123d456789
123[456789
123d456789
]123456789
123456789
123456789", reverse);
MiscActions.InsertTab (data);
Check (data, @"123d456789
123[456789
123d456789
]123456789
123456789
123456789", reverse);
}
[TestCase(false)]
[TestCase(true)]
public void TestInsertTabLineCase3 (bool reverse)
{
var data = Create (@"123d456789
[123456789
123d456789
123]456789
123456789
123456789", reverse);
MiscActions.InsertTab (data);
Check (data, @"123d456789
[123456789
123d456789
123]456789
123456789
123456789", reverse);
}
/// <summary>
/// Bug 5223 - Tab to indent with tab-to-spaces does not adjust selection correctly
/// </summary>
[Test]
public void TestBug5223 ()
{
var data = Create (@" 123d456789
123$<-456789
123d456789
->123456789
123456789
123456789", new TextEditorOptions () { TabsToSpaces = true } );
MiscActions.InsertTab (data);
Check (data, @" 123d456789
123$<-456789
123d456789
->123456789
123456789
123456789");
}
/// <summary>
/// Bug 5373 - Indenting selected block should not indent blank lines in it
/// </summary>
[Test]
public void TestBug5373 ()
{
var data = Create (@" 123d456789
123$<-456789
123d456789
->123456789", new TextEditorOptions () { IndentStyle = IndentStyle.Virtual } );
data.IndentationTracker = SmartIndentModeTests.IndentTracker;
MiscActions.InsertTab (data);
Check (data, @" 123d456789
123$<-456789
123d456789
->123456789");
}
}
}
|