From 89413a69edd2f540e5fbd514af7b0e67157da71e Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 17 May 2022 20:16:07 -0400 Subject: [PATCH] Fix hex tests --- .../System.Runtime/tests/System/CharTests.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/CharTests.cs b/src/libraries/System.Runtime/tests/System/CharTests.cs index e3583d200af1..390038835abf 100644 --- a/src/libraries/System.Runtime/tests/System/CharTests.cs +++ b/src/libraries/System.Runtime/tests/System/CharTests.cs @@ -307,22 +307,29 @@ public static void IsDigit_String_Int_Invalid() [Fact] public static void IsAsciiHexDigit_Char() => - IsAsciiHexDigit(new HashSet() { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f' }); + IsAsciiHexDigit( + new HashSet() { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f' }, + char.IsAsciiHexDigit); [Fact] public static void IsAsciiHexDigitLower_Char() => - IsAsciiHexDigit(new HashSet() { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }); + IsAsciiHexDigit( + new HashSet() { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }, + char.IsAsciiHexDigitLower); [Fact] public static void IsAsciiHexDigitUpper_Char() => - IsAsciiHexDigit(new HashSet() { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }); + IsAsciiHexDigit( + new HashSet() { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }, + char.IsAsciiHexDigitUpper); - private static void IsAsciiHexDigit(HashSet hexDigits) + private static void IsAsciiHexDigit(HashSet hexDigits, Func predicate) { for (int i = 0; i < 128; i++) { - Assert.Equal(hexDigits.Contains((char)i), char.IsAsciiHexDigit((char)i)); + Assert.Equal(hexDigits.Contains((char)i), predicate((char)i)); } + foreach (char c in hexDigits) { Assert.False(char.IsAsciiHexDigit((char)(c | 0xFF00)));