22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System . Buffers ;
5+ using System . Reflection ;
56using System . Buffers . Binary ;
67using System . Collections . Generic ;
78using System . IO ;
@@ -13,6 +14,23 @@ namespace System.Globalization.Tests
1314{
1415 public class InvariantModeTests
1516 {
17+ private static bool PredefinedCulturesOnlyIsDisabled { get ; } = ! PredefinedCulturesOnly ( ) ;
18+ private static bool PredefinedCulturesOnly ( )
19+ {
20+ bool ret ;
21+
22+ try
23+ {
24+ ret = ( bool ) typeof ( object ) . Assembly . GetType ( "System.Globalization.GlobalizationMode" ) . GetProperty ( "PredefinedCulturesOnly" , BindingFlags . Static | BindingFlags . NonPublic ) . GetValue ( null ) ;
25+ }
26+ catch
27+ {
28+ ret = false ;
29+ }
30+
31+ return ret ;
32+ }
33+
1634 public static IEnumerable < object [ ] > Cultures_TestData ( )
1735 {
1836 yield return new object [ ] { "en-US" } ;
@@ -490,13 +508,13 @@ public static IEnumerable<object[]> GetUnicode_TestData()
490508 yield return new object [ ] { "xn--de-jg4avhby1noc0d" , 0 , 21 , "\u30D1 \u30D5 \u30A3 \u30FC \u0064 \u0065 \u30EB \u30F3 \u30D0 " } ;
491509 }
492510
493- [ Fact ]
511+ [ ConditionalFact ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
494512 public static void IcuShouldNotBeLoaded ( )
495513 {
496514 Assert . False ( PlatformDetection . IsIcuGlobalization ) ;
497515 }
498516
499- [ Theory ]
517+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
500518 [ MemberData ( nameof ( Cultures_TestData ) ) ]
501519 public void TestCultureData ( string cultureName )
502520 {
@@ -636,7 +654,7 @@ public void TestCultureData(string cultureName)
636654 Assert . True ( cultureName . Equals ( ci . CompareInfo . Name , StringComparison . OrdinalIgnoreCase ) ) ;
637655 }
638656
639- [ Theory ]
657+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
640658 [ MemberData ( nameof ( Cultures_TestData ) ) ]
641659 public void SetCultureData ( string cultureName )
642660 {
@@ -652,13 +670,13 @@ public void SetCultureData(string cultureName)
652670 Assert . Throws < ArgumentOutOfRangeException > ( ( ) => ci . DateTimeFormat . Calendar = new TaiwanCalendar ( ) ) ;
653671 }
654672
655- [ Fact ]
673+ [ ConditionalFact ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
656674 public void TestEnum ( )
657675 {
658676 Assert . Equal ( new CultureInfo [ 1 ] { CultureInfo . InvariantCulture } , CultureInfo . GetCultures ( CultureTypes . AllCultures ) ) ;
659677 }
660678
661- [ Theory ]
679+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
662680 [ MemberData ( nameof ( Cultures_TestData ) ) ]
663681 public void TestSortVersion ( string cultureName )
664682 {
@@ -670,7 +688,7 @@ public void TestSortVersion(string cultureName)
670688 Assert . Equal ( version , new CultureInfo ( cultureName ) . CompareInfo . Version ) ;
671689 }
672690
673- [ Theory ]
691+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
674692 [ InlineData ( 0 , 0 ) ]
675693 [ InlineData ( 1 , 2 ) ]
676694 [ InlineData ( 100_000 , 200_000 ) ]
@@ -683,7 +701,7 @@ public void TestGetSortKeyLength_Valid(int inputLength, int expectedSortKeyLengt
683701 Assert . Equal ( expectedSortKeyLength , CultureInfo . InvariantCulture . CompareInfo . GetSortKeyLength ( dummySpan ) ) ;
684702 }
685703
686- [ Theory ]
704+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
687705 [ InlineData ( 0x4000_0000 ) ]
688706 [ InlineData ( int . MaxValue ) ]
689707 public unsafe void TestGetSortKeyLength_OverlongArgument ( int inputLength )
@@ -698,7 +716,7 @@ public unsafe void TestGetSortKeyLength_OverlongArgument(int inputLength)
698716 } ) ;
699717 }
700718
701- [ Theory ]
719+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
702720 [ InlineData ( "Hello" , CompareOptions . None , "Hello" ) ]
703721 [ InlineData ( "Hello" , CompareOptions . IgnoreWidth , "Hello" ) ]
704722 [ InlineData ( "Hello" , CompareOptions . IgnoreCase , "HELLO" ) ]
@@ -741,7 +759,7 @@ public unsafe void TestSortKey_FromSpan(string input, CompareOptions options, st
741759 }
742760 }
743761
744- [ Fact ]
762+ [ ConditionalFact ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
745763 public void TestSortKey_ZeroWeightCodePoints ( )
746764 {
747765 // In the invariant globalization mode, there's no such thing as a zero-weight code point,
@@ -753,7 +771,7 @@ public void TestSortKey_ZeroWeightCodePoints()
753771 Assert . NotEqual ( 0 , SortKey . Compare ( sortKeyForEmptyString , sortKeyForZeroWidthJoiner ) ) ;
754772 }
755773
756- [ Theory ]
774+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
757775 [ InlineData ( "" , "" , 0 ) ]
758776 [ InlineData ( "" , "not-empty" , - 1 ) ]
759777 [ InlineData ( "not-empty" , "" , 1 ) ]
@@ -794,7 +812,7 @@ private static StringComparison GetStringComparison(CompareOptions options)
794812 return sc ;
795813 }
796814
797- [ Theory ]
815+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
798816 [ MemberData ( nameof ( IndexOf_TestData ) ) ]
799817 public void TestIndexOf ( string source , string value , int startIndex , int count , CompareOptions options , int result )
800818 {
@@ -841,7 +859,7 @@ static void TestCore(CompareInfo compareInfo, string source, string value, int s
841859 }
842860 }
843861
844- [ Theory ]
862+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
845863 [ MemberData ( nameof ( LastIndexOf_TestData ) ) ]
846864 public void TestLastIndexOf ( string source , string value , int startIndex , int count , CompareOptions options , int result )
847865 {
@@ -901,7 +919,7 @@ static void TestCore(CompareInfo compareInfo, string source, string value, int s
901919 }
902920 }
903921
904- [ Theory ]
922+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
905923 [ MemberData ( nameof ( IsPrefix_TestData ) ) ]
906924 public void TestIsPrefix ( string source , string value , CompareOptions options , bool result )
907925 {
@@ -936,7 +954,7 @@ public void TestIsPrefix(string source, string value, CompareOptions options, bo
936954 }
937955 }
938956
939- [ Theory ]
957+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
940958 [ MemberData ( nameof ( IsSuffix_TestData ) ) ]
941959 public void TestIsSuffix ( string source , string value , CompareOptions options , bool result )
942960 {
@@ -971,7 +989,7 @@ public void TestIsSuffix(string source, string value, CompareOptions options, bo
971989 }
972990 }
973991
974- [ Theory ]
992+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
975993 [ InlineData ( "" , false ) ]
976994 [ InlineData ( 'x' , true ) ]
977995 [ InlineData ( '\ud800 ' , true ) ] // standalone high surrogate
@@ -988,7 +1006,7 @@ public void TestIsSortable(object sourceObj, bool expectedResult)
9881006 }
9891007 }
9901008
991- [ Theory ]
1009+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
9921010 [ MemberData ( nameof ( Compare_TestData ) ) ]
9931011 public void TestCompare ( string source , string value , CompareOptions options , int result )
9941012 {
@@ -1019,7 +1037,7 @@ public void TestCompare(string source, string value, CompareOptions options, int
10191037 }
10201038
10211039
1022- [ Theory ]
1040+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
10231041 [ MemberData ( nameof ( ToLower_TestData ) ) ]
10241042 public void TestToLower ( string upper , string lower , bool result )
10251043 {
@@ -1030,7 +1048,7 @@ public void TestToLower(string upper, string lower, bool result)
10301048 }
10311049 }
10321050
1033- [ Theory ]
1051+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
10341052 [ MemberData ( nameof ( ToUpper_TestData ) ) ]
10351053 public void TestToUpper ( string lower , string upper , bool result )
10361054 {
@@ -1041,7 +1059,7 @@ public void TestToUpper(string lower, string upper, bool result)
10411059 }
10421060 }
10431061
1044- [ Theory ]
1062+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
10451063 [ InlineData ( "" , NormalizationForm . FormC ) ]
10461064 [ InlineData ( "\uFB01 " , NormalizationForm . FormC ) ]
10471065 [ InlineData ( "\uFB01 " , NormalizationForm . FormD ) ]
@@ -1063,7 +1081,7 @@ public void TestNormalization(string s, NormalizationForm form)
10631081 Assert . Equal ( s , s . Normalize ( form ) ) ;
10641082 }
10651083
1066- [ Theory ]
1084+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
10671085 [ MemberData ( nameof ( GetAscii_TestData ) ) ]
10681086 public void GetAscii ( string unicode , int index , int count , string expected )
10691087 {
@@ -1078,7 +1096,7 @@ public void GetAscii(string unicode, int index, int count, string expected)
10781096 Assert . Equal ( expected , new IdnMapping ( ) . GetAscii ( unicode , index , count ) ) ;
10791097 }
10801098
1081- [ Theory ]
1099+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
10821100 [ MemberData ( nameof ( GetUnicode_TestData ) ) ]
10831101 public void GetUnicode ( string ascii , int index , int count , string expected )
10841102 {
@@ -1093,7 +1111,7 @@ public void GetUnicode(string ascii, int index, int count, string expected)
10931111 Assert . Equal ( expected , new IdnMapping ( ) . GetUnicode ( ascii , index , count ) ) ;
10941112 }
10951113
1096- [ Fact ]
1114+ [ ConditionalFact ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
10971115 public void TestHashing ( )
10981116 {
10991117 StringComparer cultureComparer = StringComparer . Create ( CultureInfo . GetCultureInfo ( "tr-TR" ) , true ) ;
@@ -1102,7 +1120,7 @@ public void TestHashing()
11021120 Assert . Equal ( ordinalComparer . GetHashCode ( turkishString ) , cultureComparer . GetHashCode ( turkishString ) ) ;
11031121 }
11041122
1105- [ Theory ]
1123+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
11061124 [ InlineData ( 'a' , 'A' , 'a' ) ]
11071125 [ InlineData ( 'A' , 'A' , 'a' ) ]
11081126 [ InlineData ( 'i' , 'I' , 'i' ) ] // to verify that we don't special-case the Turkish I in the invariant globalization mode
@@ -1121,7 +1139,7 @@ public void TestRune(int original, int expectedToUpper, int expectedToLower)
11211139 Assert . Equal ( expectedToLower , Rune . ToLower ( originalRune , CultureInfo . GetCultureInfo ( "tr-TR" ) ) . Value ) ;
11221140 }
11231141
1124- [ Fact ]
1142+ [ ConditionalFact ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
11251143 public void TestGetCultureInfo_PredefinedOnly_ReturnsSame ( )
11261144 {
11271145 Assert . Equal ( CultureInfo . GetCultureInfo ( "en-US" ) , CultureInfo . GetCultureInfo ( "en-US" , predefinedOnly : true ) ) ;
0 commit comments