提交 93ffcd7b 编写于 作者: B Balaji Soundrarajan

Merge pull request #4379 from basoundr/3256NewLineForSwitchSection

Switch Section honors NewLineForBracesInControlBlock option
......@@ -21,7 +21,7 @@ private bool IsControlBlock(SyntaxNode node)
parent.Kind() == SyntaxKind.ForStatement || parent.Kind() == SyntaxKind.TryStatement ||
parent.Kind() == SyntaxKind.CatchClause || parent.Kind() == SyntaxKind.FinallyClause ||
parent.Kind() == SyntaxKind.LockStatement || parent.Kind() == SyntaxKind.CheckedStatement ||
parent.Kind() == SyntaxKind.UncheckedStatement));
parent.Kind() == SyntaxKind.UncheckedStatement || parent.Kind() == SyntaxKind.SwitchSection));
}
public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation<AdjustSpacesOperation> nextOperation)
......
......@@ -6320,5 +6320,78 @@ void Main()
}";
AssertFormat(expected, code);
}
[WorkItem(3256, "https://github.com/dotnet/roslyn/issues/3256")]
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
public void SwitchSectionHonorsNewLineForBracesinControlBlockOption_Default()
{
var code = @"class Program
{
public void foo()
{
int f = 1;
switch (f) {
case 1: {
// DO nothing
break;
}
}
}
}";
var expected = @"class Program
{
public void foo()
{
int f = 1;
switch (f)
{
case 1:
{
// DO nothing
break;
}
}
}
}";
AssertFormat(expected, code);
}
[WorkItem(3256, "https://github.com/dotnet/roslyn/issues/3256")]
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
public void SwitchSectionHonorsNewLineForBracesinControlBlockOption_NonDefault()
{
var changingOptions = new Dictionary<OptionKey, object>();
changingOptions.Add(CSharpFormattingOptions.NewLinesForBracesInControlBlocks, false);
var code = @"class Program
{
public void foo()
{
int f = 1;
switch (f)
{
case 1:
{
// DO nothing
break;
}
}
}
}";
var expected = @"class Program
{
public void foo()
{
int f = 1;
switch (f) {
case 1: {
// DO nothing
break;
}
}
}
}";
AssertFormat(expected, code, changedOptionSet: changingOptions);
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册