Skip to content

Commit

Permalink
Print commas at the end of the line (#1945)
Browse files Browse the repository at this point in the history
When using line breaks, print commas behind the listed items, instead
of on a new line.

Before:
```
Expected someCollection {
    item1
    ,
    item2
    ,
```
After:
```
Expected someCollection {
    item1,
    item2,
```

Co-authored-by: ronaldkroon <ronald.kroon@wolterskluwer.com>
  • Loading branch information
ronaldkroon and ronaldkroon committed Jul 7, 2022
1 parent c1283b7 commit 9205a42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Formatting/DefaultValueFormatter.cs
Expand Up @@ -42,7 +42,7 @@ public void Format(object value, FormattedObjectGraph formattedGraph, Formatting
{
if (context.UseLineBreaks)
{
formattedGraph.AddLine(value.ToString());
formattedGraph.AddFragmentOnNewLine(value.ToString());
}
else
{
Expand Down
14 changes: 14 additions & 0 deletions Tests/FluentAssertions.Specs/Formatting/FormatterSpecs.cs
Expand Up @@ -653,6 +653,20 @@ public void When_formatting_a_large_dictionary_it_should_limit_the_number_of_for
result.Should().Match("*…18 more…*");
}

[Fact]
public void When_formatting_multiple_items_with_a_custom_string_representation_using_line_breaks_it_should_end_lines_with_a_comma()
{
// Arrange
var subject = new[] { typeof(A), typeof(B) };

// Act
string result = Formatter.ToString(subject, new FormattingOptions { UseLineBreaks = true } );

// Assert
result.Should().Contain($"FluentAssertions.Specs.Formatting.FormatterSpecs+A, {Environment.NewLine}");
result.Should().Contain($"FluentAssertions.Specs.Formatting.FormatterSpecs+B{Environment.NewLine}");
}

public class BaseStuff
{
public int StuffId { get; set; }
Expand Down

0 comments on commit 9205a42

Please sign in to comment.