Skip to content

Commit

Permalink
Keep empty arrays on a single line in destructured output
Browse files Browse the repository at this point in the history
  • Loading branch information
daningalla committed Aug 13, 2022
1 parent f7a5487 commit c95b563
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Destructuring/DestructuringWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ private void WriteStartSection(string c)
if (_options.WriteIndented)
{
_buffer.Margin += _indentation;
_buffer.WriteLine();
}
}

Expand Down Expand Up @@ -114,6 +113,11 @@ private bool WriteNode(string? key, object? value, int maxCount)
return false;
}

if (_innerCount == 1 && _options.WriteIndented)
{
_buffer.WriteLine();
}

if (_innerCount > 1)
{
_buffer.Write(", ");
Expand Down
14 changes: 13 additions & 1 deletion test/Destructuring/DestructuringWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,19 @@ public void WriteEmptyArrayIndentedRendersExpectedContent()

DestructuringWriter.Write(buffer, profile, Array.Empty<string>());

buffer.ToString().ShouldBe("[[" + Environment.NewLine + "]]");
buffer.ToString().ShouldBe("[[]]");
}

[Fact]
public void WriteEmptyDictionaryIndentedRendersExpectedContent()
{
var buffer = new WriteBuffer(Substitute.For<IConsoleWriter>());
var profile = new LogLevelProfile(LogLevel.Information);
profile.ConfigureOptions<DestructuringOptions>(opt => opt.WriteIndented = true);

DestructuringWriter.Write(buffer, profile, new Dictionary<string, string>());

buffer.ToString().ShouldBe("{}");
}

[Fact]
Expand Down

0 comments on commit c95b563

Please sign in to comment.