Skip to content

Commit e928a19

Browse files
ronaldkroonjnyrup
authored andcommitted
Print commas at the end of the line (fluentassertions#1945)
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>
1 parent bb661bb commit e928a19

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Src/FluentAssertions/Formatting/DefaultValueFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void Format(object value, FormattedObjectGraph formattedGraph, Formatting
4242
{
4343
if (context.UseLineBreaks)
4444
{
45-
formattedGraph.AddLine(value.ToString());
45+
formattedGraph.AddFragmentOnNewLine(value.ToString());
4646
}
4747
else
4848
{

Tests/FluentAssertions.Specs/Formatting/FormatterSpecs.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,20 @@ public void When_formatting_a_large_dictionary_it_should_limit_the_number_of_for
653653
result.Should().Match("*…18 more…*");
654654
}
655655

656+
[Fact]
657+
public void When_formatting_multiple_items_with_a_custom_string_representation_using_line_breaks_it_should_end_lines_with_a_comma()
658+
{
659+
// Arrange
660+
var subject = new[] { typeof(A), typeof(B) };
661+
662+
// Act
663+
string result = Formatter.ToString(subject, new FormattingOptions { UseLineBreaks = true } );
664+
665+
// Assert
666+
result.Should().Contain($"FluentAssertions.Specs.Formatting.FormatterSpecs+A, {Environment.NewLine}");
667+
result.Should().Contain($"FluentAssertions.Specs.Formatting.FormatterSpecs+B{Environment.NewLine}");
668+
}
669+
656670
public class BaseStuff
657671
{
658672
public int StuffId { get; set; }

0 commit comments

Comments
 (0)