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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.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
// 
 
2
// TestTypeLevelIndentation.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.IO;
 
29
using NUnit.Framework;
 
30
using ICSharpCode.NRefactory.CSharp;
 
31
 
 
32
namespace ICSharpCode.NRefactory.CSharp.FormattingTests
 
33
{
 
34
        [TestFixture()]
 
35
        public class TestTypeLevelIndentation : TestBase
 
36
        {
 
37
                [Test]
 
38
                public void TestUsingDeclarations()
 
39
                {
 
40
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
 
41
        
 
42
                        Test(policy, @"         using Foo;", @"using Foo;");
 
43
                }
 
44
 
 
45
                [Test]
 
46
                public void TestUsingAliasDeclarations()
 
47
                {
 
48
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
 
49
        
 
50
                        Test(policy, @"         using Foo = Bar;", @"using Foo = Bar;");
 
51
                }
 
52
 
 
53
                [Test]
 
54
                public void TestClassIndentation ()
 
55
                {
 
56
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
57
                        policy.ClassBraceStyle = BraceStyle.DoNotChange;
 
58
                        
 
59
                        Test (policy,
 
60
@"                      class Test {}",
 
61
@"class Test {}");
 
62
                }
 
63
                
 
64
                [Test]
 
65
                public void TestAttributeIndentation ()
 
66
                {
 
67
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
68
                        policy.ClassBraceStyle = BraceStyle.DoNotChange;
 
69
                        
 
70
                        Test (policy,
 
71
@"                                      [Attribute1]
 
72
                [Attribute2()]
 
73
          class Test {}",
 
74
@"[Attribute1]
 
75
[Attribute2()]
 
76
class Test {}");
 
77
                }
 
78
                
 
79
                [Test]
 
80
                public void TestClassIndentationInNamespaces ()
 
81
                {
 
82
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
83
                        policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
 
84
                        policy.ClassBraceStyle = BraceStyle.DoNotChange;
 
85
                        
 
86
                        Test (policy,
 
87
@"namespace A { class Test {} }",
 
88
@"namespace A {
 
89
        class Test {}
 
90
}");
 
91
                }
 
92
                
 
93
                [Test]
 
94
                public void TestNoIndentationInNamespaces ()
 
95
                {
 
96
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
97
                        policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
 
98
                        policy.ClassBraceStyle = BraceStyle.DoNotChange;
 
99
                        policy.IndentNamespaceBody = false;
 
100
                        
 
101
                        Test (policy,
 
102
@"namespace A { class Test {} }",
 
103
@"namespace A {
 
104
class Test {}
 
105
}");
 
106
                }
 
107
                
 
108
                [Test]
 
109
                public void TestClassIndentationInNamespacesCase2 ()
 
110
                {
 
111
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
112
                        policy.NamespaceBraceStyle = BraceStyle.NextLine;
 
113
                        policy.ClassBraceStyle = BraceStyle.NextLine;
 
114
                        policy.ConstructorBraceStyle = BraceStyle.NextLine;
 
115
                        
 
116
                        Test (policy,
 
117
@"using System;
 
118
 
 
119
namespace MonoDevelop.CSharp.Formatting {
 
120
        public class FormattingProfileService {
 
121
                public FormattingProfileService () {
 
122
                }
 
123
        }
 
124
}",
 
125
@"using System;
 
126
 
 
127
namespace MonoDevelop.CSharp.Formatting
 
128
{
 
129
        public class FormattingProfileService
 
130
        {
 
131
                public FormattingProfileService ()
 
132
                {
 
133
                }
 
134
        }
 
135
}");
 
136
                }
 
137
                
 
138
                [Test]
 
139
                public void TestIndentClassBody ()
 
140
                {
 
141
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
142
                        policy.IndentClassBody = true;
 
143
                        Test (policy,
 
144
@"class Test
 
145
{
 
146
                                Test a;
 
147
}", @"class Test
 
148
{
 
149
        Test a;
 
150
}");
 
151
                        
 
152
                        policy.IndentClassBody = false;
 
153
                        Test (policy,
 
154
@"class Test
 
155
{
 
156
        Test a;
 
157
}",
 
158
@"class Test
 
159
{
 
160
Test a;
 
161
}");
 
162
                }
 
163
                
 
164
                [Test]
 
165
                public void TestIndentInterfaceBody ()
 
166
                {
 
167
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
168
                        policy.IndentInterfaceBody = true;
 
169
                        
 
170
                        Test (policy,
 
171
@"interface Test
 
172
{
 
173
                                Test Foo ();
 
174
}", @"interface Test
 
175
{
 
176
        Test Foo ();
 
177
}");
 
178
                        policy.IndentInterfaceBody = false;
 
179
                        Test (policy,
 
180
@"interface Test
 
181
{
 
182
        Test Foo ();
 
183
}", @"interface Test
 
184
{
 
185
Test Foo ();
 
186
}");
 
187
                }
 
188
                
 
189
                [Test]
 
190
                public void TestIndentStructBody ()
 
191
                {
 
192
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
193
                        policy.IndentStructBody = true;
 
194
                        
 
195
                        Test (policy,
 
196
@"struct Test
 
197
{
 
198
                                Test Foo ();
 
199
}", @"struct Test
 
200
{
 
201
        Test Foo ();
 
202
}");
 
203
                        policy.IndentStructBody = false;
 
204
                        Test (policy,
 
205
@"struct Test
 
206
{
 
207
        Test Foo ();
 
208
}", @"struct Test
 
209
{
 
210
Test Foo ();
 
211
}");
 
212
                }
 
213
                
 
214
                [Test]
 
215
                public void TestIndentEnumBody ()
 
216
                {
 
217
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
218
                        policy.IndentEnumBody = true;
 
219
                        
 
220
                        Test (policy,
 
221
@"enum Test
 
222
{
 
223
                                A
 
224
}", @"enum Test
 
225
{
 
226
        A
 
227
}");
 
228
                        policy.IndentEnumBody = false;
 
229
                        Test (policy,
 
230
@"enum Test
 
231
{
 
232
        A
 
233
}", @"enum Test
 
234
{
 
235
A
 
236
}");
 
237
                }
 
238
                
 
239
                [Test]
 
240
                public void TestIndentMethodBody ()
 
241
                {
 
242
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
243
                        policy.IndentMethodBody = true;
 
244
                        
 
245
                        Test (policy,
 
246
@"class Test
 
247
{
 
248
        Test Foo ()
 
249
        {
 
250
;
 
251
                                                                ;
 
252
        }
 
253
}",
 
254
@"class Test
 
255
{
 
256
        Test Foo ()
 
257
        {
 
258
                ;
 
259
                ;
 
260
        }
 
261
}");
 
262
                        policy.IndentMethodBody = false;
 
263
                        Test (policy,
 
264
@"class Test
 
265
{
 
266
        Test Foo ()
 
267
        {
 
268
                ;
 
269
                ;
 
270
        }
 
271
}",
 
272
@"class Test
 
273
{
 
274
        Test Foo ()
 
275
        {
 
276
        ;
 
277
        ;
 
278
        }
 
279
}");
 
280
                }
 
281
                
 
282
                [Test]
 
283
                public void TestIndentMethodBodyOperatorCase ()
 
284
                {
 
285
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
286
                        policy.IndentMethodBody = true;
 
287
 
 
288
                        var adapter = Test (policy,
 
289
@"class Test
 
290
{
 
291
        static Test operator+(Test left, Test right)
 
292
        {
 
293
;
 
294
                                                                ;
 
295
        }
 
296
}",
 
297
@"class Test
 
298
{
 
299
        static Test operator+ (Test left, Test right)
 
300
        {
 
301
                ;
 
302
                ;
 
303
        }
 
304
}");
 
305
                        policy.IndentMethodBody = false;
 
306
                        Continue (policy, adapter, @"class Test
 
307
{
 
308
        static Test operator+ (Test left, Test right)
 
309
        {
 
310
        ;
 
311
        ;
 
312
        }
 
313
}");
 
314
                }
 
315
                
 
316
                [Test]
 
317
                public void TestIndentPropertyBody ()
 
318
                {
 
319
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
320
                        policy.IndentPropertyBody = true;
 
321
                        
 
322
                        var adapter = Test (policy,
 
323
@"class Test
 
324
{
 
325
        Test TestMe {
 
326
                        get;
 
327
set;
 
328
        }
 
329
}",
 
330
@"class Test
 
331
{
 
332
        Test TestMe {
 
333
                get;
 
334
                set;
 
335
        }
 
336
}");
 
337
                        policy.IndentPropertyBody = false;
 
338
                        
 
339
                        Continue (policy, adapter,
 
340
@"class Test
 
341
{
 
342
        Test TestMe {
 
343
        get;
 
344
        set;
 
345
        }
 
346
}");
 
347
                }
 
348
                
 
349
                [Test]
 
350
                public void TestIndentPropertyOneLine ()
 
351
                {
 
352
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
353
                        policy.PropertyFormatting = PropertyFormatting.AllowOneLine;
 
354
                        policy.AllowPropertyGetBlockInline = true;
 
355
                        policy.AllowPropertySetBlockInline = true;
 
356
                        
 
357
                        Test (policy,
 
358
@"class Test
 
359
{
 
360
        Test TestMe {      get;set;                  }
 
361
}",
 
362
@"class Test
 
363
{
 
364
        Test TestMe { get; set; }
 
365
}");
 
366
                }
 
367
                
 
368
                [Test]
 
369
                public void TestIndentPropertyOneLineCase2 ()
 
370
                {
 
371
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
372
                        policy.PropertyFormatting = PropertyFormatting.AllowOneLine;
 
373
                        policy.AllowPropertyGetBlockInline = true;
 
374
                        policy.AllowPropertySetBlockInline = true;
 
375
                        
 
376
                        Test (policy,
 
377
@"class Test
 
378
{
 
379
        Test TestMe {      get { ; }set{;}                  }
 
380
}",
 
381
@"class Test
 
382
{
 
383
        Test TestMe { get { ; } set { ; } }
 
384
}");
 
385
                }
 
386
                
 
387
                [Test]
 
388
                public void TestIndentPropertyBodyIndexerCase ()
 
389
                {
 
390
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
391
                        policy.IndentPropertyBody = true;
 
392
                        
 
393
                        var adapter = Test (policy,
 
394
@"class Test
 
395
{
 
396
        Test this[int a] {
 
397
                        get {
 
398
        return null;
 
399
}
 
400
set {
 
401
        ;
 
402
}
 
403
        }
 
404
}",
 
405
@"class Test
 
406
{
 
407
        Test this [int a] {
 
408
                get {
 
409
                        return null;
 
410
                }
 
411
                set {
 
412
                        ;
 
413
                }
 
414
        }
 
415
}");
 
416
                        policy.IndentPropertyBody = false;
 
417
                        Continue (policy, adapter,
 
418
@"class Test
 
419
{
 
420
        Test this [int a] {
 
421
        get {
 
422
                return null;
 
423
        }
 
424
        set {
 
425
                ;
 
426
        }
 
427
        }
 
428
}");
 
429
                }
 
430
                
 
431
                [Test]
 
432
                public void TestPropertyAlignment ()
 
433
                {
 
434
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
435
                        policy.PropertyFormatting = PropertyFormatting.AllowOneLine;
 
436
                        var adapter = Test (policy,
 
437
@"class Test
 
438
{
 
439
        Test TestMe { get; set; }
 
440
}",
 
441
@"class Test
 
442
{
 
443
        Test TestMe { get; set; }
 
444
}");
 
445
                        policy.PropertyFormatting = PropertyFormatting.ForceNewLine;
 
446
                        Continue (policy, adapter,
 
447
@"class Test
 
448
{
 
449
        Test TestMe {
 
450
                get;
 
451
                set;
 
452
        }
 
453
}");
 
454
                        policy.PropertyFormatting = PropertyFormatting.ForceOneLine;
 
455
                        
 
456
                        Continue (policy, adapter,
 
457
@"class Test
 
458
{
 
459
        Test TestMe { get; set; }
 
460
}");
 
461
                }
 
462
 
 
463
                
 
464
                [Test]
 
465
                public void TestIndentNamespaceBody ()
 
466
                {
 
467
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
468
                        policy.ClassBraceStyle = BraceStyle.DoNotChange;
 
469
                        policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
 
470
                        policy.IndentNamespaceBody = true;
 
471
                        var adapter = Test (policy,
 
472
@"                      namespace Test {
 
473
class FooBar {}
 
474
                }",
 
475
@"namespace Test {
 
476
        class FooBar {}
 
477
}");
 
478
                        
 
479
                        policy.IndentNamespaceBody = false;
 
480
                        Continue (policy, adapter,
 
481
@"namespace Test {
 
482
class FooBar {}
 
483
}");
 
484
                }
 
485
                
 
486
                
 
487
                [Test]
 
488
                public void TestMethodIndentation ()
 
489
                {
 
490
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
491
                        policy.MethodBraceStyle = BraceStyle.DoNotChange;
 
492
                        
 
493
                        Test (policy,
 
494
@"class Test
 
495
{
 
496
MyType TestMethod () {}
 
497
}",
 
498
@"class Test
 
499
{
 
500
        MyType TestMethod () {}
 
501
}");
 
502
                }
 
503
                
 
504
                [Test]
 
505
                public void TestPropertyIndentation ()
 
506
                {
 
507
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
508
                        policy.PropertyBraceStyle = BraceStyle.DoNotChange;
 
509
                        
 
510
                        Test (policy, 
 
511
@"class Test
 
512
{
 
513
                                public int Prop { get; set; }
 
514
}",@"class Test
 
515
{
 
516
        public int Prop { get; set; }
 
517
}");
 
518
                }
 
519
                
 
520
                [Test]
 
521
                public void TestPropertyIndentationCase2 ()
 
522
                {
 
523
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
524
                        
 
525
                        Test (policy, 
 
526
@"class Test
 
527
{
 
528
                                public int Prop {
 
529
 get;
 
530
set;
 
531
}
 
532
}",
 
533
@"class Test
 
534
{
 
535
        public int Prop {
 
536
                get;
 
537
                set;
 
538
        }
 
539
}");
 
540
                }
 
541
 
 
542
                [Test]
 
543
                public void TestPropertyIndentationClosingBracketCorrection ()
 
544
                {
 
545
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
546
 
 
547
                        Test (policy, 
 
548
@"class Test
 
549
{
 
550
                                public int Prop { get;
 
551
                                }
 
552
}",@"class Test
 
553
{
 
554
        public int Prop { get; }
 
555
}");
 
556
                }
 
557
                [Test]
 
558
                public void TestPropertyIndentationClosingBracketCorrection2 ()
 
559
                {
 
560
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
561
 
 
562
                        Test (policy, 
 
563
@"class Test
 
564
{
 
565
                                public int Prop {
 
566
                                        get;}
 
567
}",@"class Test
 
568
{
 
569
        public int Prop {
 
570
                get;
 
571
        }
 
572
}");
 
573
                }
 
574
 
 
575
                [Test]
 
576
                public void TestPropertyCorrection()
 
577
                {
 
578
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
 
579
                        policy.PropertyFormatting = PropertyFormatting.ForceNewLine;
 
580
                        Test(policy, 
 
581
                             @"class Test
 
582
{
 
583
                                public int Prop { get;          private set; }
 
584
}", @"class Test
 
585
{
 
586
        public int Prop {
 
587
                get;
 
588
                private set;
 
589
        }
 
590
}");
 
591
                }
 
592
 
 
593
                [Test]
 
594
                public void TestIndentEventBody ()
 
595
                {
 
596
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
 
597
                        policy.IndentEventBody = true;
 
598
                        
 
599
                        var adapter = Test (policy, 
 
600
@"class Test
 
601
{
 
602
        public event EventHandler TestMe {
 
603
                                                                add {
 
604
                                                        ;
 
605
                                                }
 
606
remove {
 
607
        ;
 
608
}
 
609
        }
 
610
}",
 
611
@"class Test
 
612
{
 
613
        public event EventHandler TestMe {
 
614
                add {
 
615
                        ;
 
616
                }
 
617
                remove {
 
618
                        ;
 
619
                }
 
620
        }
 
621
}");
 
622
                        policy.IndentEventBody = false;
 
623
                        Continue (policy, adapter,
 
624
@"class Test
 
625
{
 
626
        public event EventHandler TestMe {
 
627
        add {
 
628
                ;
 
629
        }
 
630
        remove {
 
631
                ;
 
632
        }
 
633
        }
 
634
}");
 
635
                }
 
636
 
 
637
                
 
638
                /// <summary>
 
639
                /// Bug 9990 - Formatting a document on save splits event into 'e vent'
 
640
                /// </summary>
 
641
                [Test]
 
642
                public void TestBug9990()
 
643
                {
 
644
                        CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
 
645
                        policy.PropertyFormatting = PropertyFormatting.ForceNewLine;
 
646
                        Test(policy, 
 
647
                             @"class Test
 
648
{
 
649
                public event EventHandler UpdateStarted = delegate { }; public event EventHandler<UpdateFinishedEventArgs> UpdateFinished = delegate { };
 
650
}", @"class Test
 
651
{
 
652
        public event EventHandler UpdateStarted = delegate { };
 
653
        public event EventHandler<UpdateFinishedEventArgs> UpdateFinished = delegate { };
 
654
}");
 
655
                }
 
656
        }
 
657
}