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()
{
[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)
{
[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)
{
[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)
{
[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)
{
[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)
{
[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)
{
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)
[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" };
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])));
}
}
}
public static IEnumerable<object[]> 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 };
}
[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)
{
{
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<Hashtable> action)
{
// Synchronized returns a slightly different version of Hashtable
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];
<!-- Builds currently do not pass -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.VisualBasic.Core\tests\Microsoft.VisualBasic.Core.Tests.csproj" />
<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.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" />