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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/IndentationTests/IndentationTests.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
using System;
 
2
using System.IO;
 
3
using NUnit.Framework;
 
4
using ICSharpCode.NRefactory.CSharp;
 
5
using ICSharpCode.NRefactory.Editor;
 
6
using System.Text;
 
7
 
 
8
namespace ICSharpCode.NRefactory.CSharp.Indentation
 
9
{
 
10
        [TestFixture]
 
11
        public class IndentationTests
 
12
        {
 
13
                static CSharpIndentEngine CreateEngine (string text)
 
14
                {
 
15
                        var policy = FormattingOptionsFactory.CreateMono ();
 
16
 
 
17
                        var sb = new StringBuilder();
 
18
                        int offset = 0;
 
19
                        for (int i = 0; i < text.Length; i++) {
 
20
                                var ch = text [i];
 
21
                                if (ch == '$') {
 
22
                                        offset = i;
 
23
                                        continue;
 
24
                                }
 
25
                                sb.Append (ch);
 
26
                        }
 
27
                        var document = new ReadOnlyDocument(sb.ToString ());
 
28
 
 
29
                        var options = new TextEditorOptions();
 
30
 
 
31
                        var result = new CSharpIndentEngine(document, options, policy);
 
32
                        result.UpdateToOffset(offset);
 
33
                        return result;
 
34
                }
 
35
 
 
36
                [Test]
 
37
                public void TestNamespaceIndent ()
 
38
                {
 
39
                        var indent = CreateEngine("namespace Foo {$");
 
40
                        Assert.AreEqual("", indent.ThisLineIndent);
 
41
                        Assert.AreEqual("\t", indent.NewLineIndent);
 
42
                }
 
43
 
 
44
                [Test]
 
45
                public void TestPreProcessorDirectives ()
 
46
                {
 
47
                        var indent = CreateEngine(@"
 
48
namespace Foo {
 
49
        class Foo {
 
50
#if NOTTHERE
 
51
        {
 
52
#endif
 
53
                $");
 
54
                        Assert.AreEqual("\t\t", indent.ThisLineIndent);
 
55
                        Assert.AreEqual("\t\t", indent.NewLineIndent);
 
56
                }
 
57
 
 
58
                [Test]
 
59
                public void TestPreProcessorDirectives2 ()
 
60
                {
 
61
                        var indent = CreateEngine(@"
 
62
namespace Foo {
 
63
        class Foo {
 
64
#if NOTTHERE || true
 
65
        {
 
66
#endif
 
67
                $");
 
68
                        Assert.AreEqual("\t\t\t", indent.ThisLineIndent);
 
69
                        Assert.AreEqual("\t\t\t", indent.NewLineIndent);
 
70
                }
 
71
 
 
72
                [Test]
 
73
                public void TestIf ()
 
74
                {
 
75
                        var indent = CreateEngine(@"
 
76
class Foo {
 
77
        void Test ()
 
78
        {
 
79
                if (true)$");
 
80
                        Assert.AreEqual("\t\t", indent.ThisLineIndent);
 
81
                        Assert.AreEqual("\t\t\t", indent.NewLineIndent);
 
82
                }
 
83
 
 
84
                [Test]
 
85
                public void TestFor ()
 
86
                {
 
87
                        var indent = CreateEngine(@"
 
88
class Foo {
 
89
        void Test ()
 
90
        {
 
91
                for (;;)$");
 
92
                        Assert.AreEqual("\t\t", indent.ThisLineIndent);
 
93
                        Assert.AreEqual("\t\t\t", indent.NewLineIndent);
 
94
                }
 
95
 
 
96
                [Test]
 
97
                public void TestForEach ()
 
98
                {
 
99
                        var indent = CreateEngine(@"
 
100
class Foo {
 
101
        void Test ()
 
102
        {
 
103
                foreach (;;)$");
 
104
                        Assert.AreEqual("\t\t", indent.ThisLineIndent);
 
105
                        Assert.AreEqual("\t\t\t", indent.NewLineIndent);
 
106
                }
 
107
 
 
108
 
 
109
                [Test]
 
110
                public void TestDo ()
 
111
                {
 
112
                        var indent = CreateEngine(@"
 
113
class Foo {
 
114
        void Test ()
 
115
        {
 
116
                do
 
117
$");
 
118
                        Assert.AreEqual("\t\t\t", indent.ThisLineIndent);
 
119
                }
 
120
 
 
121
                [Test]
 
122
                public void TestNestedDo ()
 
123
                {
 
124
                        var indent = CreateEngine(@"
 
125
class Foo {
 
126
        void Test ()
 
127
        {
 
128
                do do
 
129
$");
 
130
                        Assert.AreEqual("\t\t\t\t", indent.ThisLineIndent);
 
131
                }
 
132
 
 
133
                [Test]
 
134
                public void TestNestedDoContinuationSetBack ()
 
135
                {
 
136
                        var indent = CreateEngine(@"
 
137
class Foo {
 
138
        void Test ()
 
139
        {
 
140
                do do do
 
141
foo();$");
 
142
                        Assert.AreEqual("\t\t\t\t\t", indent.ThisLineIndent);
 
143
                        Assert.AreEqual("\t\t\t\t", indent.NewLineIndent);
 
144
                }
 
145
 
 
146
                [Test]
 
147
                public void TestWhile ()
 
148
                {
 
149
                        var indent = CreateEngine(@"
 
150
class Foo {
 
151
        void Test ()
 
152
        {
 
153
                while(true)$");
 
154
                        Assert.AreEqual("\t\t", indent.ThisLineIndent);
 
155
                        Assert.AreEqual("\t\t\t", indent.NewLineIndent);
 
156
                }
 
157
 
 
158
                [Test]
 
159
                public void TestParameters ()
 
160
                {
 
161
                        var indent = CreateEngine(@"
 
162
class Foo {
 
163
        void Test ()
 
164
        {
 
165
                Foo(true,$");
 
166
                        Assert.AreEqual("\t\t", indent.ThisLineIndent);
 
167
                        Assert.AreEqual("\t\t   ", indent.NewLineIndent);
 
168
                }
 
169
                [Test]
 
170
                public void TestThisLineIndentAfterCurlyBrace ()
 
171
                {
 
172
                        var indent = CreateEngine(@"
 
173
class Foo {
 
174
        void Test ()
 
175
        {
 
176
        }$");
 
177
                        Assert.AreEqual("\t", indent.ThisLineIndent);
 
178
                        Assert.AreEqual("\t", indent.NewLineIndent);
 
179
                }
 
180
 
 
181
                [Test]
 
182
                public void TestThisLineIndentAfterCurlyBraceCase2 ()
 
183
                {
 
184
                        var indent = CreateEngine(@"
 
185
class Foo {
 
186
        void Test ()
 
187
        {}$");
 
188
                        Assert.AreEqual("\t", indent.ThisLineIndent);
 
189
                        Assert.AreEqual("\t", indent.NewLineIndent);
 
190
                }
 
191
 
 
192
                [Test]
 
193
                public void TestParametersCase2 ()
 
194
                {
 
195
                        var indent = CreateEngine(@"
 
196
class Foo {
 
197
        void Test ()
 
198
        {
 
199
                Foo($");
 
200
                        Assert.AreEqual("\t\t", indent.ThisLineIndent);
 
201
                        Assert.AreEqual("\t\t\t", indent.NewLineIndent);
 
202
                }
 
203
        }
 
204
}
 
205