Skip to content

Commit fc7381c

Browse files
authored
Fix Failing Casing Tests with Invariant Culture (#39747)
1 parent 66a7205 commit fc7381c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void EqualsTest(TextInfo textInfo, object obj, bool expected)
171171
}
172172
}
173173

174-
private static readonly string [] s_cultureNames = new string[] { "", "en-US", "fr", "fr-FR" };
174+
private static readonly string [] s_cultureNames = new string[] { "en-US", "fr", "fr-FR" };
175175

176176
// ToLower_TestData_netcore has the data which is specific to netcore framework
177177
public static IEnumerable<object[]> ToLower_TestData_netcore()
@@ -181,6 +181,11 @@ public static IEnumerable<object[]> ToLower_TestData_netcore()
181181
// DESERT CAPITAL LETTER LONG I has a lower case variant (but not on Windows 7).
182182
yield return new object[] { cultureName, "\U00010400", PlatformDetection.IsWindows7 ? "\U00010400" : "\U00010428" };
183183
}
184+
185+
if (!PlatformDetection.IsNlsGlobalization)
186+
{
187+
yield return new object[] { "", "\U00010400", PlatformDetection.IsWindows7 ? "\U00010400" : "\U00010428" };
188+
}
184189
}
185190

186191
public static IEnumerable<string> GetTestLocales()

src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.Nls.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ private unsafe void NlsChangeCase(char* pSource, int pSourceLen, char* pResult,
1818
Debug.Assert(pSourceLen <= pResultLen);
1919

2020
// Check for Invariant to avoid A/V in LCMapStringEx
21+
// We don't specify LCMAP_LINGUISTIC_CASING for Invariant because it will enable Turkish-I behavior too which is not
22+
// right for Invariant.
2123
uint linguisticCasing = IsInvariantLocale(_textInfoName) ? 0 : LCMAP_LINGUISTIC_CASING;
2224

2325
int ret = Interop.Kernel32.LCMapStringEx(_sortHandle != IntPtr.Zero ? null : _textInfoName,

src/libraries/System.Runtime/tests/System/Text/RuneTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,27 @@ public static void Casing_CultureAware(int original, int upper, int lower, strin
5050
[InlineData('\u0130', '\u0130', '\u0130')] // U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE
5151
[InlineData('\u0131', '\u0131', '\u0131')] // U+0131 LATIN SMALL LETTER DOTLESS I
5252
[InlineData('\u1E9E', '\u1E9E', '\u1E9E')] // U+1E9E LATIN CAPITAL LETTER SHARP S
53+
public static void Casing_Invariant(int original, int upper, int lower)
54+
{
55+
var rune = new Rune(original);
56+
Assert.Equal(new Rune(upper), Rune.ToUpperInvariant(rune));
57+
Assert.Equal(new Rune(lower), Rune.ToLowerInvariant(rune));
58+
}
59+
60+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization))]
61+
[InlineData('0', '0', '0')]
62+
[InlineData('a', 'A', 'a')]
63+
[InlineData('i', 'I', 'i')]
64+
[InlineData('z', 'Z', 'z')]
65+
[InlineData('A', 'A', 'a')]
66+
[InlineData('I', 'I', 'i')]
67+
[InlineData('Z', 'Z', 'z')]
68+
[InlineData('\u00DF', '\u00DF', '\u00DF')] // U+00DF LATIN SMALL LETTER SHARP S
69+
[InlineData('\u0130', '\u0130', '\u0130')] // U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE
70+
[InlineData('\u0131', '\u0131', '\u0131')] // U+0131 LATIN SMALL LETTER DOTLESS I
5371
[InlineData(0x10400, 0x10400, 0x10428)] // U+10400 DESERET CAPITAL LETTER LONG I
5472
[InlineData(0x10428, 0x10400, 0x10428)] // U+10428 DESERET SMALL LETTER LONG I
55-
public static void Casing_Invariant(int original, int upper, int lower)
73+
public static void ICU_Casing_Invariant(int original, int upper, int lower)
5674
{
5775
var rune = new Rune(original);
5876
Assert.Equal(new Rune(upper), Rune.ToUpperInvariant(rune));

0 commit comments

Comments
 (0)