From 63e2e1636bac37b2a5ff1d82babeb8842b040ffe Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Wed, 22 Jul 2020 14:58:36 -0700 Subject: [PATCH] Fix Failing Casing Tests with Invariant Culture (#39747) --- .../System/Globalization/TextInfoTests.cs | 7 ++++++- .../src/System/Globalization/TextInfo.Nls.cs | 2 ++ .../tests/System/Text/RuneTests.cs | 20 ++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs b/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs index 099f9c24fb422..3ab4461d0176a 100644 --- a/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs +++ b/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs @@ -171,7 +171,7 @@ public void EqualsTest(TextInfo textInfo, object obj, bool expected) } } - private static readonly string [] s_cultureNames = new string[] { "", "en-US", "fr", "fr-FR" }; + private static readonly string [] s_cultureNames = new string[] { "en-US", "fr", "fr-FR" }; // ToLower_TestData_netcore has the data which is specific to netcore framework public static IEnumerable ToLower_TestData_netcore() @@ -181,6 +181,11 @@ public static IEnumerable ToLower_TestData_netcore() // DESERT CAPITAL LETTER LONG I has a lower case variant (but not on Windows 7). yield return new object[] { cultureName, "\U00010400", PlatformDetection.IsWindows7 ? "\U00010400" : "\U00010428" }; } + + if (!PlatformDetection.IsNlsGlobalization) + { + yield return new object[] { "", "\U00010400", PlatformDetection.IsWindows7 ? "\U00010400" : "\U00010428" }; + } } public static IEnumerable GetTestLocales() diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.Nls.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.Nls.cs index 656385a41a7d5..ca6689f4cef53 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.Nls.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.Nls.cs @@ -18,6 +18,8 @@ private unsafe void NlsChangeCase(char* pSource, int pSourceLen, char* pResult, Debug.Assert(pSourceLen <= pResultLen); // Check for Invariant to avoid A/V in LCMapStringEx + // We don't specify LCMAP_LINGUISTIC_CASING for Invariant because it will enable Turkish-I behavior too which is not + // right for Invariant. uint linguisticCasing = IsInvariantLocale(_textInfoName) ? 0 : LCMAP_LINGUISTIC_CASING; int ret = Interop.Kernel32.LCMapStringEx(_sortHandle != IntPtr.Zero ? null : _textInfoName, diff --git a/src/libraries/System.Runtime/tests/System/Text/RuneTests.cs b/src/libraries/System.Runtime/tests/System/Text/RuneTests.cs index 3c897871e5433..fb3a87c163f19 100644 --- a/src/libraries/System.Runtime/tests/System/Text/RuneTests.cs +++ b/src/libraries/System.Runtime/tests/System/Text/RuneTests.cs @@ -50,9 +50,27 @@ public static void Casing_CultureAware(int original, int upper, int lower, strin [InlineData('\u0130', '\u0130', '\u0130')] // U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE [InlineData('\u0131', '\u0131', '\u0131')] // U+0131 LATIN SMALL LETTER DOTLESS I [InlineData('\u1E9E', '\u1E9E', '\u1E9E')] // U+1E9E LATIN CAPITAL LETTER SHARP S + public static void Casing_Invariant(int original, int upper, int lower) + { + var rune = new Rune(original); + Assert.Equal(new Rune(upper), Rune.ToUpperInvariant(rune)); + Assert.Equal(new Rune(lower), Rune.ToLowerInvariant(rune)); + } + + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization))] + [InlineData('0', '0', '0')] + [InlineData('a', 'A', 'a')] + [InlineData('i', 'I', 'i')] + [InlineData('z', 'Z', 'z')] + [InlineData('A', 'A', 'a')] + [InlineData('I', 'I', 'i')] + [InlineData('Z', 'Z', 'z')] + [InlineData('\u00DF', '\u00DF', '\u00DF')] // U+00DF LATIN SMALL LETTER SHARP S + [InlineData('\u0130', '\u0130', '\u0130')] // U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE + [InlineData('\u0131', '\u0131', '\u0131')] // U+0131 LATIN SMALL LETTER DOTLESS I [InlineData(0x10400, 0x10400, 0x10428)] // U+10400 DESERET CAPITAL LETTER LONG I [InlineData(0x10428, 0x10400, 0x10428)] // U+10428 DESERET SMALL LETTER LONG I - public static void Casing_Invariant(int original, int upper, int lower) + public static void ICU_Casing_Invariant(int original, int upper, int lower) { var rune = new Rune(original); Assert.Equal(new Rune(upper), Rune.ToUpperInvariant(rune));