Skip to content

Commit

Permalink
Fix Globalization Tests (#88969)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekgh authored Jul 17, 2023
1 parent a513676 commit d1ef9b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ public static IEnumerable<object[]> Ctor_String_TestData()
yield return new object[] { "pa-IN", new [] { "pa-IN" }};
yield return new object[] { "pl", new [] { "pl" } };
yield return new object[] { "pl-PL", new [] { "pl-PL" } };
yield return new object[] { "prs", new [] { "prs" }};
yield return new object[] { "prs-AF", new [] { "prs-AF" }};
yield return new object[] { "prs", new [] { "prs", "fa" } };
yield return new object[] { "prs-AF", new [] { "prs-AF", "fa-AF" }};
yield return new object[] { "ps", new [] { "ps" }};
yield return new object[] { "ps-AF", new [] { "ps-AF" }};
yield return new object[] { "pt", new [] { "pt" } };
Expand Down Expand Up @@ -386,7 +386,6 @@ public static IEnumerable<object[]> Ctor_String_TestData()

[Theory]
[MemberData(nameof(Ctor_String_TestData))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/79867", typeof(PlatformDetection), nameof(PlatformDetection.IsArm64Process), nameof(PlatformDetection.IsWindows))]
public void Ctor_String(string name, string[] expectedNames)
{
CultureInfo culture = new CultureInfo(name);
Expand Down Expand Up @@ -458,7 +457,7 @@ public void TestCreationWithMangledSortName(string cultureName, string expectedC
[InlineData("qps-plocm", "qps-PLOCM")] // ICU normalize this name to "qps--plocm" which we normalize it back to "qps-plocm"
[InlineData("zh_CN", "zh_cn")]
[InlineData("km_KH", "km_kh")]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization), nameof(PlatformDetection.IsNotWindowsServerCore))]
public void TestCreationWithICUNormalizedNames(string cultureName, string expectedCultureName)
{
CultureInfo ci = CultureInfo.GetCultureInfo(cultureName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ public class NumberFormatInfoCurrencyGroupSizes
{
public static IEnumerable<object[]> CurrencyGroupSizes_TestData()
{
yield return new object[] { NumberFormatInfo.InvariantInfo, new int[] { 3 } };
yield return new object[] { CultureInfo.GetCultureInfo("en-US").NumberFormat, new int[] { 3 } };
yield return new object[] { NumberFormatInfo.InvariantInfo, new int[] { 3 }, null };
yield return new object[] { CultureInfo.GetCultureInfo("en-US").NumberFormat, new int[] { 3 }, null };

if (PlatformDetection.IsNotUsingLimitedCultures && !PlatformDetection.IsUbuntu && !PlatformDetection.IsWindows7 && !PlatformDetection.IsWindows8x && !PlatformDetection.IsFedora)
{
yield return new object[] { CultureInfo.GetCultureInfo("ur-IN").NumberFormat, new int[] { 3, 2 } };
yield return new object[] { CultureInfo.GetCultureInfo("ur-IN").NumberFormat, new int[] { 3, 2 }, new int[] { 3 }};
}
}

[Theory]
[MemberData(nameof(CurrencyGroupSizes_TestData))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/79867", typeof(PlatformDetection), nameof(PlatformDetection.IsArm64Process), nameof(PlatformDetection.IsWindows))]
public void CurrencyGroupSizes_Get_ReturnsExpected(NumberFormatInfo format, int[] expected)
public void CurrencyGroupSizes_Get_ReturnsExpected(NumberFormatInfo format, int[] expected, int [] expectedAlternative)
{
Assert.Equal(expected, format.CurrencyGroupSizes);
Assert.True(format.CurrencyGroupSizes.AsSpan().SequenceEqual(expected.AsSpan()) || format.CurrencyGroupSizes.AsSpan().SequenceEqual(expectedAlternative.AsSpan()),
$"Expected {string.Join(", ", expected)} or {string.Join(", ", expectedAlternative ?? Array.Empty<int>())}, got {string.Join(", ", format.CurrencyGroupSizes)}");
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public static IEnumerable<object[]> DigitSubstitution_TestData()
yield return new object[] { "nqo-GN" , DigitShapes.NativeNational };
yield return new object[] { "pa-Arab" , DigitShapes.NativeNational };
yield return new object[] { "pa-Arab-PK", DigitShapes.NativeNational };
yield return new object[] { "prs" , DigitShapes.NativeNational };
yield return new object[] { "prs-AF" , DigitShapes.NativeNational };
yield return new object[] { "ps" , DigitShapes.NativeNational };
yield return new object[] { "ps-AF" , DigitShapes.NativeNational };
yield return new object[] { "sd" , DigitShapes.NativeNational };
Expand Down Expand Up @@ -102,7 +100,6 @@ public void TestNFIFormatLimits()

[Theory]
[MemberData(nameof(DigitSubstitution_TestData))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/79867", typeof(PlatformDetection), nameof(PlatformDetection.IsArm64Process), nameof(PlatformDetection.IsWindows))]
public void DigitSubstitutionListTest(string cultureName, DigitShapes shape)
{
try
Expand All @@ -116,6 +113,24 @@ public void DigitSubstitutionListTest(string cultureName, DigitShapes shape)
}
}

[Theory]
[InlineData("prs")]
[InlineData("prs-AF")]
public void PrsNativeDigitsTest(string cultureName)
{
try
{
CultureInfo ci = CultureInfo.GetCultureInfo(cultureName);

// Some OS's set the DigitSubstitution to Context for the culture "prs" and "prs-AF". Majority of Os's set it to NativeNational.
Assert.True(ci.NumberFormat.DigitSubstitution == DigitShapes.Context || ci.NumberFormat.DigitSubstitution == DigitShapes.NativeNational);
}
catch (CultureNotFoundException)
{
// ignore the cultures that we cannot create as it is not supported on the platforms
}
}

public static IEnumerable<object[]> NativeDigitTestData()
{
yield return new object[] { "ccp-Cakm-BD", new string[] { "\U0001E950", "\U0001E951", "\U0001E952", "\U0001E953", "\U0001E954", "\U0001E955", "\U0001E956", "\U0001E957", "\U0001E958", "\U0001E959" }};
Expand Down

0 comments on commit d1ef9b6

Please sign in to comment.