1
+ // Copyright (c) Microsoft. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ using System ;
5
+ using System . Globalization ;
6
+ using Xunit ;
7
+
8
+ namespace System . Globalization . Tests
9
+ {
10
+ public class CompareInfoTest
11
+ {
12
+ [ Fact ]
13
+ [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
14
+ public void TestCompareInfo ( )
15
+ {
16
+ CompareInfo ciENG = CompareInfo . GetCompareInfo ( "en-US" ) ;
17
+ CompareInfo ciFR = CompareInfo . GetCompareInfo ( "fr-FR" ) ;
18
+
19
+ Assert . True ( ciENG . Name . Equals ( "en-US" , StringComparison . CurrentCultureIgnoreCase ) ) ;
20
+ Assert . NotEqual ( ciENG . GetHashCode ( ) , ciFR . GetHashCode ( ) ) ;
21
+ Assert . NotEqual ( ciENG , ciFR ) ;
22
+ }
23
+
24
+ [ Fact ]
25
+ [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
26
+ public void CompareInfoIndexTest1 ( )
27
+ {
28
+ // Creates CompareInfo for the InvariantCulture.
29
+ CompareInfo myComp = CultureInfo . InvariantCulture . CompareInfo ;
30
+
31
+ // iS is the starting index of the substring.
32
+ int iS = 8 ;
33
+ // iL is the length of the substring.
34
+ int iL = 18 ;
35
+
36
+ // Searches for the ligature Æ.
37
+ String myStr = "Is AE or ae the same as \u00C6 or \u00E6 ?" ;
38
+
39
+ Assert . Equal ( myComp . IndexOf ( myStr , "AE" , iS , iL ) , 24 ) ;
40
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "AE" , iS + iL - 1 , iL ) , 24 ) ;
41
+
42
+ Assert . Equal ( myComp . IndexOf ( myStr , "ae" , iS , iL ) , 9 ) ;
43
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "ae" , iS + iL - 1 , iL ) , 9 ) ;
44
+
45
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00C6 ' , iS , iL ) , 24 ) ;
46
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00C6 ' , iS + iL - 1 , iL ) , 24 ) ;
47
+
48
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00E6 ' , iS , iL ) , 9 ) ;
49
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00E6 ' , iS + iL - 1 , iL ) , 9 ) ;
50
+
51
+ Assert . Equal ( myComp . IndexOf ( myStr , "AE" , iS , iL , CompareOptions . Ordinal ) , - 1 ) ;
52
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "AE" , iS + iL - 1 , iL , CompareOptions . Ordinal ) , - 1 ) ;
53
+
54
+ Assert . Equal ( myComp . IndexOf ( myStr , "ae" , iS , iL , CompareOptions . Ordinal ) , 9 ) ;
55
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "ae" , iS + iL - 1 , iL , CompareOptions . Ordinal ) , 9 ) ;
56
+
57
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00C6 ' , iS , iL , CompareOptions . Ordinal ) , 24 ) ;
58
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00C6 ' , iS + iL - 1 , iL , CompareOptions . Ordinal ) , 24 ) ;
59
+
60
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00E6 ' , iS , iL , CompareOptions . Ordinal ) , - 1 ) ;
61
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00E6 ' , iS + iL - 1 , iL , CompareOptions . Ordinal ) , - 1 ) ;
62
+
63
+ Assert . Equal ( myComp . IndexOf ( myStr , "AE" , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
64
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "AE" , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
65
+
66
+ Assert . Equal ( myComp . IndexOf ( myStr , "ae" , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
67
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "ae" , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
68
+
69
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00C6 ' , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
70
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00C6 ' , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
71
+
72
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00E6 ' , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
73
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00E6 ' , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
74
+ }
75
+
76
+ [ Fact ]
77
+ [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
78
+ public void CompareInfoIndexTest2 ( )
79
+ {
80
+ // Creates CompareInfo for the InvariantCulture.
81
+ CompareInfo myComp = CultureInfo . InvariantCulture . CompareInfo ;
82
+
83
+ // iS is the starting index of the substring.
84
+ int iS = 8 ;
85
+ // iL is the length of the substring.
86
+ int iL = 18 ;
87
+
88
+ // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
89
+ string myStr = "Is \u0055 \u0308 or \u0075 \u0308 the same as \u00DC or \u00FC ?" ;
90
+
91
+ Assert . Equal ( myComp . IndexOf ( myStr , "U\u0308 " , iS , iL ) , 24 ) ;
92
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "U\u0308 " , iS + iL - 1 , iL ) , 24 ) ;
93
+
94
+ Assert . Equal ( myComp . IndexOf ( myStr , "u\u0308 " , iS , iL ) , 9 ) ;
95
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "u\u0308 " , iS + iL - 1 , iL ) , 9 ) ;
96
+
97
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00DC ' , iS , iL ) , 24 ) ;
98
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00DC ' , iS + iL - 1 , iL ) , 24 ) ;
99
+
100
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00FC ' , iS , iL ) , 9 ) ;
101
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00FC ' , iS + iL - 1 , iL ) , 9 ) ;
102
+
103
+ Assert . Equal ( myComp . IndexOf ( myStr , "U\u0308 " , iS , iL , CompareOptions . Ordinal ) , - 1 ) ;
104
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "U\u0308 " , iS + iL - 1 , iL , CompareOptions . Ordinal ) , - 1 ) ;
105
+
106
+ Assert . Equal ( myComp . IndexOf ( myStr , "u\u0308 " , iS , iL , CompareOptions . Ordinal ) , 9 ) ;
107
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "u\u0308 " , iS + iL - 1 , iL , CompareOptions . Ordinal ) , 9 ) ;
108
+
109
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00DC ' , iS , iL , CompareOptions . Ordinal ) , 24 ) ;
110
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00DC ' , iS + iL - 1 , iL , CompareOptions . Ordinal ) , 24 ) ;
111
+
112
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00FC ' , iS , iL , CompareOptions . Ordinal ) , - 1 ) ;
113
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00FC ' , iS + iL - 1 , iL , CompareOptions . Ordinal ) , - 1 ) ;
114
+
115
+ Assert . Equal ( myComp . IndexOf ( myStr , "U\u0308 " , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
116
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "U\u0308 " , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
117
+
118
+ Assert . Equal ( myComp . IndexOf ( myStr , "u\u0308 " , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
119
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "u\u0308 " , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
120
+
121
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00DC ' , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
122
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00DC ' , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
123
+
124
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00FC ' , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
125
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00FC ' , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
126
+ }
127
+ }
128
+ }
0 commit comments