Skip to content

Commit

Permalink
Change CheckChars() to work without ignore char + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed Oct 21, 2023
1 parent 8755b01 commit 3f42d4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Src/FinderOuter/Services/InputService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public static bool TryGetCompareService(CompareInputType inType, string input, o
public static bool IsMissingCharValid(char c) => ConstantsFO.MissingSymbols.Contains(c);


public static bool CheckChars(ReadOnlySpan<char> array, ReadOnlySpan<char> charSet, char ignore, out string error)
public static bool CheckChars(ReadOnlySpan<char> array, ReadOnlySpan<char> charSet, char? ignore, out string error)
{
bool isValid = true;
error = string.Empty;
for (int i = 0; i < array.Length; i++)
{
if (!charSet.Contains(array[i]) && array[i] != ignore)
if (!charSet.Contains(array[i]) && (!ignore.HasValue || array[i] != ignore.Value))
{
isValid = false;
if (!string.IsNullOrEmpty(error))
Expand Down Expand Up @@ -249,7 +249,7 @@ public static bool IsValidWif(string key, out string message)
message = "Could not decode the given key.";
return false;
}

if (keyBa[0] != ConstantsFO.PrivKeyFirstByte)
{
message = $"Invalid first key byte (actual={keyBa[0]}, expected={ConstantsFO.PrivKeyFirstByte}).";
Expand Down
4 changes: 3 additions & 1 deletion Src/Tests/Services/InputServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ public static IEnumerable<object[]> GetCheckCharsCases()
yield return new object[] { "a ", "abcde", '*', false, "Invalid character \" \" found at index=1." };
yield return new object[] { "a*b", "abcde", '*', true, "" };
yield return new object[] { "***", "abcde", '*', true, "" };
yield return new object[] { "ab", "abcde", null, true, "" };
yield return new object[] { "ab*", "abcde", null, false, "Invalid character \"*\" found at index=2." };
}
[Theory]
[MemberData(nameof(GetCheckCharsCases))]
public void CheckCharsTest(string input, string charSet, char ignore, bool expected, string expErr)
public void CheckCharsTest(string input, string charSet, char? ignore, bool expected, string expErr)
{
bool actual = InputService.CheckChars(input, charSet, ignore, out string error);
Assert.Equal(expected, actual);
Expand Down

0 comments on commit 3f42d4d

Please sign in to comment.