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

« back to all changes in this revision

Viewing changes to tests/UnitTests/MonoDevelop.CSharpBinding/TestBlankLineFormatting.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
// TastBlankLineFormatting.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 NUnit.Framework;
 
29
using MonoDevelop.Ide.Gui;
 
30
using MonoDevelop.Projects;
 
31
using MonoDevelop.Core;
 
32
using MonoDevelop.Ide.CodeCompletion;
 
33
using MonoDevelop.Ide.Gui.Content;
 
34
using MonoDevelop.Projects.Dom.Parser;
 
35
using MonoDevelop.CSharp.Parser;
 
36
using MonoDevelop.CSharp.Resolver;
 
37
using MonoDevelop.CSharp.Completion;
 
38
using Mono.TextEditor;
 
39
using MonoDevelop.CSharp.Formatting;
 
40
 
 
41
namespace MonoDevelop.CSharpBinding.FormattingTests
 
42
{
 
43
        [TestFixture()]
 
44
        public class TestBlankLineFormatting : UnitTests.TestBase
 
45
        {
 
46
                [Test()]
 
47
                public void TestBlankLinesAfterUsings ()
 
48
                {
 
49
                        TextEditorData data = new TextEditorData ();
 
50
                        data.Document.FileName = "a.cs";
 
51
                        data.Document.Text = @"using System;
 
52
using System.Text;
 
53
namespace Test
 
54
{
 
55
}";
 
56
                        
 
57
                        CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
 
58
                        policy.BlankLinesAfterUsings = 2;
 
59
                        var compilationUnit = new CSharpParser ().Parse (data);
 
60
                        compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
61
                        Assert.AreEqual (@"using System;
 
62
using System.Text;
 
63
 
 
64
 
 
65
namespace Test
 
66
{
 
67
}", data.Document.Text);
 
68
                        
 
69
                policy.BlankLinesAfterUsings = 0;
 
70
                compilationUnit = new CSharpParser ().Parse (data);
 
71
                compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
72
                Assert.AreEqual (@"using System;
 
73
using System.Text;
 
74
namespace Test
 
75
{
 
76
}", data.Document.Text);
 
77
                }
 
78
                
 
79
                [Test()]
 
80
                public void TestBlankLinesBeforeUsings ()
 
81
                {
 
82
                        TextEditorData data = new TextEditorData ();
 
83
                        data.Document.FileName = "a.cs";
 
84
                        data.Document.Text = @"using System;
 
85
using System.Text;
 
86
namespace Test
 
87
{
 
88
}";
 
89
                        
 
90
                        CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
 
91
                        policy.BlankLinesAfterUsings = 0;
 
92
                        policy.BlankLinesBeforeUsings = 2;
 
93
                        var compilationUnit = new CSharpParser ().Parse (data);
 
94
                        compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
95
                        Assert.AreEqual (@"
 
96
 
 
97
using System;
 
98
using System.Text;
 
99
namespace Test
 
100
{
 
101
}", data.Document.Text);
 
102
                        
 
103
                policy.BlankLinesBeforeUsings = 0;
 
104
                compilationUnit = new CSharpParser ().Parse (data);
 
105
                compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
106
                Assert.AreEqual (@"using System;
 
107
using System.Text;
 
108
namespace Test
 
109
{
 
110
}", data.Document.Text);
 
111
                }
 
112
                
 
113
                [Test()]
 
114
                public void TestBlankLinesBeforeFirstDeclaration ()
 
115
                {
 
116
                        TextEditorData data = new TextEditorData ();
 
117
                        data.Document.FileName = "a.cs";
 
118
                        data.Document.Text = @"namespace Test
 
119
{
 
120
        class Test
 
121
        {
 
122
        }
 
123
}";
 
124
                        
 
125
                        CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
 
126
                        policy.BlankLinesBeforeFirstDeclaration = 2;
 
127
                        var compilationUnit = new CSharpParser ().Parse (data);
 
128
                        compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
129
                        Assert.AreEqual (@"namespace Test
 
130
{
 
131
 
 
132
 
 
133
        class Test
 
134
        {
 
135
        }
 
136
}", data.Document.Text);
 
137
                        
 
138
                policy.BlankLinesBeforeFirstDeclaration = 0;
 
139
                compilationUnit = new CSharpParser ().Parse (data);
 
140
                compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
141
                Assert.AreEqual (@"namespace Test
 
142
{
 
143
        class Test
 
144
        {
 
145
        }
 
146
}", data.Document.Text);
 
147
                }
 
148
                
 
149
                
 
150
                [Test()]
 
151
                public void TestBlankLinesBetweenTypes ()
 
152
                {
 
153
                        TextEditorData data = new TextEditorData ();
 
154
                        data.Document.FileName = "a.cs";
 
155
                        data.Document.Text = @"namespace Test
 
156
{
 
157
        class Test1
 
158
        {
 
159
        }
 
160
        class Test2
 
161
        {
 
162
        }
 
163
        class Test3
 
164
        {
 
165
        }
 
166
}";
 
167
                        
 
168
                        CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
 
169
                        policy.BlankLinesBetweenTypes = 1;
 
170
                        var compilationUnit = new CSharpParser ().Parse (data);
 
171
                        compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
172
                        Assert.AreEqual (@"namespace Test
 
173
{
 
174
        class Test1
 
175
        {
 
176
        }
 
177
 
 
178
        class Test2
 
179
        {
 
180
        }
 
181
 
 
182
        class Test3
 
183
        {
 
184
        }
 
185
}", data.Document.Text);
 
186
                        
 
187
                policy.BlankLinesBetweenTypes = 0;
 
188
                compilationUnit = new CSharpParser ().Parse (data);
 
189
                compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
190
                Assert.AreEqual (@"namespace Test
 
191
{
 
192
        class Test1
 
193
        {
 
194
        }
 
195
        class Test2
 
196
        {
 
197
        }
 
198
        class Test3
 
199
        {
 
200
        }
 
201
}", data.Document.Text);
 
202
                }
 
203
                
 
204
                [Test()]
 
205
                public void TestBlankLinesBetweenFields ()
 
206
                {
 
207
                        TextEditorData data = new TextEditorData ();
 
208
                        data.Document.FileName = "a.cs";
 
209
                        data.Document.Text = @"class Test
 
210
{
 
211
        int a;
 
212
        int b;
 
213
        int c;
 
214
}";
 
215
                        
 
216
                        CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
 
217
                        policy.BlankLinesBetweenFields = 1;
 
218
                        var compilationUnit = new CSharpParser ().Parse (data);
 
219
                        compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
220
                        Assert.AreEqual (@"class Test
 
221
{
 
222
        int a;
 
223
 
 
224
        int b;
 
225
 
 
226
        int c;
 
227
}", data.Document.Text);
 
228
                        
 
229
                policy.BlankLinesBetweenFields = 0;
 
230
                compilationUnit = new CSharpParser ().Parse (data);
 
231
                compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
232
                Assert.AreEqual (@"class Test
 
233
{
 
234
        int a;
 
235
        int b;
 
236
        int c;
 
237
}", data.Document.Text);
 
238
                }
 
239
                
 
240
                [Test()]
 
241
                public void TestBlankLinesBetweenEventFields ()
 
242
                {
 
243
                        TextEditorData data = new TextEditorData ();
 
244
                        data.Document.FileName = "a.cs";
 
245
                        data.Document.Text = @"class Test
 
246
{
 
247
        public event EventHandler a;
 
248
        public event EventHandler b;
 
249
        public event EventHandler c;
 
250
}";
 
251
                        
 
252
                        CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
 
253
                        policy.BlankLinesBetweenEventFields = 1;
 
254
                        var compilationUnit = new CSharpParser ().Parse (data);
 
255
                        compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
256
                        Assert.AreEqual (@"class Test
 
257
{
 
258
        public event EventHandler a;
 
259
 
 
260
        public event EventHandler b;
 
261
 
 
262
        public event EventHandler c;
 
263
}", data.Document.Text);
 
264
                        
 
265
                policy.BlankLinesBetweenEventFields = 0;
 
266
                compilationUnit = new CSharpParser ().Parse (data);
 
267
                compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
268
                Assert.AreEqual (@"class Test
 
269
{
 
270
        public event EventHandler a;
 
271
        public event EventHandler b;
 
272
        public event EventHandler c;
 
273
}", data.Document.Text);
 
274
                }
 
275
                
 
276
                
 
277
                [Test()]
 
278
                public void TestBlankLinesBetweenMembers ()
 
279
                {
 
280
                        TextEditorData data = new TextEditorData ();
 
281
                        data.Document.FileName = "a.cs";
 
282
                        data.Document.Text = @"class Test
 
283
{
 
284
        void AMethod ()
 
285
        {
 
286
        }
 
287
        void BMethod ()
 
288
        {
 
289
        }
 
290
        void CMethod ()
 
291
        {
 
292
        }
 
293
}";
 
294
                        
 
295
                        CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
 
296
                        policy.BlankLinesBetweenMembers = 1;
 
297
                        var compilationUnit = new CSharpParser ().Parse (data);
 
298
                        compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
299
                        Assert.AreEqual (@"class Test
 
300
{
 
301
        void AMethod ()
 
302
        {
 
303
        }
 
304
 
 
305
        void BMethod ()
 
306
        {
 
307
        }
 
308
 
 
309
        void CMethod ()
 
310
        {
 
311
        }
 
312
}", data.Document.Text);
 
313
                        
 
314
                policy.BlankLinesBetweenMembers = 0;
 
315
                compilationUnit = new CSharpParser ().Parse (data);
 
316
                compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
 
317
                Assert.AreEqual (@"class Test
 
318
{
 
319
        void AMethod ()
 
320
        {
 
321
        }
 
322
        void BMethod ()
 
323
        {
 
324
        }
 
325
        void CMethod ()
 
326
        {
 
327
        }
 
328
}", data.Document.Text);
 
329
                }
 
330
                
 
331
                
 
332
                
 
333
        }
 
334
}
 
335