77
88namespace System . Globalization . Tests
99{
10- public class CompareInfoIsPrefixTests
10+ public class CompareInfoIsPrefixTests : CompareInfoTestsBase
1111 {
12- private static CompareInfo s_invariantCompare = CultureInfo . InvariantCulture . CompareInfo ;
13- private static CompareInfo s_germanCompare = new CultureInfo ( "de-DE" ) . CompareInfo ;
14- private static CompareInfo s_hungarianCompare = new CultureInfo ( "hu-HU" ) . CompareInfo ;
15- private static CompareInfo s_turkishCompare = new CultureInfo ( "tr-TR" ) . CompareInfo ;
16- private static CompareInfo s_frenchCompare = new CultureInfo ( "fr-FR" ) . CompareInfo ;
17-
1812 public static IEnumerable < object [ ] > IsPrefix_TestData ( )
1913 {
2014 // Empty strings
@@ -31,7 +25,8 @@ public static IEnumerable<object[]> IsPrefix_TestData()
3125 yield return new object [ ] { s_invariantCompare , "dzsdzsfoobar" , "ddzsf" , CompareOptions . Ordinal , false , 0 } ;
3226 yield return new object [ ] { s_hungarianCompare , "dzsdzsfoobar" , "ddzsf" , CompareOptions . Ordinal , false , 0 } ;
3327 yield return new object [ ] { s_invariantCompare , "dz" , "d" , CompareOptions . None , true , 1 } ;
34- yield return new object [ ] { s_hungarianCompare , "dz" , "d" , CompareOptions . None , false , 0 } ;
28+ if ( ! PlatformDetection . IsHybridGlobalizationOnBrowser )
29+ yield return new object [ ] { s_hungarianCompare , "dz" , "d" , CompareOptions . None , false , 0 } ;
3530 yield return new object [ ] { s_hungarianCompare , "dz" , "d" , CompareOptions . Ordinal , true , 1 } ;
3631
3732 // Turkish
@@ -56,7 +51,7 @@ public static IEnumerable<object[]> IsPrefix_TestData()
5651 yield return new object [ ] { s_invariantCompare , "\u00C0 nimal" , "a\u0300 " , CompareOptions . Ordinal , false , 0 } ;
5752 yield return new object [ ] { s_invariantCompare , "\u00C0 nimal" , "a\u0300 " , CompareOptions . OrdinalIgnoreCase , false , 0 } ;
5853 yield return new object [ ] { s_invariantCompare , "FooBar" , "Foo\u0400 Bar" , CompareOptions . Ordinal , false , 0 } ;
59- yield return new object [ ] { s_invariantCompare , "FooBA\u0300 R" , "FooB\u00C0 R" , CompareOptions . IgnoreNonSpace , true , 7 } ;
54+ yield return new object [ ] { s_invariantCompare , "FooBA\u0300 R" , "FooB\u00C0 R" , supportedIgnoreNonSpaceOption , true , 7 } ;
6055 yield return new object [ ] { s_invariantCompare , "o\u0308 " , "o" , CompareOptions . None , false , 0 } ;
6156 yield return new object [ ] { s_invariantCompare , "o\u0308 " , "o" , CompareOptions . Ordinal , true , 1 } ;
6257 yield return new object [ ] { s_invariantCompare , "o\u0000 \u0308 " , "o" , CompareOptions . None , true , 1 } ;
@@ -76,42 +71,57 @@ public static IEnumerable<object[]> IsPrefix_TestData()
7671 yield return new object [ ] { s_invariantCompare , "\uD800 \uD800 " , "\uD800 \uD800 " , CompareOptions . None , true , 2 } ;
7772
7873 // Ignore symbols
79- yield return new object [ ] { s_invariantCompare , "Test's can be interesting" , "Tests" , CompareOptions . IgnoreSymbols , true , 6 } ;
80- yield return new object [ ] { s_invariantCompare , "Test's can be interesting" , "Tests" , CompareOptions . None , false , 0 } ;
74+ if ( ! PlatformDetection . IsHybridGlobalizationOnBrowser )
75+ {
76+ yield return new object [ ] { s_invariantCompare , "Test's can be interesting" , "Tests" , CompareOptions . IgnoreSymbols , true , 6 } ;
77+ yield return new object [ ] { s_invariantCompare , "Test's can be interesting" , "Tests" , CompareOptions . None , false , 0 } ;
78+ }
8179
8280 // Platform differences
83- bool useNls = PlatformDetection . IsNlsGlobalization ;
84- if ( useNls )
81+ // in HybridGlobalization on Browser we use TextEncoder that is not supported for v8 and the manual decoding works like NLS
82+ bool behavesLikeNls = PlatformDetection . IsNlsGlobalization ||
83+ ( PlatformDetection . IsHybridGlobalizationOnBrowser && ! PlatformDetection . IsBrowserDomSupportedOrNodeJS ) ;
84+ if ( behavesLikeNls )
8585 {
86- yield return new object [ ] { s_hungarianCompare , "dzsdzsfoobar" , "ddzsf" , CompareOptions . None , true , 7 } ;
87- yield return new object [ ] { s_invariantCompare , "''Tests" , "Tests" , CompareOptions . IgnoreSymbols , true , 7 } ;
88- yield return new object [ ] { s_frenchCompare , "\u0153 " , "oe" , CompareOptions . None , true , 1 } ;
86+ if ( ! PlatformDetection . IsHybridGlobalizationOnBrowser )
87+ {
88+ yield return new object [ ] { s_hungarianCompare , "dzsdzsfoobar" , "ddzsf" , CompareOptions . None , true , 7 } ;
89+ yield return new object [ ] { s_invariantCompare , "''Tests" , "Tests" , CompareOptions . IgnoreSymbols , true , 7 } ;
90+ yield return new object [ ] { s_frenchCompare , "\u0153 " , "oe" , CompareOptions . None , true , 1 } ;
91+ }
8992 yield return new object [ ] { s_invariantCompare , "\uD800 \uDC00 " , "\uD800 " , CompareOptions . None , true , 1 } ;
9093 yield return new object [ ] { s_invariantCompare , "\uD800 \uDC00 " , "\uD800 " , CompareOptions . IgnoreCase , true , 1 } ;
9194 }
9295 else
9396 {
9497 yield return new object [ ] { s_hungarianCompare , "dzsdzsfoobar" , "ddzsf" , CompareOptions . None , false , 0 } ;
95- yield return new object [ ] { s_invariantCompare , "''Tests" , "Tests" , CompareOptions . IgnoreSymbols , false , 0 } ;
98+ if ( ! PlatformDetection . IsHybridGlobalizationOnBrowser )
99+ yield return new object [ ] { s_invariantCompare , "''Tests" , "Tests" , CompareOptions . IgnoreSymbols , false , 0 } ;
96100 yield return new object [ ] { s_frenchCompare , "\u0153 " , "oe" , CompareOptions . None , false , 0 } ;
97101 yield return new object [ ] { s_invariantCompare , "\uD800 \uDC00 " , "\uD800 " , CompareOptions . None , false , 0 } ;
98102 yield return new object [ ] { s_invariantCompare , "\uD800 \uDC00 " , "\uD800 " , CompareOptions . IgnoreCase , false , 0 } ;
99103 }
100104
101105 // ICU bugs
102106 // UInt16 overflow: https://unicode-org.atlassian.net/browse/ICU-20832 fixed in https://github.com/unicode-org/icu/pull/840 (ICU 65)
103- if ( useNls || PlatformDetection . ICUVersion . Major >= 65 )
107+ if ( PlatformDetection . IsNlsGlobalization || PlatformDetection . ICUVersion . Major >= 65 )
104108 {
105109 yield return new object [ ] { s_frenchCompare , "b" , new string ( 'a' , UInt16 . MaxValue + 1 ) , CompareOptions . None , false , 0 } ;
106110 }
107111
108112 // Prefixes where matched length does not equal value string length
109- yield return new object [ ] { s_invariantCompare , "dzxyz" , "\u01F3 " , CompareOptions . IgnoreNonSpace , true , 2 } ;
110- yield return new object [ ] { s_invariantCompare , "\u01F3 xyz" , "dz" , CompareOptions . IgnoreNonSpace , true , 1 } ;
111- yield return new object [ ] { s_germanCompare , "Strasse xyz" , "stra\u00DF e" , CompareOptions . IgnoreCase | CompareOptions . IgnoreNonSpace , true , 7 } ;
112- yield return new object [ ] { s_germanCompare , "Strasse xyz" , "xtra\u00DF e" , CompareOptions . IgnoreCase | CompareOptions . IgnoreNonSpace , false , 0 } ;
113- yield return new object [ ] { s_germanCompare , "stra\u00DF e xyz" , "Strasse" , CompareOptions . IgnoreCase | CompareOptions . IgnoreNonSpace , true , 6 } ;
114- yield return new object [ ] { s_germanCompare , "stra\u00DF e xyz" , "Xtrasse" , CompareOptions . IgnoreCase | CompareOptions . IgnoreNonSpace , false , 0 } ;
113+ if ( ! PlatformDetection . IsHybridGlobalizationOnBrowser )
114+ {
115+ yield return new object [ ] { s_invariantCompare , "dzxyz" , "\u01F3 " , supportedIgnoreNonSpaceOption , true , 2 } ;
116+ yield return new object [ ] { s_invariantCompare , "\u01F3 xyz" , "dz" , supportedIgnoreNonSpaceOption , true , 1 } ;
117+ }
118+ if ( ! PlatformDetection . IsHybridGlobalizationOnBrowser )
119+ {
120+ yield return new object [ ] { s_germanCompare , "Strasse xyz" , "stra\u00DF e" , supportedIgnoreCaseIgnoreNonSpaceOptions , true , 7 } ;
121+ yield return new object [ ] { s_germanCompare , "stra\u00DF e xyz" , "Strasse" , supportedIgnoreCaseIgnoreNonSpaceOptions , true , 6 } ;
122+ }
123+ yield return new object [ ] { s_germanCompare , "Strasse xyz" , "xtra\u00DF e" , supportedIgnoreCaseIgnoreNonSpaceOptions , false , 0 } ;
124+ yield return new object [ ] { s_germanCompare , "stra\u00DF e xyz" , "Xtrasse" , supportedIgnoreCaseIgnoreNonSpaceOptions , false , 0 } ;
115125 }
116126
117127 [ Theory ]
@@ -140,8 +150,11 @@ public void IsPrefix(CompareInfo compareInfo, string source, string value, Compa
140150 valueBoundedMemory . MakeReadonly ( ) ;
141151
142152 Assert . Equal ( expected , compareInfo . IsPrefix ( sourceBoundedMemory . Span , valueBoundedMemory . Span , options ) ) ;
143- Assert . Equal ( expected , compareInfo . IsPrefix ( sourceBoundedMemory . Span , valueBoundedMemory . Span , options , out int actualMatchLength ) ) ;
144- Assert . Equal ( expectedMatchLength , actualMatchLength ) ;
153+ if ( ! PlatformDetection . IsHybridGlobalizationOnBrowser )
154+ {
155+ Assert . Equal ( expected , compareInfo . IsPrefix ( sourceBoundedMemory . Span , valueBoundedMemory . Span , options , out int actualMatchLength ) ) ;
156+ Assert . Equal ( expectedMatchLength , actualMatchLength ) ;
157+ }
145158 }
146159
147160 [ Fact ]
@@ -150,7 +163,7 @@ public void IsPrefix_UnassignedUnicode()
150163 bool result = PlatformDetection . IsNlsGlobalization ? true : false ;
151164 int expectedMatchLength = ( result ) ? 6 : 0 ;
152165 IsPrefix ( s_invariantCompare , "FooBar" , "Foo\uFFFF Bar" , CompareOptions . None , result , expectedMatchLength ) ;
153- IsPrefix ( s_invariantCompare , "FooBar" , "Foo\uFFFF Bar" , CompareOptions . IgnoreNonSpace , result , expectedMatchLength ) ;
166+ IsPrefix ( s_invariantCompare , "FooBar" , "Foo\uFFFF Bar" , supportedIgnoreNonSpaceOption , result , expectedMatchLength ) ;
154167 }
155168
156169 [ Fact ]
0 commit comments