Skip to content

Commit

Permalink
Unify whitespace characters to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Feb 3, 2025
1 parent 75ff5c2 commit f31e73b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
53 changes: 38 additions & 15 deletions DiscordChatExporter.Cli.Tests/Specs/HtmlMarkdownSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using AngleSharp.Dom;
using DiscordChatExporter.Cli.Tests.Infra;
using DiscordChatExporter.Cli.Tests.Utils.Extensions;
using DiscordChatExporter.Core.Discord;
using FluentAssertions;
using Xunit;
Expand All @@ -19,8 +20,13 @@ public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestam
);

// Assert
message.Text().Should().Contain("Default timestamp: 2/12/2023 1:36 PM");
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 1:36 PM");
message
.Text()
.ReplaceWhiteSpace()
.Should()
.Contain("Default timestamp: 2/12/2023 1:36 PM");

message.InnerHtml.ReplaceWhiteSpace().Should().Contain("Sunday, February 12, 2023 1:36 PM");
}

[Fact]
Expand All @@ -33,8 +39,8 @@ public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestam
);

// Assert
message.Text().Should().Contain("Short time timestamp: 1:36 PM");
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 1:36 PM");
message.Text().ReplaceWhiteSpace().Should().Contain("Short time timestamp: 1:36 PM");
message.InnerHtml.ReplaceWhiteSpace().Should().Contain("Sunday, February 12, 2023 1:36 PM");
}

[Fact]
Expand All @@ -47,8 +53,8 @@ public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestam
);

// Assert
message.Text().Should().Contain("Long time timestamp: 1:36:12 PM");
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 1:36 PM");
message.Text().ReplaceWhiteSpace().Should().Contain("Long time timestamp: 1:36:12 PM");
message.InnerHtml.ReplaceWhiteSpace().Should().Contain("Sunday, February 12, 2023 1:36 PM");
}

[Fact]
Expand All @@ -61,8 +67,8 @@ public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestam
);

// Assert
message.Text().Should().Contain("Short date timestamp: 2/12/2023");
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 1:36 PM");
message.Text().ReplaceWhiteSpace().Should().Contain("Short date timestamp: 2/12/2023");
message.InnerHtml.ReplaceWhiteSpace().Should().Contain("Sunday, February 12, 2023 1:36 PM");
}

[Fact]
Expand All @@ -75,8 +81,13 @@ public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestam
);

// Assert
message.Text().Should().Contain("Long date timestamp: Sunday, February 12, 2023");
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 1:36 PM");
message
.Text()
.ReplaceWhiteSpace()
.Should()
.Contain("Long date timestamp: Sunday, February 12, 2023");

message.InnerHtml.ReplaceWhiteSpace().Should().Contain("Sunday, February 12, 2023 1:36 PM");
}

[Fact]
Expand All @@ -89,8 +100,13 @@ public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestam
);

// Assert
message.Text().Should().Contain("Full timestamp: Sunday, February 12, 2023 1:36 PM");
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 1:36 PM");
message
.Text()
.ReplaceWhiteSpace()
.Should()
.Contain("Full timestamp: Sunday, February 12, 2023 1:36 PM");

message.InnerHtml.ReplaceWhiteSpace().Should().Contain("Sunday, February 12, 2023 1:36 PM");
}

[Fact]
Expand All @@ -105,9 +121,11 @@ public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestam
// Assert
message
.Text()
.ReplaceWhiteSpace()
.Should()
.Contain("Full long timestamp: Sunday, February 12, 2023 1:36:12 PM");
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 1:36 PM");

message.InnerHtml.ReplaceWhiteSpace().Should().Contain("Sunday, February 12, 2023 1:36 PM");
}

[Fact]
Expand All @@ -120,8 +138,13 @@ public async Task I_can_export_a_channel_that_contains_a_message_with_a_timestam
);

// Assert
message.Text().Should().Contain("Relative timestamp: 2/12/2023 1:36 PM");
message.InnerHtml.Should().Contain("Sunday, February 12, 2023 1:36 PM");
message
.Text()
.ReplaceWhiteSpace()
.Should()
.Contain("Relative timestamp: 2/12/2023 1:36 PM");

message.InnerHtml.ReplaceWhiteSpace().Should().Contain("Sunday, February 12, 2023 1:36 PM");
}

[Fact]
Expand Down
16 changes: 16 additions & 0 deletions DiscordChatExporter.Cli.Tests/Utils/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Text;

namespace DiscordChatExporter.Cli.Tests.Utils.Extensions;

internal static class StringExtensions
{
public static string ReplaceWhiteSpace(this string str, string replacement = " ")
{
var buffer = new StringBuilder(str.Length);

foreach (var ch in str)
buffer.Append(char.IsWhiteSpace(ch) ? replacement : ch);

return buffer.ToString();
}
}

0 comments on commit f31e73b

Please sign in to comment.