5
// Mike KrĆ¼ger <mkrueger@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.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 TestWrapping : TestBase
38
public void TestInitializerWrapAlways()
40
var policy = FormattingOptionsFactory.CreateMono();
41
policy.ArrayInitializerWrapping = Wrapping.WrapAlways;
43
Test(policy, @"class Test
47
var foo = new [] { 1, 2, 3 };
64
public void TestInitializerDoNotWrap()
66
var policy = FormattingOptionsFactory.CreateMono();
67
policy.ArrayInitializerWrapping = Wrapping.DoNotWrap;
84
var foo = new [] { 1, 2, 3 };
90
public void TestInitializerBraceStyle()
92
var policy = FormattingOptionsFactory.CreateMono();
93
policy.ArrayInitializerWrapping = Wrapping.WrapAlways;
94
policy.ArrayInitializerBraceStyle = BraceStyle.NextLine;
96
Test(policy, @"class Test
122
public void TestChainedMethodCallWrapping()
124
var policy = FormattingOptionsFactory.CreateMono();
125
policy.ChainedMethodCallWrapping = Wrapping.WrapAlways;
127
Test(policy, @"class Test
131
Foo ().Bar (). Zoom();
146
public void TestChainedMethodCallDoNotWrapWrapping()
148
var policy = FormattingOptionsFactory.CreateMono();
149
policy.ChainedMethodCallWrapping = Wrapping.DoNotWrap;
151
Test(policy, @"class Test
164
Foo ().Bar ().Zoom ();
170
public void TestMethodCallArgumentWrapping()
172
var policy = FormattingOptionsFactory.CreateMono();
173
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways;
174
policy.NewLineAferMethodCallOpenParentheses = NewLinePlacement.NewLine;
175
policy.MethodCallClosingParenthesesOnNewLine = NewLinePlacement.NewLine;
177
Test(policy, @"class Test
198
public void TestMethodCallArgumentNoNewLineWrapping()
200
var policy = FormattingOptionsFactory.CreateMono();
201
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways;
202
policy.NewLineAferMethodCallOpenParentheses = NewLinePlacement.SameLine;
203
policy.MethodCallClosingParenthesesOnNewLine = NewLinePlacement.SameLine;
205
Test(policy, @"class Test
225
public void TestMethodCallArgumentDoNotWrapWrapping()
227
var policy = FormattingOptionsFactory.CreateMono();
228
policy.MethodCallArgumentWrapping = Wrapping.DoNotWrap;
229
policy.NewLineAferMethodCallOpenParentheses = NewLinePlacement.NewLine;
230
policy.MethodCallClosingParenthesesOnNewLine = NewLinePlacement.NewLine;
232
Test(policy, @"class Test
254
public void TestIndexerCallArgumentNoNewLineWrapping()
256
var policy = FormattingOptionsFactory.CreateMono();
257
policy.IndexerArgumentWrapping = Wrapping.WrapAlways;
258
policy.NewLineAferIndexerOpenBracket = NewLinePlacement.NewLine;
259
policy.IndexerClosingBracketOnNewLine = NewLinePlacement.NewLine;
261
Test(policy, @"class Test
265
FooBar [1, 2, 3] = 5;
282
public void TestObjectCreationArgumentNoNewLineWrapping()
284
var policy = FormattingOptionsFactory.CreateMono();
285
policy.MethodCallArgumentWrapping = Wrapping.WrapAlways;
286
policy.NewLineAferMethodCallOpenParentheses = NewLinePlacement.NewLine;
287
policy.MethodCallClosingParenthesesOnNewLine = NewLinePlacement.NewLine;
289
Test(policy, @"class Test
293
new FooBar (1, 2, 3);
310
public void TestMethodDeclarationParameterNewLineWrapping()
312
var policy = FormattingOptionsFactory.CreateMono();
313
policy.MethodDeclarationParameterWrapping = Wrapping.WrapAlways;
314
policy.NewLineAferMethodDeclarationOpenParentheses = NewLinePlacement.NewLine;
315
policy.MethodDeclarationClosingParenthesesOnNewLine = NewLinePlacement.NewLine;
317
Test(policy, @"class Test
319
void TestMe (int i, int j, int k)
336
public void TestMethodDeclarationParameterDoNotChangeCase1()
338
var policy = FormattingOptionsFactory.CreateMono();
339
policy.MethodDeclarationParameterWrapping = Wrapping.DoNotChange;
341
Test(policy, @"class Test
364
public void TestMethodDeclarationParameterDoNotChangeCase2()
366
var policy = FormattingOptionsFactory.CreateMono();
367
policy.MethodDeclarationParameterWrapping = Wrapping.DoNotChange;
369
Test(policy, @"class Test
390
public void TestMethodDeclarationParameterDoNotChangeCase3()
392
var policy = FormattingOptionsFactory.CreateMono();
393
policy.MethodDeclarationParameterWrapping = Wrapping.DoNotChange;
395
Test(policy, @"class Test
414
public void TestOperatorDeclarationParameterNewLineWrapping()
416
var policy = FormattingOptionsFactory.CreateMono();
417
policy.MethodDeclarationParameterWrapping = Wrapping.WrapAlways;
418
policy.NewLineAferMethodDeclarationOpenParentheses = NewLinePlacement.NewLine;
419
policy.MethodDeclarationClosingParenthesesOnNewLine = NewLinePlacement.SameLine;
421
Test(policy, @"class Test
423
public static Test operator + (Test a, Test b)
430
public static Test operator + (
440
public void TestConstructorDeclarationParameterNewLineWrapping()
442
var policy = FormattingOptionsFactory.CreateMono();
443
policy.MethodDeclarationParameterWrapping = Wrapping.WrapAlways;
444
policy.NewLineAferMethodDeclarationOpenParentheses = NewLinePlacement.NewLine;
445
policy.MethodDeclarationClosingParenthesesOnNewLine = NewLinePlacement.NewLine;
447
Test(policy, @"class Test
449
Test (int i, int j, int k)
466
public void TestIndexerDeclarationParameterNewLineWrapping()
468
var policy = FormattingOptionsFactory.CreateMono();
469
policy.IndexerDeclarationParameterWrapping = Wrapping.WrapAlways;
470
policy.NewLineAferIndexerDeclarationOpenBracket = NewLinePlacement.NewLine;
471
policy.IndexerDeclarationClosingBracketOnNewLine = NewLinePlacement.NewLine;
472
Test(policy, @"class Test
474
int this [int i, int j, int k] {
493
public void TestIndexerDeclarationAlignment()
495
var policy = FormattingOptionsFactory.CreateMono();
496
policy.AlignToFirstIndexerDeclarationParameter = true;
497
Test(policy, @"class Test
518
public void TestMethodCallArgumentWrappingDoNotChangeCase1()
520
var policy = FormattingOptionsFactory.CreateMono();
521
policy.MethodCallArgumentWrapping = Wrapping.DoNotChange;
522
policy.NewLineAferMethodCallOpenParentheses = NewLinePlacement.NewLine;
523
policy.MethodCallClosingParenthesesOnNewLine = NewLinePlacement.NewLine;
525
Test(policy, @"class Test
550
public void TestMethodCallArgumentWrappingDoNotChangeCase2()
552
var policy = FormattingOptionsFactory.CreateMono();
553
policy.MethodCallArgumentWrapping = Wrapping.DoNotChange;
554
policy.NewLineAferMethodCallOpenParentheses = NewLinePlacement.NewLine;
555
policy.MethodCallClosingParenthesesOnNewLine = NewLinePlacement.NewLine;
557
Test(policy, @"class Test
580
public void TestMethodCallArgumentWrappingDoNotChangeCase3()
582
var policy = FormattingOptionsFactory.CreateMono();
583
policy.MethodCallArgumentWrapping = Wrapping.DoNotChange;
584
policy.NewLineAferMethodCallOpenParentheses = NewLinePlacement.NewLine;
585
policy.MethodCallClosingParenthesesOnNewLine = NewLinePlacement.NewLine;
587
Test(policy, @"class Test
608
public void TestDoNotTouchMethodDeclarationCase1 ()
610
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
612
var adapter = Test (policy, @"class Test
614
int Foo (int i, double d, Action a)
621
int Foo (int i, double d, Action a)
625
}", FormattingMode.Intrusive);
629
public void TestNoBlankLinesBetweenEndBraceAndEndParenthesis ()
631
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
632
policy.BlankLinesBetweenMembers = 1;
634
var adapter = Test (policy, @"class Test
636
int Foo (int i, double d, Action a)
649
int Foo (int i, double d, Action a)
659
}", FormattingMode.Intrusive);
663
public void TestMethodCallDoNotWrapCorrectionNoAlignment()
665
var policy = FormattingOptionsFactory.CreateMono();
666
policy.MethodCallArgumentWrapping = Wrapping.DoNotChange;
667
policy.NewLineAferMethodCallOpenParentheses = NewLinePlacement.DoNotCare;
668
policy.MethodCallClosingParenthesesOnNewLine = NewLinePlacement.DoNotCare;
669
policy.AlignToFirstMethodCallArgument = false;
670
Test(policy, @"class Test
694
public void TestMethodCallNoAlignmentHasNoEffectInNewLineCase()
696
var policy = FormattingOptionsFactory.CreateMono();
697
policy.MethodCallArgumentWrapping = Wrapping.DoNotChange;
698
policy.AlignToFirstMethodCallArgument = true;
699
Test(policy, @"class Test
724
public void TestMethodDeclarationNoAlignmentHasNoEffectInNewLineCase()
726
var policy = FormattingOptionsFactory.CreateMono();
727
policy.MethodCallArgumentWrapping = Wrapping.DoNotChange;
728
policy.AlignToFirstMethodDeclarationParameter = true;
729
Test(policy, @"class Test
748
public void TestMethodDeclarationAlignment()
750
var policy = FormattingOptionsFactory.CreateMono();
751
policy.AlignToFirstMethodDeclarationParameter = true;
752
Test(policy, @"class Test
754
void TestMe (int test,
761
void TestMe (int test,
769
public void TestMethodDeclarationNoAlignmentHasNoEffectInNewLine2()
771
var policy = FormattingOptionsFactory.CreateMono();
772
policy.MethodDeclarationParameterWrapping = Wrapping.WrapAlways;
773
policy.AlignToFirstMethodDeclarationParameter = false;
774
Test(policy, @"class Test
776
public void LongMethodCallInMultiple (
777
int test,string foo,double bar)
783
public void LongMethodCallInMultiple (
793
public void TestMethodDeclarationDoNotWrapCorrectionNoAlignment()
795
var policy = FormattingOptionsFactory.CreateMono();
796
policy.MethodDeclarationParameterWrapping = Wrapping.DoNotChange;
797
policy.NewLineAferMethodDeclarationOpenParentheses = NewLinePlacement.DoNotCare;
798
policy.MethodDeclarationClosingParenthesesOnNewLine = NewLinePlacement.DoNotCare;
799
policy.AlignToFirstMethodDeclarationParameter = false;
800
Test(policy, @"class Test
802
void TestMe (int bar,
810
void TestMe (int bar,