~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to tests/UnitTests/Mono.TextEditor.Tests/InsertionModeTests.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
Import upstream version 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// InsertionModeTests.cs
 
3
//  
 
4
// Author:
 
5
//       Mike Krüger <mkrueger@novell.com>
 
6
// 
 
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.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
 
 
27
using System;
 
28
using System.Collections.Generic;
 
29
using NUnit.Framework;
 
30
 
 
31
namespace Mono.TextEditor.Tests
 
32
{
 
33
        [TestFixture()]
 
34
        public class InsertionModeTests
 
35
        {
 
36
                [TestFixtureSetUp] 
 
37
                public void SetUp()
 
38
                {
 
39
                        Gtk.Application.Init ();
 
40
                }
 
41
                
 
42
                string CreateInsertionPoint (string input, string text, NewLineInsertion before, NewLineInsertion after)
 
43
                {
 
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;
 
51
                        
 
52
                }
 
53
                
 
54
                [Test()]
 
55
                public void TestInsertionPointClassStart ()
 
56
                {
 
57
                        string test = CreateInsertionPoint (@"class Test
 
58
{
 
59
$       void TestMethod ()
 
60
        {
 
61
        }
 
62
}", "\tint a;", NewLineInsertion.None, NewLineInsertion.BlankLine);
 
63
                        Assert.AreEqual (@"class Test
 
64
{
 
65
        int a;
 
66
 
 
67
        void TestMethod ()
 
68
        {
 
69
        }
 
70
}", test);
 
71
                }
 
72
                
 
73
                [Test()]
 
74
                public void TestInsertionPointClassEnd ()
 
75
                {
 
76
                        string test = CreateInsertionPoint (@"class Test
 
77
{
 
78
        void TestMethod ()
 
79
        {
 
80
        }
 
81
$}", "\tint a;", NewLineInsertion.Eol, NewLineInsertion.Eol);
 
82
                        Assert.AreEqual (@"class Test
 
83
{
 
84
        void TestMethod ()
 
85
        {
 
86
        }
 
87
 
 
88
        int a;
 
89
}", test);
 
90
                }
 
91
                
 
92
                [Test()]
 
93
                public void TestInsertionPointClassMiddle ()
 
94
                {
 
95
                        string test = CreateInsertionPoint (@"class Test
 
96
{
 
97
        void TestMethod1 ()
 
98
        {
 
99
        }
 
100
$       void TestMethod2 ()
 
101
        {
 
102
        }
 
103
}", "\tint a;", NewLineInsertion.Eol, NewLineInsertion.BlankLine);
 
104
                        Assert.AreEqual (@"class Test
 
105
{
 
106
        void TestMethod1 ()
 
107
        {
 
108
        }
 
109
 
 
110
        int a;
 
111
 
 
112
        void TestMethod2 ()
 
113
        {
 
114
        }
 
115
}", test);
 
116
                }
 
117
                
 
118
                /// <summary>
 
119
                /// Bug 683011 - Implement interface may insert region in the wrong spot
 
120
                /// </summary>
 
121
                [Test()]
 
122
                public void TestBug683011 ()
 
123
                {
 
124
                        string test = CreateInsertionPoint (@"class Test
 
125
{$}", "\tint a;", NewLineInsertion.Eol, NewLineInsertion.Eol);
 
126
                        Assert.AreEqual (@"class Test
 
127
{
 
128
        int a;
 
129
}", test);
 
130
                }
 
131
                
 
132
        }
 
133
}
 
134