Skip to content

Commit

Permalink
Fixing bug with directive following a trailing comment getting extra …
Browse files Browse the repository at this point in the history
…indentation

closes #216
  • Loading branch information
belav committed May 26, 2021
1 parent 8e8f5b3 commit 4f5919c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Src/CSharpier.Tests/DocPrinterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,22 @@ public void TrailingComment_Does_Not_Get_Extra_Space_From_Line()
PrintedDocShouldBe(doc, $"x // comment{NewLine}y");
}

[Test]
public void TrailingComment_Does_Affect_Trim()
{
var doc = Doc.Concat(
Doc.TrailingComment("// trailing", CommentType.SingleLine),
Doc.HardLine,
Doc.Indent(
Doc.HardLineIfNoPreviousLineSkipBreakIfFirstInGroup,
Doc.Trim,
" #endregion"
)
);
var result = Print(doc);
result.Should().Be($" // trailing{NewLine} #endregion");
}

[Test]
public void HardLineIfNoPreviousLine_Should_Insert_Line_If_There_Is_Not_One()
{
Expand Down
4 changes: 4 additions & 0 deletions Src/CSharpier.Tests/TestFiles/Directives/Directives.cst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class ClassName { }

public class ClassName
{
#region Trailing comment does not indent more than it should #endregion
private int x; // trailing comment
#endregion

void MethodWithOnlyDisabled()
{
#if DEBUG
Expand Down
1 change: 1 addition & 0 deletions Src/CSharpier/DocPrinter/DocPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ void Push(Doc doc, PrintMode printMode, Indent indent)
break;
case Trim:
currentWidth -= TrimOutput(output);
newLineNextStringValue = false;
break;
case Group group:
switch (command.Mode)
Expand Down

0 comments on commit 4f5919c

Please sign in to comment.