Skip to content

Commit

Permalink
Add AppendLineN for no string (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Aug 9, 2022
1 parent acd4ed0 commit 4d385fd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;msb3277;CS0436</NoWarn>
<Version>17.8.0</Version>
<Version>17.8.1</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
Expand Down
11 changes: 10 additions & 1 deletion src/Verify/StringBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ public static void FixNewlines(this StringBuilder builder)
/// <summary>
/// Appends a line with a `\n` as the newline character.
/// </summary>
public static StringBuilder AppendLineN(this StringBuilder builder, string value)
public static StringBuilder AppendLineN(this StringBuilder builder)
{
builder.Append('\n');
return builder;
}

/// <summary>
/// Appends a line with a `\n` as the newline character.
/// </summary>
public static StringBuilder AppendLineN(this StringBuilder builder, string? value)
{
builder.Append(value);
builder.Append('\n');
Expand Down
42 changes: 21 additions & 21 deletions src/Verify/Verifier/VerifyExceptionMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public static string Build(
IReadOnlyCollection<FilePair> equal)
{
var builder = new StringBuilder($"Directory: {directory}");
builder.AppendLine();
builder.AppendLineN();

if (@new.Any())
{
builder.AppendLine("New:");
builder.AppendLineN("New:");
foreach (var file in @new)
{
AppendFile(builder, file.File);
Expand All @@ -21,7 +21,7 @@ public static string Build(

if (notEquals.Any())
{
builder.AppendLine("NotEqual:");
builder.AppendLineN("NotEqual:");
foreach (var file in notEquals)
{
AppendFile(builder, file.File);
Expand All @@ -30,16 +30,16 @@ public static string Build(

if (delete.Any())
{
builder.AppendLine("Delete:");
builder.AppendLineN("Delete:");
foreach (var file in delete)
{
builder.AppendLine($" - {Path.GetFileName(file)}");
builder.AppendLineN($" - {Path.GetFileName(file)}");
}
}

if (equal.Any())
{
builder.AppendLine("Equal:");
builder.AppendLineN("Equal:");
foreach (var file in equal)
{
AppendFile(builder, file);
Expand All @@ -53,8 +53,8 @@ public static string Build(

static void AppendFile(StringBuilder builder, FilePair file)
{
builder.AppendLine($" - Received: {file.ReceivedName}");
builder.AppendLine($" Verified: {file.VerifiedName}");
builder.AppendLineN($" - Received: {file.ReceivedName}");
builder.AppendLineN($" Verified: {file.VerifiedName}");
}

static void AppendContent(IReadOnlyCollection<NewResult> @new, IReadOnlyCollection<NotEqualResult> notEquals, StringBuilder builder)
Expand All @@ -73,32 +73,32 @@ static void AppendContent(IReadOnlyCollection<NewResult> @new, IReadOnlyCollecti
return;
}

builder.AppendLine();
builder.AppendLine("FileContent:");
builder.AppendLine();
builder.AppendLineN();
builder.AppendLineN("FileContent:");
builder.AppendLineN();

if (newContentFiles.Any())
{
builder.AppendLine("New:");
builder.AppendLine();
builder.AppendLineN("New:");
builder.AppendLineN();
foreach (var item in newContentFiles)
{
builder.AppendLine($"Received: {item.File.ReceivedName}");
builder.AppendLine(item.ReceivedText);
builder.AppendLine();
builder.AppendLineN($"Received: {item.File.ReceivedName}");
builder.AppendLineN(item.ReceivedText);
builder.AppendLineN();
}
}

if (notEqualContentFiles.Any())
{
builder.AppendLine("NotEqual:");
builder.AppendLine();
builder.AppendLineN("NotEqual:");
builder.AppendLineN();
foreach (var notEqual in notEqualContentFiles)
{
if (notEqual.File.IsText || notEqual.Message != null)
{
AppendNotEqualContent(builder, notEqual);
builder.AppendLine();
builder.AppendLineN();
}
}
}
Expand All @@ -110,7 +110,7 @@ static void AppendNotEqualContent(StringBuilder builder, NotEqualResult notEqual
var message = notEqual.Message;
if (message is null)
{
builder.AppendLine(
builder.AppendLineN(
$"""
Received: {item.ReceivedName}
{notEqual.ReceivedText}
Expand All @@ -120,7 +120,7 @@ static void AppendNotEqualContent(StringBuilder builder, NotEqualResult notEqual
}
else
{
builder.AppendLine(
builder.AppendLineN(
$"""
Received: {item.ReceivedName}
Verified: {item.VerifiedName}
Expand Down

0 comments on commit 4d385fd

Please sign in to comment.