From f31e73bb7a392f450448625db9d69e20df75d634 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Tue, 4 Feb 2025 00:17:57 +0200 Subject: [PATCH] Unify whitespace characters to fix tests --- .../Specs/HtmlMarkdownSpecs.cs | 53 +++++++++++++------ .../Utils/Extensions/StringExtensions.cs | 16 ++++++ 2 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 DiscordChatExporter.Cli.Tests/Utils/Extensions/StringExtensions.cs diff --git a/DiscordChatExporter.Cli.Tests/Specs/HtmlMarkdownSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/HtmlMarkdownSpecs.cs index 7340467..c9623ef 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/HtmlMarkdownSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/HtmlMarkdownSpecs.cs @@ -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; @@ -19,8 +20,13 @@ public class HtmlMarkdownSpecs ); // 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] @@ -33,8 +39,8 @@ public class HtmlMarkdownSpecs ); // 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] @@ -47,8 +53,8 @@ public class HtmlMarkdownSpecs ); // 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] @@ -61,8 +67,8 @@ public class HtmlMarkdownSpecs ); // 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] @@ -75,8 +81,13 @@ public class HtmlMarkdownSpecs ); // 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] @@ -89,8 +100,13 @@ public class HtmlMarkdownSpecs ); // 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] @@ -105,9 +121,11 @@ public class HtmlMarkdownSpecs // 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] @@ -120,8 +138,13 @@ public class HtmlMarkdownSpecs ); // 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] diff --git a/DiscordChatExporter.Cli.Tests/Utils/Extensions/StringExtensions.cs b/DiscordChatExporter.Cli.Tests/Utils/Extensions/StringExtensions.cs new file mode 100644 index 0000000..db61fc1 --- /dev/null +++ b/DiscordChatExporter.Cli.Tests/Utils/Extensions/StringExtensions.cs @@ -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(); + } +}