Skip to content

Commit

Permalink
Allow ignore spaces around declaration to work when `preserve singl…
Browse files Browse the repository at this point in the history
…e line statements` is set to false (#34959)

* Add tests for 31868

* interim fix

* Fix check for flag
  • Loading branch information
chborl authored May 2, 2019
1 parent a578d07 commit 76e66c4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected void RemoveSuppressOperation(

for (int i = 0; i < list.Count; i++)
{
if (list[i] != null && list[i].TextSpan.Start >= span.Start && list[i].TextSpan.End <= span.End)
if (list[i] != null && list[i].TextSpan.Start >= span.Start && list[i].TextSpan.End <= span.End && list[i].Option.HasFlag(SuppressOption.NoWrappingIfOnSingleLine))
{
list[i] = null;
}
Expand Down
51 changes: 51 additions & 0 deletions src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9162,5 +9162,56 @@ public unsafe class Test
}}",
changedOptionSet: changedOptionSet);
}

[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
[WorkItem(31868, "https://github.com/dotnet/roslyn/issues/31868")]
public async Task SpaceAroundDeclaration()
{
var changingOptions = new Dictionary<OptionKey, object>();
changingOptions.Add(CSharpFormattingOptions.SpacesIgnoreAroundVariableDeclaration, true);
await AssertFormatAsync(
@"
class Program
{
public void FixMyType()
{
var myint = 0;
}
}",
@"
class Program
{
public void FixMyType()
{
var myint = 0;
}
}", changedOptionSet: changingOptions);
}

[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
[WorkItem(31868, "https://github.com/dotnet/roslyn/issues/31868")]
public async Task SpaceAroundDeclarationAndPreserveSingleLine()
{
var changingOptions = new Dictionary<OptionKey, object>();
changingOptions.Add(CSharpFormattingOptions.SpacesIgnoreAroundVariableDeclaration, true);
changingOptions.Add(CSharpFormattingOptions.WrappingKeepStatementsOnSingleLine, false);
await AssertFormatAsync(
@"
class Program
{
public void FixMyType()
{
var myint = 0;
}
}",
@"
class Program
{
public void FixMyType()
{
var myint = 0;
}
}", changedOptionSet: changingOptions);
}
}
}

0 comments on commit 76e66c4

Please sign in to comment.