From d3eab796e24e719150364d23dab4ec6c152e9cb6 Mon Sep 17 00:00:00 2001 From: "ANDRE-PC\\ital-" Date: Tue, 23 Jan 2024 21:45:57 -0500 Subject: [PATCH] Added string tests --- .../Player/PlayerEnumFileGeneratorHelper.cs | 21 +++++++++++++++++-- Nhl.Api.Tests/StringTests.cs | 19 +++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 Nhl.Api.Tests/StringTests.cs diff --git a/Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs b/Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs index 361323a6..d5bb3ac6 100644 --- a/Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs +++ b/Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs @@ -69,7 +69,7 @@ public static void GetAllPlayers(string path) /// /// The string value for conversion /// The ASCII equivalent of the non-ASCII string - private static string ReplaceNonAsciiWithAscii(string input) + public static string ReplaceNonAsciiWithAscii(string input) { // Define a regular expression pattern for non-ASCII characters string pattern = @"[^\x00-\x7F]"; @@ -80,10 +80,25 @@ private static string ReplaceNonAsciiWithAscii(string input) char c = match.Value[0]; return c switch { + 'À' or 'Á' or 'Â' or 'Ã' or 'Ä' => "A", + 'Å' => "A", + 'Æ' => "AE", + 'Ç' or 'Ć' => "C", + 'È' or 'É' or 'Ê' or 'Ë' => "E", + 'Ì' or 'Í' or 'Î' or 'Ï' => "I", + 'Ð' or 'Đ' => "D", + 'Ñ' => "N", + 'Ò' or 'Ó' or 'Ô' or 'Õ' or 'Ö' => "O", + 'Ø' => "O", + 'Ù' or 'Ú' or 'Û' or 'Ü' => "U", + 'Š' => "S", + 'Ý' or 'Ÿ' => "Y", + 'Ž' => "Z", 'à' or 'á' or 'â' or 'ã' or 'ä' => "a", 'å' => "a", 'æ' => "ae", - 'ç' => "c", + 'ç' or 'ć' => "c", + 'đ' => "d", 'è' or 'é' or 'ê' or 'ë' => "e", 'ì' or 'í' or 'î' or 'ï' => "i", 'ð' => "d", @@ -91,7 +106,9 @@ private static string ReplaceNonAsciiWithAscii(string input) 'ò' or 'ó' or 'ô' or 'õ' or 'ö' => "o", 'ø' => "o", 'ù' or 'ú' or 'û' or 'ü' => "u", + 'š' => "s", 'ý' or 'ÿ' => "y", + 'ž' => "z", _ => c.ToString(), }; }); diff --git a/Nhl.Api.Tests/StringTests.cs b/Nhl.Api.Tests/StringTests.cs new file mode 100644 index 00000000..39ff06c8 --- /dev/null +++ b/Nhl.Api.Tests/StringTests.cs @@ -0,0 +1,19 @@ +using Nhl.Api.Models.Enumerations.Player; + +namespace Nhl.Api.Tests; + +[TestClass] +public class StringTests +{ + + [TestMethod] + [DataRow("ŠĐĆŽćžšđ", "SDCZczsd")] + [DataRow("àndre", "andre")] + + public void ReplaceNonAsciiWithAscii_Returns_Correct_Ascii_String(string input, string expected) + { + var actual = PlayerEnumFileGeneratorHelper.ReplaceNonAsciiWithAscii(input); + + Assert.AreEqual(expected, actual); + } +}