From 385fc186e70194b747c2769b889a7762655b5931 Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Thu, 9 Jul 2020 14:04:29 -0700 Subject: [PATCH] WASM enable System.Collections.NonGeneric.Tests --- .../TestUtilities/System/PlatformDetection.cs | 3 +- .../tests/CaseInsensitiveComparerTests.cs | 27 ++------------ .../CaseInsensitiveHashCodeProviderTests.cs | 29 +++------------ .../tests/ComparerTests.cs | 35 ++++++++----------- .../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 e4b7ec92f3294..088e533e1399e 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -181,8 +181,9 @@ private static bool GetIsInvariantGlobalization() 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 159c2fc6646f3..6a0428686cb38 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveComparerTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveComparerTests.cs @@ -45,14 +45,7 @@ public void Ctor_Empty_Compare(object a, object b, int expected) [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 @@ public void Ctor_CultureInfo_Compare(object a, object b, int expected) [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 @@ public void Ctor_CultureInfo_NullCulture_ThrowsArgumentNullException() [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 b4b4dac2dd60a..f41a9225e0246 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveHashCodeProviderTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/CaseInsensitiveHashCodeProviderTests.cs @@ -39,14 +39,7 @@ public void Ctor_Empty_GetHashCodeCompare(object a, object b, bool expected) [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 @@ public void Ctor_Empty_ChangeCurrentCulture_GetHashCodeCompare(object a, object [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 @@ public void Ctor_CultureInfo_ChangeCurrentCulture_GetHashCodeCompare(object a, o [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 @@ public void Default_GetHashCodeCompare(object a, object b, bool expected) 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 0e660eb976717..98662f8152eca 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/ComparerTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/ComparerTests.cs @@ -39,14 +39,7 @@ public void Ctor_CultureInfo_NullCulture_ThrowsArgumentNullException() [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 @@ public void DefaultInvariant_Compare() 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 @@ public void DefaultInvariant_Compare_Invalid() 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 @@ public static IEnumerable CompareTestData() } [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 9e6fb7d8cc416..e9b34ee5d595f 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 e49e76c9e5d82..8125d6a014a88 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/SortedListTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/SortedListTests.cs @@ -1339,14 +1339,7 @@ public void Item_Get_DifferentCulture() 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 d369aba08d76e..407af099361b6 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -27,7 +27,6 @@ -