From e7f061a3d9ee55fa474095988d6cef8e994ad010 Mon Sep 17 00:00:00 2001 From: ronaldkroon Date: Fri, 24 Jun 2022 15:04:46 +0200 Subject: [PATCH] Print commas at the end of the line 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, ``` --- .../Formatting/DefaultValueFormatter.cs | 2 +- .../Formatting/FormatterSpecs.cs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Src/FluentAssertions/Formatting/DefaultValueFormatter.cs b/Src/FluentAssertions/Formatting/DefaultValueFormatter.cs index a6b69dcab8..848da7d1e9 100644 --- a/Src/FluentAssertions/Formatting/DefaultValueFormatter.cs +++ b/Src/FluentAssertions/Formatting/DefaultValueFormatter.cs @@ -42,7 +42,7 @@ public void Format(object value, FormattedObjectGraph formattedGraph, Formatting { if (context.UseLineBreaks) { - formattedGraph.AddLine(value.ToString()); + formattedGraph.AddFragmentOnNewLine(value.ToString()); } else { diff --git a/Tests/FluentAssertions.Specs/Formatting/FormatterSpecs.cs b/Tests/FluentAssertions.Specs/Formatting/FormatterSpecs.cs index aee194f681..3a4045b521 100644 --- a/Tests/FluentAssertions.Specs/Formatting/FormatterSpecs.cs +++ b/Tests/FluentAssertions.Specs/Formatting/FormatterSpecs.cs @@ -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; }