2
// TestTypeLevelIndentation.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
29
using NUnit.Framework;
30
using ICSharpCode.NRefactory.CSharp;
32
namespace ICSharpCode.NRefactory.CSharp.FormattingTests
35
public class TestTypeLevelIndentation : TestBase
38
public void TestUsingDeclarations()
40
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
42
Test(policy, @" using Foo;", @"using Foo;");
46
public void TestUsingAliasDeclarations()
48
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
50
Test(policy, @" using Foo = Bar;", @"using Foo = Bar;");
54
public void TestClassIndentation ()
56
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
57
policy.ClassBraceStyle = BraceStyle.DoNotChange;
65
public void TestAttributeIndentation ()
67
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
68
policy.ClassBraceStyle = BraceStyle.DoNotChange;
80
public void TestClassIndentationInNamespaces ()
82
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
83
policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
84
policy.ClassBraceStyle = BraceStyle.DoNotChange;
87
@"namespace A { class Test {} }",
94
public void TestNoIndentationInNamespaces ()
96
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
97
policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
98
policy.ClassBraceStyle = BraceStyle.DoNotChange;
99
policy.IndentNamespaceBody = false;
102
@"namespace A { class Test {} }",
109
public void TestClassIndentationInNamespacesCase2 ()
111
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
112
policy.NamespaceBraceStyle = BraceStyle.NextLine;
113
policy.ClassBraceStyle = BraceStyle.NextLine;
114
policy.ConstructorBraceStyle = BraceStyle.NextLine;
119
namespace MonoDevelop.CSharp.Formatting {
120
public class FormattingProfileService {
121
public FormattingProfileService () {
127
namespace MonoDevelop.CSharp.Formatting
129
public class FormattingProfileService
131
public FormattingProfileService ()
139
public void TestIndentClassBody ()
141
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
142
policy.IndentClassBody = true;
152
policy.IndentClassBody = false;
165
public void TestIndentInterfaceBody ()
167
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
168
policy.IndentInterfaceBody = true;
178
policy.IndentInterfaceBody = false;
190
public void TestIndentStructBody ()
192
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
193
policy.IndentStructBody = true;
203
policy.IndentStructBody = false;
215
public void TestIndentEnumBody ()
217
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
218
policy.IndentEnumBody = true;
228
policy.IndentEnumBody = false;
240
public void TestIndentMethodBody ()
242
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
243
policy.IndentMethodBody = true;
262
policy.IndentMethodBody = false;
283
public void TestIndentMethodBodyOperatorCase ()
285
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
286
policy.IndentMethodBody = true;
288
var adapter = Test (policy,
291
static Test operator+(Test left, Test right)
299
static Test operator+ (Test left, Test right)
305
policy.IndentMethodBody = false;
306
Continue (policy, adapter, @"class Test
308
static Test operator+ (Test left, Test right)
317
public void TestIndentPropertyBody ()
319
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
320
policy.IndentPropertyBody = true;
322
var adapter = Test (policy,
337
policy.IndentPropertyBody = false;
339
Continue (policy, adapter,
350
public void TestIndentPropertyOneLine ()
352
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
353
policy.PropertyFormatting = PropertyFormatting.AllowOneLine;
354
policy.AllowPropertyGetBlockInline = true;
355
policy.AllowPropertySetBlockInline = true;
360
Test TestMe { get;set; }
364
Test TestMe { get; set; }
369
public void TestIndentPropertyOneLineCase2 ()
371
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
372
policy.PropertyFormatting = PropertyFormatting.AllowOneLine;
373
policy.AllowPropertyGetBlockInline = true;
374
policy.AllowPropertySetBlockInline = true;
379
Test TestMe { get { ; }set{;} }
383
Test TestMe { get { ; } set { ; } }
388
public void TestIndentPropertyBodyIndexerCase ()
390
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
391
policy.IndentPropertyBody = true;
393
var adapter = Test (policy,
416
policy.IndentPropertyBody = false;
417
Continue (policy, adapter,
432
public void TestPropertyAlignment ()
434
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
435
policy.PropertyFormatting = PropertyFormatting.AllowOneLine;
436
var adapter = Test (policy,
439
Test TestMe { get; set; }
443
Test TestMe { get; set; }
445
policy.PropertyFormatting = PropertyFormatting.ForceNewLine;
446
Continue (policy, adapter,
454
policy.PropertyFormatting = PropertyFormatting.ForceOneLine;
456
Continue (policy, adapter,
459
Test TestMe { get; set; }
465
public void TestIndentNamespaceBody ()
467
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
468
policy.ClassBraceStyle = BraceStyle.DoNotChange;
469
policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
470
policy.IndentNamespaceBody = true;
471
var adapter = Test (policy,
479
policy.IndentNamespaceBody = false;
480
Continue (policy, adapter,
488
public void TestMethodIndentation ()
490
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
491
policy.MethodBraceStyle = BraceStyle.DoNotChange;
496
MyType TestMethod () {}
500
MyType TestMethod () {}
505
public void TestPropertyIndentation ()
507
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
508
policy.PropertyBraceStyle = BraceStyle.DoNotChange;
513
public int Prop { get; set; }
516
public int Prop { get; set; }
521
public void TestPropertyIndentationCase2 ()
523
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
543
public void TestPropertyIndentationClosingBracketCorrection ()
545
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
550
public int Prop { get;
554
public int Prop { get; }
558
public void TestPropertyIndentationClosingBracketCorrection2 ()
560
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
576
public void TestPropertyCorrection()
578
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
579
policy.PropertyFormatting = PropertyFormatting.ForceNewLine;
583
public int Prop { get; private set; }
594
public void TestIndentEventBody ()
596
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
597
policy.IndentEventBody = true;
599
var adapter = Test (policy,
602
public event EventHandler TestMe {
613
public event EventHandler TestMe {
622
policy.IndentEventBody = false;
623
Continue (policy, adapter,
626
public event EventHandler TestMe {
639
/// Bug 9990 - Formatting a document on save splits event into 'e vent'
642
public void TestBug9990()
644
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
645
policy.PropertyFormatting = PropertyFormatting.ForceNewLine;
649
public event EventHandler UpdateStarted = delegate { }; public event EventHandler<UpdateFinishedEventArgs> UpdateFinished = delegate { };
652
public event EventHandler UpdateStarted = delegate { };
653
public event EventHandler<UpdateFinishedEventArgs> UpdateFinished = delegate { };