public static void GetUnicodeCategory_Char_AllInputs() { // This tests calls char.GetUnicodeCategory for every possible input, ensuring that // the runtime agrees with the data in the core Unicode files. for (uint i = 0; i <= char.MaxValue; i++) { UnicodeCategory expected; // The code points in the switch block below must be special-cased // because they switched categories between versions of the Unicode // specification. For compatibility reasons Char keeps its own copy // of the categories for the first 256 code points, as it's locked // to an earlier version of the standard. For an example of a code // point that switched categories, see the discussion on U+00AD // SOFT HYPHEN at https://www.unicode.org/versions/Unicode4.0.0/. switch (i) { case '\u00a7': case '\u00b6': expected = UnicodeCategory.OtherSymbol; break; case '\u00aa': case '\u00ba': expected = UnicodeCategory.LowercaseLetter; break; case '\u00ad': expected = UnicodeCategory.DashPunctuation; break; default: expected = UnicodeData.GetUnicodeCategory(i); break; } if (expected != char.GetUnicodeCategory((char)i)) { // We'll build up the exception message ourselves so the dev knows what code point failed. throw new AssertActualExpectedException( expected: expected, actual: char.GetUnicodeCategory((char)i), userMessage: FormattableString.Invariant($@"char.GetUnicodeCategory('\u{i:X4}') returned wrong value.")); } } }
public static void GetUnicodeCategory_AllInputs() { // This tests calls Rune.GetUnicodeCategory for every possible input, ensuring that // the runtime agrees with the data in the core Unicode files. foreach (Rune rune in AllRunes()) { if (UnicodeData.GetUnicodeCategory(rune.Value) != Rune.GetUnicodeCategory(rune)) { // We'll build up the exception message ourselves so the dev knows what code point failed. throw new AssertActualExpectedException( expected: UnicodeData.GetUnicodeCategory(rune.Value), actual: Rune.GetUnicodeCategory(rune), userMessage: FormattableString.Invariant($@"Rune.GetUnicodeCategory(U+{rune.Value:X4}) returned wrong value.")); } } }
public static void IsUpper_Char_AllInputs() { // This tests calls char.IsUpper for every possible input, ensuring that // the runtime agrees with the data in the core Unicode files. for (uint i = 0; i <= char.MaxValue; i++) { bool expected = UnicodeData.GetUnicodeCategory((char)i) == UnicodeCategory.UppercaseLetter; if (expected != char.IsUpper((char)i)) { // We'll build up the exception message ourselves so the dev knows what code point failed. throw new AssertActualExpectedException( expected: expected, actual: char.IsUpper((char)i), userMessage: FormattableString.Invariant($@"char.IsUpper('\u{i:X4}') returned wrong value.")); } } }
public static void IsLower_Char_AllInputs() { // This tests calls char.IsLower for every possible input, ensuring that // the runtime agrees with the data in the core Unicode files. for (uint i = 0; i <= char.MaxValue; i++) { bool expected; switch (i) { case '\u00AA': // FEMININE ORDINAL INDICATOR case '\u00BA': // MASCULINE ORDINAL INDICATOR // In Unicode 6.1 the code points U+00AA and U+00BA were reassigned // from category Ll to category Lo. However, for compatibility reasons, // Char uses the older version of the Unicode standard for code points // in the range U+0000..U+00FF. So we'll special-case these here. // More info: https://www.unicode.org/review/pri181/ expected = true; break; default: expected = UnicodeData.GetUnicodeCategory((char)i) == UnicodeCategory.LowercaseLetter; break; } if (expected != char.IsLower((char)i)) { // We'll build up the exception message ourselves so the dev knows what code point failed. throw new AssertActualExpectedException( expected: expected, actual: char.IsLower((char)i), userMessage: FormattableString.Invariant($@"char.IsLower('\u{i:X4}') returned wrong value.")); } } }