2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System . Buffers ;
5
+ using System . Reflection ;
5
6
using System . Buffers . Binary ;
6
7
using System . Collections . Generic ;
7
8
using System . IO ;
@@ -13,6 +14,23 @@ namespace System.Globalization.Tests
13
14
{
14
15
public class InvariantModeTests
15
16
{
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
+
16
34
public static IEnumerable < object [ ] > Cultures_TestData ( )
17
35
{
18
36
yield return new object [ ] { "en-US" } ;
@@ -490,13 +508,13 @@ public static IEnumerable<object[]> GetUnicode_TestData()
490
508
yield return new object [ ] { "xn--de-jg4avhby1noc0d" , 0 , 21 , "\u30D1 \u30D5 \u30A3 \u30FC \u0064 \u0065 \u30EB \u30F3 \u30D0 " } ;
491
509
}
492
510
493
- [ Fact ]
511
+ [ ConditionalFact ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
494
512
public static void IcuShouldNotBeLoaded ( )
495
513
{
496
514
Assert . False ( PlatformDetection . IsIcuGlobalization ) ;
497
515
}
498
516
499
- [ Theory ]
517
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
500
518
[ MemberData ( nameof ( Cultures_TestData ) ) ]
501
519
public void TestCultureData ( string cultureName )
502
520
{
@@ -636,7 +654,7 @@ public void TestCultureData(string cultureName)
636
654
Assert . True ( cultureName . Equals ( ci . CompareInfo . Name , StringComparison . OrdinalIgnoreCase ) ) ;
637
655
}
638
656
639
- [ Theory ]
657
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
640
658
[ MemberData ( nameof ( Cultures_TestData ) ) ]
641
659
public void SetCultureData ( string cultureName )
642
660
{
@@ -652,13 +670,13 @@ public void SetCultureData(string cultureName)
652
670
Assert . Throws < ArgumentOutOfRangeException > ( ( ) => ci . DateTimeFormat . Calendar = new TaiwanCalendar ( ) ) ;
653
671
}
654
672
655
- [ Fact ]
673
+ [ ConditionalFact ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
656
674
public void TestEnum ( )
657
675
{
658
676
Assert . Equal ( new CultureInfo [ 1 ] { CultureInfo . InvariantCulture } , CultureInfo . GetCultures ( CultureTypes . AllCultures ) ) ;
659
677
}
660
678
661
- [ Theory ]
679
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
662
680
[ MemberData ( nameof ( Cultures_TestData ) ) ]
663
681
public void TestSortVersion ( string cultureName )
664
682
{
@@ -670,7 +688,7 @@ public void TestSortVersion(string cultureName)
670
688
Assert . Equal ( version , new CultureInfo ( cultureName ) . CompareInfo . Version ) ;
671
689
}
672
690
673
- [ Theory ]
691
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
674
692
[ InlineData ( 0 , 0 ) ]
675
693
[ InlineData ( 1 , 2 ) ]
676
694
[ InlineData ( 100_000 , 200_000 ) ]
@@ -683,7 +701,7 @@ public void TestGetSortKeyLength_Valid(int inputLength, int expectedSortKeyLengt
683
701
Assert . Equal ( expectedSortKeyLength , CultureInfo . InvariantCulture . CompareInfo . GetSortKeyLength ( dummySpan ) ) ;
684
702
}
685
703
686
- [ Theory ]
704
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
687
705
[ InlineData ( 0x4000_0000 ) ]
688
706
[ InlineData ( int . MaxValue ) ]
689
707
public unsafe void TestGetSortKeyLength_OverlongArgument ( int inputLength )
@@ -698,7 +716,7 @@ public unsafe void TestGetSortKeyLength_OverlongArgument(int inputLength)
698
716
} ) ;
699
717
}
700
718
701
- [ Theory ]
719
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
702
720
[ InlineData ( "Hello" , CompareOptions . None , "Hello" ) ]
703
721
[ InlineData ( "Hello" , CompareOptions . IgnoreWidth , "Hello" ) ]
704
722
[ InlineData ( "Hello" , CompareOptions . IgnoreCase , "HELLO" ) ]
@@ -741,7 +759,7 @@ public unsafe void TestSortKey_FromSpan(string input, CompareOptions options, st
741
759
}
742
760
}
743
761
744
- [ Fact ]
762
+ [ ConditionalFact ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
745
763
public void TestSortKey_ZeroWeightCodePoints ( )
746
764
{
747
765
// In the invariant globalization mode, there's no such thing as a zero-weight code point,
@@ -753,7 +771,7 @@ public void TestSortKey_ZeroWeightCodePoints()
753
771
Assert . NotEqual ( 0 , SortKey . Compare ( sortKeyForEmptyString , sortKeyForZeroWidthJoiner ) ) ;
754
772
}
755
773
756
- [ Theory ]
774
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
757
775
[ InlineData ( "" , "" , 0 ) ]
758
776
[ InlineData ( "" , "not-empty" , - 1 ) ]
759
777
[ InlineData ( "not-empty" , "" , 1 ) ]
@@ -794,7 +812,7 @@ private static StringComparison GetStringComparison(CompareOptions options)
794
812
return sc ;
795
813
}
796
814
797
- [ Theory ]
815
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
798
816
[ MemberData ( nameof ( IndexOf_TestData ) ) ]
799
817
public void TestIndexOf ( string source , string value , int startIndex , int count , CompareOptions options , int result )
800
818
{
@@ -841,7 +859,7 @@ static void TestCore(CompareInfo compareInfo, string source, string value, int s
841
859
}
842
860
}
843
861
844
- [ Theory ]
862
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
845
863
[ MemberData ( nameof ( LastIndexOf_TestData ) ) ]
846
864
public void TestLastIndexOf ( string source , string value , int startIndex , int count , CompareOptions options , int result )
847
865
{
@@ -901,7 +919,7 @@ static void TestCore(CompareInfo compareInfo, string source, string value, int s
901
919
}
902
920
}
903
921
904
- [ Theory ]
922
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
905
923
[ MemberData ( nameof ( IsPrefix_TestData ) ) ]
906
924
public void TestIsPrefix ( string source , string value , CompareOptions options , bool result )
907
925
{
@@ -936,7 +954,7 @@ public void TestIsPrefix(string source, string value, CompareOptions options, bo
936
954
}
937
955
}
938
956
939
- [ Theory ]
957
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
940
958
[ MemberData ( nameof ( IsSuffix_TestData ) ) ]
941
959
public void TestIsSuffix ( string source , string value , CompareOptions options , bool result )
942
960
{
@@ -971,7 +989,7 @@ public void TestIsSuffix(string source, string value, CompareOptions options, bo
971
989
}
972
990
}
973
991
974
- [ Theory ]
992
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
975
993
[ InlineData ( "" , false ) ]
976
994
[ InlineData ( 'x' , true ) ]
977
995
[ InlineData ( '\ud800 ' , true ) ] // standalone high surrogate
@@ -988,7 +1006,7 @@ public void TestIsSortable(object sourceObj, bool expectedResult)
988
1006
}
989
1007
}
990
1008
991
- [ Theory ]
1009
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
992
1010
[ MemberData ( nameof ( Compare_TestData ) ) ]
993
1011
public void TestCompare ( string source , string value , CompareOptions options , int result )
994
1012
{
@@ -1019,7 +1037,7 @@ public void TestCompare(string source, string value, CompareOptions options, int
1019
1037
}
1020
1038
1021
1039
1022
- [ Theory ]
1040
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
1023
1041
[ MemberData ( nameof ( ToLower_TestData ) ) ]
1024
1042
public void TestToLower ( string upper , string lower , bool result )
1025
1043
{
@@ -1030,7 +1048,7 @@ public void TestToLower(string upper, string lower, bool result)
1030
1048
}
1031
1049
}
1032
1050
1033
- [ Theory ]
1051
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
1034
1052
[ MemberData ( nameof ( ToUpper_TestData ) ) ]
1035
1053
public void TestToUpper ( string lower , string upper , bool result )
1036
1054
{
@@ -1041,7 +1059,7 @@ public void TestToUpper(string lower, string upper, bool result)
1041
1059
}
1042
1060
}
1043
1061
1044
- [ Theory ]
1062
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
1045
1063
[ InlineData ( "" , NormalizationForm . FormC ) ]
1046
1064
[ InlineData ( "\uFB01 " , NormalizationForm . FormC ) ]
1047
1065
[ InlineData ( "\uFB01 " , NormalizationForm . FormD ) ]
@@ -1063,7 +1081,7 @@ public void TestNormalization(string s, NormalizationForm form)
1063
1081
Assert . Equal ( s , s . Normalize ( form ) ) ;
1064
1082
}
1065
1083
1066
- [ Theory ]
1084
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
1067
1085
[ MemberData ( nameof ( GetAscii_TestData ) ) ]
1068
1086
public void GetAscii ( string unicode , int index , int count , string expected )
1069
1087
{
@@ -1078,7 +1096,7 @@ public void GetAscii(string unicode, int index, int count, string expected)
1078
1096
Assert . Equal ( expected , new IdnMapping ( ) . GetAscii ( unicode , index , count ) ) ;
1079
1097
}
1080
1098
1081
- [ Theory ]
1099
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
1082
1100
[ MemberData ( nameof ( GetUnicode_TestData ) ) ]
1083
1101
public void GetUnicode ( string ascii , int index , int count , string expected )
1084
1102
{
@@ -1093,7 +1111,7 @@ public void GetUnicode(string ascii, int index, int count, string expected)
1093
1111
Assert . Equal ( expected , new IdnMapping ( ) . GetUnicode ( ascii , index , count ) ) ;
1094
1112
}
1095
1113
1096
- [ Fact ]
1114
+ [ ConditionalFact ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
1097
1115
public void TestHashing ( )
1098
1116
{
1099
1117
StringComparer cultureComparer = StringComparer . Create ( CultureInfo . GetCultureInfo ( "tr-TR" ) , true ) ;
@@ -1102,7 +1120,7 @@ public void TestHashing()
1102
1120
Assert . Equal ( ordinalComparer . GetHashCode ( turkishString ) , cultureComparer . GetHashCode ( turkishString ) ) ;
1103
1121
}
1104
1122
1105
- [ Theory ]
1123
+ [ ConditionalTheory ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
1106
1124
[ InlineData ( 'a' , 'A' , 'a' ) ]
1107
1125
[ InlineData ( 'A' , 'A' , 'a' ) ]
1108
1126
[ 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)
1121
1139
Assert . Equal ( expectedToLower , Rune . ToLower ( originalRune , CultureInfo . GetCultureInfo ( "tr-TR" ) ) . Value ) ;
1122
1140
}
1123
1141
1124
- [ Fact ]
1142
+ [ ConditionalFact ( nameof ( PredefinedCulturesOnlyIsDisabled ) ) ]
1125
1143
public void TestGetCultureInfo_PredefinedOnly_ReturnsSame ( )
1126
1144
{
1127
1145
Assert . Equal ( CultureInfo . GetCultureInfo ( "en-US" ) , CultureInfo . GetCultureInfo ( "en-US" , predefinedOnly : true ) ) ;
0 commit comments