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
+ public void TestCompareInfo ( )
14
+ {
15
+ CompareInfo ciENG = CompareInfo . GetCompareInfo ( "en-US" ) ;
16
+ CompareInfo ciFR = CompareInfo . GetCompareInfo ( "fr-FR" ) ;
17
+
18
+ Assert . True ( ciENG . Name . Equals ( "en-US" , StringComparison . CurrentCultureIgnoreCase ) ) ;
19
+ Assert . NotEqual ( ciENG . GetHashCode ( ) , ciFR . GetHashCode ( ) ) ;
20
+ Assert . NotEqual ( ciENG , ciFR ) ;
21
+ }
22
+
23
+ [ Fact ]
24
+ public void CompareInfoIndexTest1 ( )
25
+ {
26
+ // Creates CompareInfo for the InvariantCulture.
27
+ CompareInfo myComp = CultureInfo . InvariantCulture . CompareInfo ;
28
+
29
+ // iS is the starting index of the substring.
30
+ int iS = 8 ;
31
+ // iL is the length of the substring.
32
+ int iL = 18 ;
33
+
34
+ // Searches for the ligature Æ.
35
+ String myStr = "Is AE or ae the same as \u00C6 or \u00E6 ?" ;
36
+
37
+ Assert . Equal ( myComp . IndexOf ( myStr , "AE" , iS , iL ) , 24 ) ;
38
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "AE" , iS + iL - 1 , iL ) , 24 ) ;
39
+
40
+ Assert . Equal ( myComp . IndexOf ( myStr , "ae" , iS , iL ) , 9 ) ;
41
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "ae" , iS + iL - 1 , iL ) , 9 ) ;
42
+
43
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00C6 ' , iS , iL ) , 24 ) ;
44
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00C6 ' , iS + iL - 1 , iL ) , 24 ) ;
45
+
46
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00E6 ' , iS , iL ) , 9 ) ;
47
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00E6 ' , iS + iL - 1 , iL ) , 9 ) ;
48
+
49
+ Assert . Equal ( myComp . IndexOf ( myStr , "AE" , iS , iL , CompareOptions . Ordinal ) , - 1 ) ;
50
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "AE" , iS + iL - 1 , iL , CompareOptions . Ordinal ) , - 1 ) ;
51
+
52
+ Assert . Equal ( myComp . IndexOf ( myStr , "ae" , iS , iL , CompareOptions . Ordinal ) , 9 ) ;
53
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "ae" , iS + iL - 1 , iL , CompareOptions . Ordinal ) , 9 ) ;
54
+
55
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00C6 ' , iS , iL , CompareOptions . Ordinal ) , 24 ) ;
56
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00C6 ' , iS + iL - 1 , iL , CompareOptions . Ordinal ) , 24 ) ;
57
+
58
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00E6 ' , iS , iL , CompareOptions . Ordinal ) , - 1 ) ;
59
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00E6 ' , iS + iL - 1 , iL , CompareOptions . Ordinal ) , - 1 ) ;
60
+
61
+ Assert . Equal ( myComp . IndexOf ( myStr , "AE" , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
62
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "AE" , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
63
+
64
+ Assert . Equal ( myComp . IndexOf ( myStr , "ae" , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
65
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "ae" , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
66
+
67
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00C6 ' , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
68
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00C6 ' , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
69
+
70
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00E6 ' , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
71
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00E6 ' , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
72
+ }
73
+
74
+ [ Fact ]
75
+ public void CompareInfoIndexTest2 ( )
76
+ {
77
+ // Creates CompareInfo for the InvariantCulture.
78
+ CompareInfo myComp = CultureInfo . InvariantCulture . CompareInfo ;
79
+
80
+ // iS is the starting index of the substring.
81
+ int iS = 8 ;
82
+ // iL is the length of the substring.
83
+ int iL = 18 ;
84
+
85
+ // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
86
+ string myStr = "Is \u0055 \u0308 or \u0075 \u0308 the same as \u00DC or \u00FC ?" ;
87
+
88
+ Assert . Equal ( myComp . IndexOf ( myStr , "U\u0308 " , iS , iL ) , 24 ) ;
89
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "U\u0308 " , iS + iL - 1 , iL ) , 24 ) ;
90
+
91
+ Assert . Equal ( myComp . IndexOf ( myStr , "u\u0308 " , iS , iL ) , 9 ) ;
92
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "u\u0308 " , iS + iL - 1 , iL ) , 9 ) ;
93
+
94
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00DC ' , iS , iL ) , 24 ) ;
95
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00DC ' , iS + iL - 1 , iL ) , 24 ) ;
96
+
97
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00FC ' , iS , iL ) , 9 ) ;
98
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00FC ' , iS + iL - 1 , iL ) , 9 ) ;
99
+
100
+ Assert . Equal ( myComp . IndexOf ( myStr , "U\u0308 " , iS , iL , CompareOptions . Ordinal ) , - 1 ) ;
101
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "U\u0308 " , iS + iL - 1 , iL , CompareOptions . Ordinal ) , - 1 ) ;
102
+
103
+ Assert . Equal ( myComp . IndexOf ( myStr , "u\u0308 " , iS , iL , CompareOptions . Ordinal ) , 9 ) ;
104
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "u\u0308 " , iS + iL - 1 , iL , CompareOptions . Ordinal ) , 9 ) ;
105
+
106
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00DC ' , iS , iL , CompareOptions . Ordinal ) , 24 ) ;
107
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00DC ' , iS + iL - 1 , iL , CompareOptions . Ordinal ) , 24 ) ;
108
+
109
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00FC ' , iS , iL , CompareOptions . Ordinal ) , - 1 ) ;
110
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00FC ' , iS + iL - 1 , iL , CompareOptions . Ordinal ) , - 1 ) ;
111
+
112
+ Assert . Equal ( myComp . IndexOf ( myStr , "U\u0308 " , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
113
+ Assert . Equal ( myComp . LastIndexOf ( myStr , "U\u0308 " , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
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 , '\u00DC ' , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
119
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00DC ' , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
120
+
121
+ Assert . Equal ( myComp . IndexOf ( myStr , '\u00FC ' , iS , iL , CompareOptions . IgnoreCase ) , 9 ) ;
122
+ Assert . Equal ( myComp . LastIndexOf ( myStr , '\u00FC ' , iS + iL - 1 , iL , CompareOptions . IgnoreCase ) , 24 ) ;
123
+ }
124
+ }
125
+ }
0 commit comments