From 2a4c626a0f5fb5d640b3e8ee7707e650ca570f7e Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Fri, 10 Jul 2020 00:11:48 -0700 Subject: [PATCH] WASM enable System.Collections.NonGeneric.Tests (#39020) --- .../TestUtilities/System/PlatformDetection.cs | 3 +- .../tests/CaseInsensitiveComparerTests.cs | 27 ++--------------- .../tests/CaseInsensitiveHashCodeProviderTests.cs | 29 +++--------------- .../tests/ComparerTests.cs | 35 ++++++++++------------ .../System.Collections.NonGeneric/tests/Helpers.cs | 12 ++++++++ .../tests/SortedListTests.cs | 9 +----- src/libraries/tests.proj | 1 - 7 files changed, 37 insertions(+), 79 deletions(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index a96c217..48a2f5c 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -183,8 +183,9 @@ namespace System public static Version ICUVersion => m_icuVersion.Value; public static bool IsInvariantGlobalization => m_isInvariant.Value; + public static bool IsNotInvariantGlobalization => !IsInvariantGlobalization; public static bool IsIcuGlobalization => ICUVersion > new Version(0,0,0,0); - public static bool IsNlsGlobalization => !IsIcuGlobalization; + public static bool IsNlsGlobalization => IsNotInvariantGlobalization && !IsIcuGlobalization; private static Version GetICUVersion() { diff --git a/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveComparerTests.cs b/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveComparerTests.cs index 159c2fc..6a04286 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveComparerTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveComparerTests.cs @@ -45,14 +45,7 @@ namespace System.Collections.Tests [InlineData(null, null, 0)] public void Ctor_CultureInfo_Compare(object a, object b, int expected) { - var cultureNames = new string[] - { - "cs-CZ","da-DK","de-DE","el-GR","en-US", - "es-ES","fi-FI","fr-FR","hu-HU","it-IT", - "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", - "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", - "zh-CN","zh-HK","zh-TW" - }; + var cultureNames = Helpers.TestCultureNames; foreach (string cultureName in cultureNames) { @@ -74,14 +67,7 @@ namespace System.Collections.Tests [Fact] public void Ctor_CultureInfo_Compare_TurkishI() { - var cultureNames = new string[] - { - "cs-CZ","da-DK","de-DE","el-GR","en-US", - "es-ES","fi-FI","fr-FR","hu-HU","it-IT", - "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", - "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", - "zh-CN","zh-HK","zh-TW" - }; + var cultureNames = Helpers.TestCultureNames; foreach (string cultureName in cultureNames) { @@ -132,14 +118,7 @@ namespace System.Collections.Tests [InlineData(null, null, 0)] public void DefaultInvariant_Compare(object a, object b, int expected) { - var cultureNames = new string[] - { - "cs-CZ","da-DK","de-DE","el-GR","en-US", - "es-ES","fi-FI","fr-FR","hu-HU","it-IT", - "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", - "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", - "zh-CN","zh-HK","zh-TW" - }; + var cultureNames = Helpers.TestCultureNames; foreach (string cultureName in cultureNames) { diff --git a/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveHashCodeProviderTests.cs b/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveHashCodeProviderTests.cs index b4b4dac..f41a922 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveHashCodeProviderTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveHashCodeProviderTests.cs @@ -39,14 +39,7 @@ namespace System.Collections.Tests [InlineData(5, 10, false)] public void Ctor_Empty_ChangeCurrentCulture_GetHashCodeCompare(object a, object b, bool expected) { - var cultureNames = new string[] - { - "cs-CZ","da-DK","de-DE","el-GR","en-US", - "es-ES","fi-FI","fr-FR","hu-HU","it-IT", - "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", - "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", - "zh-CN","zh-HK","zh-TW" - }; + var cultureNames = Helpers.TestCultureNames; foreach (string cultureName in cultureNames) { @@ -80,14 +73,7 @@ namespace System.Collections.Tests [InlineData(5, 10, false)] public void Ctor_CultureInfo_ChangeCurrentCulture_GetHashCodeCompare(object a, object b, bool expected) { - var cultureNames = new string[] - { - "cs-CZ","da-DK","de-DE","el-GR","en-US", - "es-ES","fi-FI","fr-FR","hu-HU","it-IT", - "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", - "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", - "zh-CN","zh-HK","zh-TW" - }; + var cultureNames = Helpers.TestCultureNames; foreach (string cultureName in cultureNames) { @@ -111,14 +97,7 @@ namespace System.Collections.Tests [Fact] public void Ctor_CultureInfo_GetHashCodeCompare_TurkishI() { - var cultureNames = new string[] - { - "cs-CZ","da-DK","de-DE","el-GR","en-US", - "es-ES","fi-FI","fr-FR","hu-HU","it-IT", - "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", - "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", - "zh-CN","zh-HK","zh-TW" - }; + var cultureNames = Helpers.TestCultureNames; foreach (string cultureName in cultureNames) { @@ -170,7 +149,7 @@ namespace System.Collections.Tests CaseInsensitiveHashCodeProvider.DefaultInvariant.GetHashCode(a) == CaseInsensitiveHashCodeProvider.DefaultInvariant.GetHashCode(b)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotInvariantGlobalization))] public void Default_Compare_TurkishI() { // Turkish has lower-case and upper-case version of the dotted "i", so the upper case of "i" (U+0069) isn't "I" (U+0049) diff --git a/src/libraries/System.Collections.NonGeneric/tests/ComparerTests.cs b/src/libraries/System.Collections.NonGeneric/tests/ComparerTests.cs index 0e660eb..98662f8 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/ComparerTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/ComparerTests.cs @@ -39,14 +39,7 @@ namespace System.Collections.Tests [Fact] public void DefaultInvariant_Compare() { - var cultureNames = new string[] - { - "cs-CZ","da-DK","de-DE","el-GR","en-US", - "es-ES","fi-FI","fr-FR","hu-HU","it-IT", - "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", - "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", - "zh-CN","zh-HK","zh-TW" - }; + var cultureNames = Helpers.TestCultureNames; var string1 = new string[] { "Apple", "abc", }; var string2 = new string[] { "\u00C6ble", "ABC" }; @@ -67,8 +60,9 @@ namespace System.Collections.Tests using (new ThreadCultureChange(culture, culture)) { Comparer comp = Comparer.DefaultInvariant; - Assert.Equal(1, comp.Compare(string1[0], string2[0])); - Assert.Equal(-1, comp.Compare(string1[1], string2[1])); + /* Comparing in invariant mode compars firstChar - secondChar (A(65) - \u00C6(198) */ + Assert.Equal(PlatformDetection.IsInvariantGlobalization ? -1 : 1, Math.Sign(comp.Compare(string1[0], string2[0]))); + Assert.Equal(PlatformDetection.IsInvariantGlobalization ? 1 : -1, Math.Sign(comp.Compare(string1[1], string2[1]))); } } } @@ -86,6 +80,17 @@ namespace System.Collections.Tests public static IEnumerable CompareTestData() { + yield return new object[] { "hello", "hello", 0 }; + yield return new object[] { "HELLO", "HELLO", 0 }; + yield return new object[] { "hello", "HELLO", PlatformDetection.IsInvariantGlobalization ? 1 : -1 }; + yield return new object[] { "hello", "goodbye", 1 }; + yield return new object[] { 1, 2, -1 }; + yield return new object[] { 2, 1, 1 }; + yield return new object[] { 1, 1, 0 }; + yield return new object[] { 1, null, 1 }; + yield return new object[] { null, 1, -1 }; + yield return new object[] { null, null, 0 }; + yield return new object[] { new Foo(5), new Bar(5), 0 }; yield return new object[] { new Bar(5), new Foo(5), 0 }; @@ -94,16 +99,6 @@ namespace System.Collections.Tests } [Theory] - [InlineData("hello", "hello", 0)] - [InlineData("HELLO", "HELLO", 0)] - [InlineData("hello", "HELLO", -1)] - [InlineData("hello", "goodbye", 1)] - [InlineData(1, 2, -1)] - [InlineData(2, 1, 1)] - [InlineData(1, 1, 0)] - [InlineData(1, null, 1)] - [InlineData(null, 1, -1)] - [InlineData(null, null, 0)] [MemberData(nameof(CompareTestData))] public void Default_Compare(object a, object b, int expected) { diff --git a/src/libraries/System.Collections.NonGeneric/tests/Helpers.cs b/src/libraries/System.Collections.NonGeneric/tests/Helpers.cs index 9e6fb7d..e9b34ee 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/Helpers.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/Helpers.cs @@ -7,6 +7,18 @@ namespace System.Collections.Tests { internal static class Helpers { + public static string[] TestCultureNames => + PlatformDetection.IsInvariantGlobalization ? + new string[] { "" } : + new string[] + { + "cs-CZ","da-DK","de-DE","el-GR","en-US", + "es-ES","fi-FI","fr-FR","hu-HU","it-IT", + "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", + "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", + "zh-CN","zh-HK","zh-TW" + }; + public static void PerformActionOnAllHashtableWrappers(Hashtable hashtable, Action action) { // Synchronized returns a slightly different version of Hashtable diff --git a/src/libraries/System.Collections.NonGeneric/tests/SortedListTests.cs b/src/libraries/System.Collections.NonGeneric/tests/SortedListTests.cs index e49e76c..8125d6a 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/SortedListTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/SortedListTests.cs @@ -1339,14 +1339,7 @@ namespace System.Collections.Tests try { - var cultureNames = new string[] - { - "cs-CZ","da-DK","de-DE","el-GR","en-US", - "es-ES","fi-FI","fr-FR","hu-HU","it-IT", - "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", - "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", - "zh-CN","zh-HK","zh-TW" - }; + var cultureNames = Helpers.TestCultureNames; var installedCultures = new CultureInfo[cultureNames.Length]; var cultureDisplayNames = new string[installedCultures.Length]; diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 59c1e71..b663b4d 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -27,7 +27,6 @@ - -- 2.7.4