WASM Enable System.Collections tests (#38976)
authorSantiago Fernandez Madero <safern@microsoft.com>
Thu, 9 Jul 2020 19:39:04 +0000 (12:39 -0700)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2020 19:39:04 +0000 (12:39 -0700)
src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs
src/libraries/System.Collections/tests/StructuralComparisonsTests.cs
src/libraries/tests.proj

index 35edbc0..e4b7ec9 100644 (file)
@@ -160,9 +160,27 @@ namespace System
             }
         }
 
-        private static Lazy<Version> m_icuVersion = new Lazy<Version>(GetICUVersion);
+        private static readonly Lazy<bool> m_isInvariant = new Lazy<bool>(GetIsInvariantGlobalization);
+
+        private static bool GetIsInvariantGlobalization()
+        {
+            Type globalizationMode = Type.GetType("System.Globalization.GlobalizationMode");
+            if (globalizationMode != null)
+            {
+                MethodInfo methodInfo = globalizationMode.GetProperty("Invariant", BindingFlags.NonPublic | BindingFlags.Static)?.GetMethod;
+                if (methodInfo != null)
+                {
+                    return (bool)methodInfo.Invoke(null, null);
+                }
+            }
+
+            return false;
+        }
+
+        private static readonly Lazy<Version> m_icuVersion = new Lazy<Version>(GetICUVersion);
         public static Version ICUVersion => m_icuVersion.Value;
 
+        public static bool IsInvariantGlobalization => m_isInvariant.Value;
         public static bool IsIcuGlobalization => ICUVersion > new Version(0,0,0,0);
         public static bool IsNlsGlobalization => !IsIcuGlobalization;
 
index 50d3187..4318875 100644 (file)
@@ -20,8 +20,9 @@ namespace System.Collections.Tests
             yield return new object[] { null, "abc", -1 };
             yield return new object[] { "abc", null, 1 };
             yield return new object[] { "abc", "abc", 0 };
-            yield return new object[] { "abc", "def", -1 };
-            yield return new object[] { "def", "abc", 1 };
+            // Invariant mode comparison of strings, ends up returning firstChar - secondChar when different, i.e 'd' - 'a'
+            yield return new object[] { "abc", "def", PlatformDetection.IsInvariantGlobalization ? -3 : -1 };
+            yield return new object[] { "def", "abc", PlatformDetection.IsInvariantGlobalization ? 3 : 1 };
             yield return new object[] { new StructuralObject(), "abc", 5 };
             yield return new object[] { new StructuralObject(), 123, -5 };
         }
index 66b98ce..d369aba 100644 (file)
@@ -29,7 +29,6 @@
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.CodeDom\tests\System.CodeDom.Tests.csproj" />
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Collections.NonGeneric\tests\System.Collections.NonGeneric.Tests.csproj" />
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Collections.Specialized\tests\System.Collections.Specialized.Tests.csproj" />
-    <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Collections\tests\System.Collections.Tests.csproj" />
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.ComponentModel.Annotations\tests\System.ComponentModel.Annotations.Tests.csproj" />
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.ComponentModel.Primitives\tests\System.ComponentModel.Primitives.Tests.csproj" />
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.ComponentModel.TypeConverter\tests\System.ComponentModel.TypeConverter.Tests.csproj" />