Skip to content

Commit

Permalink
GH-18 while statement formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
belav committed Mar 1, 2021
1 parent 14ef62a commit 7894443
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class ClassName
{
void MethodName()
{
while (true)
{
return;
}

while (true && false)
{
return;
}

while (
directoryInfo.Name != "Test" &&
directoryInfo.Parent != null &&
someLongCondition == "test")
{
directoryInfo = directoryInfo.Parent;
}
}
}
23 changes: 23 additions & 0 deletions Src/CSharpier.Tests/TestFiles/WhileStatement/WhileStatements.cst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class ClassName
{
void MethodName()
{
while (true)
{
return;
}

while (true && false)
{
return;
}

while (
directoryInfo.Name != "Test" &&
directoryInfo.Parent != null &&
someLongCondition == "test")
{
directoryInfo = directoryInfo.Parent;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace CSharpier.Tests.TestFiles
public class WhileStatementTests : BaseTest
{
[Test]
public void BasicWhileStatement()
public void WhileStatements()
{
this.RunTest("WhileStatement", "BasicWhileStatement");
this.RunTest("WhileStatement", "WhileStatements");
}
}
}
6 changes: 4 additions & 2 deletions Src/CSharpier/Printer/WhileStatementSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ public partial class Printer
private Doc PrintWhileStatementSyntax(WhileStatementSyntax node)
{
return Concat(
this.PrintExtraNewLines(node),
this.PrintSyntaxToken(node.WhileKeyword, " "),
this.PrintSyntaxToken(node.OpenParenToken),
this.Print(node.Condition),
Group(Indent(SoftLine,
this.Print(node.Condition))),
this.PrintSyntaxToken(node.CloseParenToken),
this.Print(node.Statement));
}
}
}
}

0 comments on commit 7894443

Please sign in to comment.