Skip to content

Commit

Permalink
Adding ifBreak doc type
Browse files Browse the repository at this point in the history
changing if, while, foreach and using to use SpaceBrace formatting.
closes #34
  • Loading branch information
belav committed Apr 10, 2021
1 parent 759dd33 commit d68c5e1
Show file tree
Hide file tree
Showing 29 changed files with 430 additions and 210 deletions.
67 changes: 65 additions & 2 deletions Src/CSharpier.Tests/DocPrinterTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using FluentAssertions;
using NUnit.Framework;

Expand Down Expand Up @@ -275,6 +276,67 @@ public void ForceFlat_Should_Be_Included_In_Fits_Logic_Of_Printer()
);
}

[Test]
public void IfBreak_Should_Print_Flat_Contents()
{
var doc = Docs.Group(Docs.IfBreak("break", "flat"));

var result = this.Print(doc);

result.Should().Be("flat");
}

[Test]
public void IfBreak_Should_Print_Break_Contents()
{
var doc = Docs.Group(Docs.HardLine, Docs.IfBreak("break", "flat"));

var result = this.Print(doc);

result.Should().Be("break");
}

[Test]
public void IfBreak_Should_Print_Break_Contents_When_Group_Does_Not_Fit()
{
var doc = Docs.Group(
"another",
Docs.Line,
Docs.IfBreak("break", "flat")
);

var result = this.Print(doc, 10);

result.Should().Be($"another{NewLine}break");
}

[Test]
public void IfBreak_Should_Print_Flat_Contents_When_GroupId_Does_Not_Break()
{
var doc = Docs.Concat(
Docs.GroupWithId("1", "1"),
Docs.IfBreak("break", "flat", "1")
);

var result = this.Print(doc);

result.Should().Be("1flat");
}

[Test]
public void IfBreak_Should_Print_Break_Contents_When_GroupId_Breaks()
{
var doc = Docs.Concat(
"1",
Docs.GroupWithId("hl", Docs.HardLine),
Docs.IfBreak("break", "flat", "hl")
);

var result = this.Print(doc);

result.Should().Be($"1{NewLine}break");
}

[Test]
public void Scratch()
{
Expand All @@ -283,9 +345,10 @@ public void Scratch()
result.Should().Be("");
}

private string Print(Doc doc)
private string Print(Doc doc, int width = 80)
{
return DocPrinter.Print(doc, new Options()).TrimEnd('\r', '\n');
return DocPrinter.Print(doc, new Options { Width = width })
.TrimEnd('\r', '\n');
}

public static Doc HardLine => Printer.HardLine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace CSharpier.Tests.TestFiles
public class DoStatementTests : BaseTest
{
[Test]
public void BasicDoStatement()
public void DoStatements()
{
this.RunTest("DoStatement", "BasicDoStatement");
this.RunTest("DoStatement", "DoStatements");
}
}
}
14 changes: 0 additions & 14 deletions Src/CSharpier.Tests/TestFiles/ElseStatement/BasicElse.cst

This file was deleted.

14 changes: 0 additions & 14 deletions Src/CSharpier.Tests/TestFiles/ElseStatement/ElseIf.cst

This file was deleted.

34 changes: 34 additions & 0 deletions Src/CSharpier.Tests/TestFiles/ElseStatement/ElseStatements.cst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
public class ClassName
{
public void MethodName()
{
if (true)
{
DoIf();
}
else
{
DoElse();
}

if (true)
{
DoIf();
}
else if (false)
{
DoElse();
}

if (true)
{
DoIf();
}
else if (
jklasdfklalsdkfjlkasdflkaslkjfjsdkf
|| kljadsfklaskldflkjasdfklaskjdfjklasdfjlkasdfjlkasdf
) {
DoElse();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ namespace CSharpier.Tests.TestFiles
public class ElseStatementTests : BaseTest
{
[Test]
public void BasicElse()
public void ElseStatements()
{
this.RunTest("ElseStatement", "BasicElse");
}
[Test]
public void ElseIf()
{
this.RunTest("ElseStatement", "ElseIf");
this.RunTest("ElseStatement", "ElseStatements");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class ClassName

foreach (var x in this.SomeMethodCall()
.SomeChainedCall()
.AnotherChainedCall())
{
.AnotherChainedCall()
) {
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace CSharpier.Tests.TestFiles
public class ForEachStatementTests : BaseTest
{
[Test]
public void BasicForEachStatement()
public void ForEachStatements()
{
this.RunTest("ForEachStatement", "BasicForEachStatement");
this.RunTest("ForEachStatement", "ForEachStatements");
}
}
}
9 changes: 7 additions & 2 deletions Src/CSharpier.Tests/TestFiles/IfStatement/IfStatements.cst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ public class ClassName
{
public void MethodName()
{
if (true) { }
if (true)
{
return;
}

if (true == false) { }

Expand All @@ -13,7 +16,9 @@ public class ClassName
&& longerStatementName
&& evenLongerStatementName
&& superLongStatementName
) { }
) {
return;
}

if (true)
DoSoemthing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class ClassName
return;
}

if (MethodKind is not (MethodKind.Ordinary or MethodKind.LocalFunction))
{
if (
MethodKind is not (MethodKind.Ordinary or MethodKind.LocalFunction)
) {
return;
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

38 changes: 38 additions & 0 deletions Src/CSharpier.Tests/TestFiles/UsingStatement/UsingStatements.cst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class ClassName
{
void MethodName()
{
using (var x = BeginScope())
{
return;
}

await using (var x = BeginScope())
{
return;
}

using (var x = BeginScope())
using (var y = BeginScope())
{
return;
}

using (BeginScope())
{
return;
}

using (BeginScope())
return;

using (BeginScope()
.LongerMethod()
.MakeThisThingChain()
.MaybeNow()
.OrNow()
) {
return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,9 @@ namespace CSharpier.Tests.TestFiles
public class UsingStatementTests : BaseTest
{
[Test]
public void BasicUsingStatement()
public void UsingStatements()
{
this.RunTest("UsingStatement", "BasicUsingStatement");
}
[Test]
public void NestedUsingStatement()
{
this.RunTest("UsingStatement", "NestedUsingStatement");
}
[Test]
public void UsingStatementWithExpression()
{
this.RunTest("UsingStatement", "UsingStatementWithExpression");
}
[Test]
public void UsingStatementWithNoBody()
{
this.RunTest("UsingStatement", "UsingStatementWithNoBody");
this.RunTest("UsingStatement", "UsingStatements");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ClassName
while (
directoryInfo.Name != "Test"
&& directoryInfo.Parent != null
&& someLongCondition == "test")
{
&& someLongCondition == "test"
) {
directoryInfo = directoryInfo.Parent;
}
}
Expand Down
Loading

0 comments on commit d68c5e1

Please sign in to comment.