-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
closes #40 - empty line handling
- Loading branch information
Showing
15 changed files
with
547 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace CSharpier.Tests | ||
{ | ||
public class DocUtilitiesTests | ||
{ | ||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Handle_Empty_List() | ||
{ | ||
var doc = new List<Doc>(); | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
doc.Should().BeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Remove_Null() | ||
{ | ||
var doc = new List<Doc> { Docs.Null }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
doc.Should().BeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Not_Remove_Simple_HardLine() | ||
{ | ||
var doc = new List<Doc> { Docs.HardLine }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
doc.Should().HaveCount(1); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Remove_Simple_Double_HardLine() | ||
{ | ||
var doc = new List<Doc> { Docs.HardLine, Docs.HardLine }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
doc.Should().HaveCount(1); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Not_Remove_Concated_HardLine() | ||
{ | ||
var concat = Docs.Concat(Docs.HardLine); | ||
var doc = new List<Doc> { concat }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
concat.Parts.Should().BeEquivalentTo(Docs.HardLine); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Remove_Concated_HardLine() | ||
{ | ||
var concat = Docs.Concat(Docs.HardLine, Docs.HardLine); | ||
var doc = new List<Doc> { concat }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
concat.Parts.Should().ContainSingle(); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Not_Remove_Deep_Concated_HardLine() | ||
{ | ||
var concat = Docs.Concat(Docs.HardLine); | ||
var doc = new List<Doc> { Docs.Concat(concat) }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
concat.Parts.Should().BeEquivalentTo(Docs.HardLine); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Remove_Deep_Concated_HardLine() | ||
{ | ||
var concat = Docs.Concat(Docs.HardLine, Docs.HardLine); | ||
var doc = new List<Doc> { Docs.Concat(concat) }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
concat.Parts.Should().ContainSingle(); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Remove_Single_HardLine() | ||
{ | ||
var concat = Docs.Concat( | ||
Docs.HardLine, | ||
Docs.HardLine, | ||
Docs.HardLine | ||
); | ||
var doc = new List<Doc> { Docs.Concat(concat) }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
concat.Parts.Should().HaveCount(2); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Not_Remove_Indented_HardLine() | ||
{ | ||
var indent = Docs.Indent(Docs.HardLine); | ||
var doc = new List<Doc> { indent }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
indent.Contents.Should().BeEquivalentTo(Docs.HardLine); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Remove_Indented_HardLine() | ||
{ | ||
var indent = Docs.Indent(Docs.HardLine); | ||
var doc = new List<Doc> { Docs.HardLine, indent }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
indent.Contents.Should().Be(Docs.Null); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Not_Remove_Deep_Indented_HardLine() | ||
{ | ||
var indent = Docs.Indent(Docs.HardLine); | ||
var doc = new List<Doc> { Docs.Indent(indent) }; | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
indent.Contents.Should().BeEquivalentTo(Docs.HardLine); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Remove_Grouped_Double_HardLine() | ||
{ | ||
var contents = new List<Doc> { Docs.HardLine, Docs.HardLine }; | ||
var doc = Docs.Group(contents); | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
contents.Should().ContainSingle(); | ||
} | ||
|
||
[Test] | ||
public void RemoveInitialDoubleHardLine_Should_Only_Remove_Initial_HardLines() | ||
{ | ||
var doc = Docs.Concat("1", Docs.HardLine, Docs.HardLine); | ||
|
||
DocUtilities.RemoveInitialDoubleHardLine(doc); | ||
|
||
doc.Should() | ||
.BeEquivalentTo(Docs.Concat("1", Docs.HardLine, Docs.HardLine)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ static // trailing | |
class // trailing | ||
ClassName2 { } | ||
|
||
|
||
// this | ||
public | ||
// is | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace Namespace | ||
{ | ||
|
||
public class RemovesLineBefore { } | ||
|
||
|
||
public class RemovesDoubledLines { } | ||
|
||
public class RemoveTrailingLine { } | ||
|
||
} | ||
|
||
public class ClassName | ||
{ | ||
|
||
public int RemoveLineBefore; | ||
|
||
|
||
public int RemoveDoubleLines; | ||
|
||
public void MethodName() | ||
{ | ||
|
||
var removeLineBefore = 1; | ||
|
||
|
||
var removeDoubleLines = 2; | ||
|
||
var removeTrailingLine = 3; | ||
|
||
} | ||
|
||
public int RemoveTrailingLine; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
Src/CSharpier.Tests/TestFiles/EmptyLines/EmptyLines.expected.cst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Namespace | ||
{ | ||
public class RemovesLineBefore { } | ||
|
||
public class RemovesDoubledLines { } | ||
|
||
public class RemoveTrailingLine { } | ||
} | ||
|
||
public class ClassName | ||
{ | ||
public int RemoveLineBefore; | ||
|
||
public int RemoveDoubleLines; | ||
|
||
public void MethodName() | ||
{ | ||
var removeLineBefore = 1; | ||
|
||
var removeDoubleLines = 2; | ||
|
||
var removeTrailingLine = 3; | ||
} | ||
|
||
public int RemoveTrailingLine; | ||
} |
14 changes: 14 additions & 0 deletions
14
Src/CSharpier.Tests/TestFiles/EmptyLines/_EmptyLineTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using CSharpier.Tests.TestFileTests; | ||
using NUnit.Framework; | ||
|
||
namespace CSharpier.Tests.TestFiles | ||
{ | ||
public class EmptyLineTests : BaseTest | ||
{ | ||
[Test] | ||
public void EmptyLines() | ||
{ | ||
this.RunTest("EmptyLines", "EmptyLines"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.