2
// InsertionModeTests.cs
5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.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
28
using System.Collections.Generic;
29
using NUnit.Framework;
31
namespace Mono.TextEditor.Tests
34
public class InsertionModeTests
39
Gtk.Application.Init ();
42
string CreateInsertionPoint (string input, string text, NewLineInsertion before, NewLineInsertion after)
44
int idx = input.IndexOf ('$');
45
Assert.Greater (idx, -1);
46
TextEditor editor = new TextEditor ();
47
editor.Document.Text = input.Substring (0, idx) + input.Substring (idx + 1);
48
InsertionPoint point = new InsertionPoint (editor.Document.OffsetToLocation (idx), before, after);
49
point.Insert (editor.GetTextEditorData (), text);
50
return editor.Document.Text;
55
public void TestInsertionPointClassStart ()
57
string test = CreateInsertionPoint (@"class Test
62
}", "\tint a;", NewLineInsertion.None, NewLineInsertion.BlankLine);
63
Assert.AreEqual (@"class Test
74
public void TestInsertionPointClassEnd ()
76
string test = CreateInsertionPoint (@"class Test
81
$}", "\tint a;", NewLineInsertion.Eol, NewLineInsertion.Eol);
82
Assert.AreEqual (@"class Test
93
public void TestInsertionPointClassMiddle ()
95
string test = CreateInsertionPoint (@"class Test
100
$ void TestMethod2 ()
103
}", "\tint a;", NewLineInsertion.Eol, NewLineInsertion.BlankLine);
104
Assert.AreEqual (@"class Test
119
/// Bug 683011 - Implement interface may insert region in the wrong spot
122
public void TestBug683011 ()
124
string test = CreateInsertionPoint (@"class Test
125
{$}", "\tint a;", NewLineInsertion.Eol, NewLineInsertion.Eol);
126
Assert.AreEqual (@"class Test