Skip to content

Commit

Permalink
Added string tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Afischbacher committed Jan 24, 2024
1 parent 88fd723 commit d3eab79
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void GetAllPlayers(string path)
/// </summary>
/// <param name="input">The string value for conversion</param>
/// <returns>The ASCII equivalent of the non-ASCII string</returns>
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]";
Expand All @@ -80,18 +80,35 @@ private static string ReplaceNonAsciiWithAscii(string input)
char c = match.Value[0];
return c switch
{
'À' or 'Á' or 'Â' or 'Ã' or 'Ä' => "A",
'Å' => "A",
'Æ' => "AE",

Check warning on line 85 in Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs

View check run for this annotation

Codecov / codecov/patch

Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs#L83-L85

Added lines #L83 - L85 were not covered by tests
'Ç' or 'Ć' => "C",
'È' or 'É' or 'Ê' or 'Ë' => "E",
'Ì' or 'Í' or 'Î' or 'Ï' => "I",

Check warning on line 88 in Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs

View check run for this annotation

Codecov / codecov/patch

Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs#L87-L88

Added lines #L87 - L88 were not covered by tests
'Ð' or 'Đ' => "D",
'Ñ' => "N",
'Ò' or 'Ó' or 'Ô' or 'Õ' or 'Ö' => "O",
'Ø' => "O",
'Ù' or 'Ú' or 'Û' or 'Ü' => "U",

Check warning on line 93 in Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs

View check run for this annotation

Codecov / codecov/patch

Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs#L90-L93

Added lines #L90 - L93 were not covered by tests
'Š' => "S",
'Ý' or 'Ÿ' => "Y",

Check warning on line 95 in Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs

View check run for this annotation

Codecov / codecov/patch

Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs#L95

Added line #L95 was not covered by tests
'Ž' => "Z",
'à' or 'á' or 'â' or 'ã' or 'ä' => "a",
'å' => "a",
'æ' => "ae",

Check warning on line 99 in Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs

View check run for this annotation

Codecov / codecov/patch

Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs#L98-L99

Added lines #L98 - L99 were not covered by tests
'ç' => "c",
'ç' or 'ć' => "c",
'đ' => "d",
'è' or 'é' or 'ê' or 'ë' => "e",
'ì' or 'í' or 'î' or 'ï' => "i",
'ð' => "d",
'ñ' => "n",

Check warning on line 105 in Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs

View check run for this annotation

Codecov / codecov/patch

Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs#L103-L105

Added lines #L103 - L105 were not covered by tests
'ò' or 'ó' or 'ô' or 'õ' or 'ö' => "o",
'ø' => "o",

Check warning on line 107 in Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs

View check run for this annotation

Codecov / codecov/patch

Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs#L107

Added line #L107 was not covered by tests
'ù' or 'ú' or 'û' or 'ü' => "u",
'š' => "s",
'ý' or 'ÿ' => "y",

Check warning on line 110 in Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs

View check run for this annotation

Codecov / codecov/patch

Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs#L110

Added line #L110 was not covered by tests
'ž' => "z",
_ => c.ToString(),

Check warning on line 112 in Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs

View check run for this annotation

Codecov / codecov/patch

Nhl.Api.Domain/Enumerations/Player/PlayerEnumFileGeneratorHelper.cs#L112

Added line #L112 was not covered by tests
};
});
Expand Down
19 changes: 19 additions & 0 deletions Nhl.Api.Tests/StringTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit d3eab79

Please sign in to comment.