-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing regression on csharpier ignore that deleted empty lines
closes #879
- Loading branch information
Showing
4 changed files
with
115 additions
and
1 deletion.
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,75 @@ | ||
using NUnit.Framework; | ||
|
||
namespace CSharpier.Tests; | ||
|
||
using CSharpier.SyntaxPrinter; | ||
using FluentAssertions; | ||
|
||
[TestFixture] | ||
public class CSharpierIgnoreTests | ||
{ | ||
[Test] | ||
public void KeepLineBreaks() | ||
{ | ||
var testCode = | ||
@" | ||
1 | ||
2 | ||
"; | ||
|
||
var result = PrintWithoutFormatting(testCode); | ||
|
||
result.Should().Be(testCode); | ||
} | ||
|
||
[Test] | ||
public void TrimTrailing() | ||
{ | ||
var testCode = | ||
@"1 | ||
2"; | ||
|
||
var result = PrintWithoutFormatting(testCode); | ||
|
||
result | ||
.Should() | ||
.Be( | ||
@"1 | ||
2" | ||
); | ||
} | ||
|
||
[Test] | ||
public void FullProperty() | ||
{ | ||
var testCode = | ||
@" | ||
// csharpier-ignore | ||
public string Example | ||
{ | ||
get | ||
{ | ||
if (_example is not null) | ||
return _example; | ||
var number = Random.Shared.Next(); | ||
return _example = number.ToString(); | ||
} | ||
} | ||
"; | ||
|
||
var result = PrintWithoutFormatting(testCode); | ||
|
||
result.Should().Be(testCode); | ||
} | ||
|
||
private string PrintWithoutFormatting(string code) | ||
{ | ||
return CSharpierIgnore.PrintWithoutFormatting( | ||
code, | ||
new FormattingContext { LineEnding = Environment.NewLine } | ||
); | ||
} | ||
} |
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