New test.
[mono.git] / mcs / class / corlib / Test / System.Globalization / CompareInfoTest.cs
1 // CompareInfoTest.cs - NUnit Test Cases for the
2 // System.Globalization.CompareInfo class
3 //
4 // Dick Porter <dick@ximian.com>
5 // Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // (C) 2003-2005 Novell, Inc.  http://www.novell.com
8 //
9
10 using NUnit.Framework;
11 using System;
12 using System.Globalization;
13
14 namespace MonoTests.System.Globalization
15 {
16
17 [TestFixture]
18 public class CompareInfoTest : Assertion
19 {
20         static bool doTest = Environment.GetEnvironmentVariable ("MONO_DISABLE_MANAGED_COLLATION") != "yes";
21
22         public CompareInfoTest() {}
23
24         [Test]
25         public void Compare()
26         {
27                 string s1 = "foo";
28                 
29                 AssertEquals ("Compare two empty strings", 0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", ""));
30                 AssertEquals ("Compare string with empty string", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, ""));
31                 AssertEquals ("Compare empty string with string", -1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", s1));
32
33                 AssertEquals ("Compare two empty strings, with 0 offsets", 0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "", 0));
34                 AssertEquals ("Compare string with empty string, with 0 offsets", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, "", 0));
35                 AssertEquals ("Compare empty string with string, with 0 offsets", -1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, s1, 0));
36
37                 AssertEquals ("Compare two empty strings, with 0 offsets and specified lengths", 0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "".Length, "", 0, "".Length));
38                 AssertEquals ("Compare string with empty string, with 0 offsets and specified lengths", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1.Length, "", 0, "".Length));
39                 AssertEquals ("Compare empty string with string, with 0 offsets and specified lengths", -1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "".Length, s1, 0, s1.Length));
40
41                 AssertEquals ("Compare two strings, with offsets == string lengths", 0, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s1.Length, s1, s1.Length));
42                 AssertEquals ("Compare two strings, with first offset == string length", -1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s1.Length, s1, 0));
43                 AssertEquals ("Compare two strings, with second offset == string length", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1, s1.Length));
44
45                 AssertEquals ("Compare two strings, with zero lengths", 0, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, 0, s1, 0, 0));
46                 AssertEquals ("Compare two strings, with first length zero", -1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, 0, s1, 0, s1.Length));
47                 AssertEquals ("Compare strings, with second length zero", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1.Length, s1, 0, 0));
48                 
49         }
50
51         // Culture-sensitive collation tests
52
53         CompareInfo invariant = CultureInfo.InvariantCulture.CompareInfo;
54         CompareInfo french = new CultureInfo ("fr").CompareInfo;
55         CompareInfo japanese = new CultureInfo ("ja").CompareInfo;
56         CompareInfo czech = new CultureInfo ("cs").CompareInfo;
57         CompareInfo hungarian = new CultureInfo ("hu").CompareInfo;
58
59         CompareOptions ignoreCW =
60                 CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase;
61         CompareOptions ignoreCN =
62                 CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase;
63
64         void AssertSortKey (string message, byte [] expected, string test)
65         {
66                 AssertSortKey (message, expected, test, CompareOptions.None);
67         }
68
69         void AssertSortKey (string message, byte [] expected, string test, CompareOptions opt)
70         {
71                 AssertSortKey (message, expected, test, opt, invariant);
72         }
73
74         void AssertSortKey (string message, byte [] expected, string test, CompareOptions opt, CompareInfo ci)
75         {
76                 byte [] actual = ci.GetSortKey (test, opt).KeyData;
77                 AssertEquals (message, expected, actual);
78         }
79
80         void AssertSortKeyLevel5 (string message, byte [] expected, string test)
81         {
82                 byte [] tmp = invariant.GetSortKey (test).KeyData;
83                 int idx = 0;
84                 for (int i = 0; i < 4; i++, idx++)
85                         for (; tmp [idx] != 1; idx++)
86                                 ;
87                 byte [] actual = new byte [tmp.Length - idx];
88                 Array.Copy (tmp, idx, actual, 0, actual.Length);
89                 AssertEquals (message, expected, actual);
90         }
91
92         void AssertCompare (string message, int result, string s1, string s2)
93         {
94                 AssertCompare (message, result, s1, s2, CompareOptions.None);
95         }
96
97         void AssertCompare (string message, int result, string s1, string s2,
98                 CompareOptions opt)
99         {
100                 AssertCompare (message, result, s1, s2, opt, invariant);
101         }
102
103         void AssertCompare (string message, int result, string s1, string s2,
104                 CompareOptions opt, CompareInfo ci)
105         {
106                 int ret = ci.Compare (s1, s2, opt);
107                 if (result == 0)
108                         AssertEquals (message, 0, ret);
109                 else if (result < 0)
110                         Assert (message + String.Format ("(neg: {0})", ret), ret < 0);
111                 else
112                         Assert (message + String.Format ("(pos: {0})", ret), ret > 0);
113         }
114
115         void AssertCompare (string message, int result,
116                 string s1, int idx1, int len1, string s2, int idx2, int len2)
117         {
118                 int ret = invariant.Compare (s1, idx1, len1, s2, idx2, len2);
119                 if (result == 0)
120                         AssertEquals (message, 0, ret);
121                 else if (result < 0)
122                         Assert (message, ret < 0);
123                 else
124                         Assert (message, ret > 0);
125         }
126
127         void AssertCompare (string message, int result,
128                 string s1, int idx1, int len1, string s2, int idx2, int len2,
129                 CompareOptions opt, CompareInfo ci)
130         {
131                 int ret = ci.Compare (s1, idx1, len1, s2, idx2, len2, opt);
132                 if (result == 0)
133                         AssertEquals (message, 0, ret);
134                 else if (result < 0)
135                         Assert (message, ret < 0);
136                 else
137                         Assert (message, ret > 0);
138         }
139
140         void AssertIndexOf (string message, int expected,
141                 string source, char target)
142         {
143                 AssertEquals (message, expected,
144                         invariant.IndexOf (source, target));
145         }
146
147         void AssertIndexOf (string message, int expected, string source,
148                 char target, CompareOptions opt)
149         {
150                 AssertEquals (message, expected,
151                         invariant.IndexOf (source, target, opt));
152         }
153
154         void AssertIndexOf (string message, int expected, string source,
155                 char target, int idx, int len, CompareOptions opt, CompareInfo ci)
156         {
157                 AssertEquals (message, expected,
158                         ci.IndexOf (source, target, idx, len, opt));
159         }
160
161         void AssertIndexOf (string message, int expected,
162                 string source, string target)
163         {
164                 AssertEquals (message, expected,
165                         invariant.IndexOf (source, target));
166         }
167
168         void AssertIndexOf (string message, int expected, string source,
169                 string target, CompareOptions opt)
170         {
171                 AssertEquals (message, expected,
172                         invariant.IndexOf (source, target, opt));
173         }
174
175         void AssertIndexOf (string message, int expected, string source,
176                 string target, int idx, int len, CompareOptions opt, CompareInfo ci)
177         {
178                 AssertEquals (message, expected,
179                         ci.IndexOf (source, target, idx, len, opt));
180         }
181
182         void AssertLastIndexOf (string message, int expected,
183                 string source, char target)
184         {
185                 AssertEquals (message, expected,
186                         invariant.LastIndexOf (source, target));
187         }
188
189         void AssertLastIndexOf (string message, int expected, string source,
190                 char target, CompareOptions opt)
191         {
192                 AssertEquals (message, expected,
193                         invariant.LastIndexOf (source, target, opt));
194         }
195
196         void AssertLastIndexOf (string message, int expected, string source,
197                 char target, int idx, int len)
198         {
199                 AssertEquals (message, expected,
200                         invariant.LastIndexOf (source, target, idx, len));
201         }
202
203         void AssertLastIndexOf (string message, int expected, string source,
204                 char target, int idx, int len, CompareOptions opt, CompareInfo ci)
205         {
206                 AssertEquals (message, expected,
207                         ci.LastIndexOf (source, target, idx, len, opt));
208         }
209
210         void AssertLastIndexOf (string message, int expected,
211                 string source, string target)
212         {
213                 AssertEquals (message, expected,
214                         invariant.LastIndexOf (source, target));
215         }
216
217         void AssertLastIndexOf (string message, int expected, string source,
218                 string target, CompareOptions opt)
219         {
220                 AssertEquals (message, expected,
221                         invariant.LastIndexOf (source, target, opt));
222         }
223
224         void AssertLastIndexOf (string message, int expected, string source,
225                 string target, int idx, int len)
226         {
227                 AssertEquals (message, expected,
228                         invariant.LastIndexOf (source, target, idx, len));
229         }
230
231         void AssertLastIndexOf (string message, int expected, string source,
232                 string target, int idx, int len, CompareOptions opt, CompareInfo ci)
233         {
234                 AssertEquals (message, expected,
235                         ci.LastIndexOf (source, target, idx, len, opt));
236         }
237
238         void AssertIsPrefix (string message, bool expected, string source,
239                 string target)
240         {
241                 Assert (message, expected == invariant.IsPrefix (
242                         source, target));
243         }
244
245         void AssertIsPrefix (string message, bool expected, string source,
246                 string target, CompareOptions opt)
247         {
248                 Assert (message, expected == invariant.IsPrefix (
249                         source, target, opt));
250         }
251
252         void AssertIsSuffix (string message, bool expected, string source,
253                 string target)
254         {
255                 Assert (message, expected == invariant.IsSuffix (
256                         source, target));
257         }
258
259         void AssertIsSuffix (string message, bool expected, string source,
260                 string target, CompareOptions opt)
261         {
262                 Assert (message, expected == invariant.IsSuffix (
263                         source, target, opt));
264         }
265
266         [Test]
267         public void GetSortKey ()
268         {
269                 if (!doTest)
270                         return;
271
272                 // AE == \u00C6
273                 AssertSortKey ("#1", new byte [] {0xE, 2, 0xE, 0x21, 1, 1,
274                         0x12, 0x12, 1, 1, 0}, "AE");
275                 AssertSortKey ("#2", new byte [] {0xE, 2, 0xE, 0x21, 1, 1,
276                         0x12, 0x12, 1, 1, 0}, "\u00C6");
277                 AssertSortKey ("#3", new byte [] {1, 1, 1, 1,
278                         0x80, 7, 6, 0x82, 0}, "-");
279                 AssertSortKey ("#4", new byte [] {1, 1, 1, 1,
280                         0x80, 7, 6, 0x82, 0x80, 7, 6, 0x82, 0}, "--");
281                 AssertSortKey ("#4", new byte [] {0xE, 2, 0xE, 9,
282                         0xE, 0xA, 1, 1, 0x12, 0x12, 0x12, 1, 1, 0x80, 0xB,
283                         6, 0x82, 0x80, 0xF, 6, 0x82, 0}, "A-B-C");
284                 AssertSortKey ("#6", new byte [] {0xE, 2, 1,
285                         0x17, 1, 0x12, 1, 1, 0}, "A\u0304");
286                 AssertSortKey ("#7", new byte [] {0xE, 2, 1,
287                         0x17, 1, 0x12, 1, 1, 0}, "\u0100");
288
289                 // StringSort
290                 AssertSortKey ("#8", new byte [] {
291                         0xE, 2, 6, 0x82, 1, 1, 1, 1, 0},
292                         "a-", CompareOptions.StringSort);
293                 // FIXME: not working (table fix is required)
294 //              AssertSortKey ("#9", new byte [] {
295 //                      0xE, 2, 6, 0x82, 1, 1, 2, 0x3, 1, 1, 0},
296 //                      "a\uFF0D", CompareOptions.StringSort);
297
298                 AssertSortKey ("#10", new byte [] {1, 1, 1, 1, 0}, "\u3007");
299         }
300
301
302         [Test]
303         public void GetSortKeyIgnoreWidth ()
304         {
305                 if (!doTest)
306                         return;
307
308                 AssertSortKey ("#i1", new byte [] {
309                         0xE, 2, 1, 1, 0x13, 1, 1, 0}, "\uFF21");
310                 AssertSortKey ("#i2", new byte [] {
311                         0xE, 2, 1, 1, 0x12, 1, 1, 0}, "\uFF21", CompareOptions.IgnoreWidth);
312                 AssertSortKey ("#i3", new byte [] {
313                         0xE, 2, 1, 1, 0x3, 1, 1, 0}, "\uFF41");
314                 AssertSortKey ("#i4", new byte [] {
315                         0xE, 2, 1, 1, 1, 1, 0}, "\uFF41", CompareOptions.IgnoreWidth);
316         }
317
318         [Test]
319         public void GetSortKeyDiacritical ()
320         {
321                 if (!doTest)
322                         return;
323
324                 AssertSortKey ("#i1", new byte [] {
325                         0xE, 0x21, 1, 0xE, 1, 1, 1, 0}, "e\u0301");
326                 AssertSortKey ("#i2", new byte [] {
327                         0xE, 0x21, 1, 0x12, 1, 1, 1, 0}, "e\u0302");
328                 AssertSortKey ("#i3", new byte [] {
329                         0xE, 0x21, 1, 0x13, 1, 1, 1, 0}, "e\u0308");
330                 AssertSortKey ("#i4", new byte [] {
331                         0xE, 0x21, 1, 0x1F, 1, 1, 1, 0}, "e\u0308\u0301");
332                 // FIXME: not working (table fix is required)
333 //              AssertSortKey ("#i5", new byte [] {
334 //                      0xE, 0x21, 1, 0x16, 1, 1, 1, 0}, "e\u0344");
335                 AssertSortKey ("#i6", new byte [] {
336                         0x22, 2, 1, 0xE, 1, 1, 0xC4, 0xFF, 2, 0xFF, 0xFF, 1, 0}, "\u3041\u0301");
337                 AssertSortKey ("#i7", new byte [] {
338                         0xC, 0x21, 1, 0xE, 1, 1, 1, 0}, "1\u0301");
339                 AssertSortKey ("#i8", new byte [] {
340                         0x22, 0xA, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0}, "\u304B\u309B");
341                 AssertSortKey ("#i9", new byte [] {
342                         0x22, 0xA, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0}, "\u304C");
343
344                 AssertSortKey ("#i10", new byte [] {
345                         0xE, 0x2, 1, 0x12, 1, 0x12, 1, 1, 0},
346                         "A\u0302");
347                 AssertSortKey ("#i11", new byte [] {
348                         0xE, 0x2, 1, 0x65, 1, 0x12, 1, 1, 0},
349                         "A\u0302\u0320");
350                 AssertSortKey ("#i12", new byte [] {
351                         0xE, 0x2, 1, 0xB8, 1, 0x12, 1, 1, 0},
352                         "A\u0302\u0320\u0320");
353                 // LAMESPEC: Windows just appends diacritical weight without
354 //              AssertSortKey ("#i13", new byte [] {
355 //                      0xE, 0x2, 1, 0xB, 1, 12, 1, 1, 0},
356 //                      "A\u0302\u0320\u0320\u0320");
357                 // FIXME: not working (table fix is required)
358 //              AssertSortKey ("#i14", new byte [] {
359 //                      0xE, 0x2, 1, 0xF2, 1, 0x12, 1, 1, 0},
360 //                      "A\u20E1");
361                 // LAMESPEC: It should not be equivalent to \u1EA6
362                 AssertSortKey ("#i15", new byte [] {
363                         0xE, 0x2, 1, 0x1F, 1, 0x12, 1, 1, 0},
364                         "A\u0308\u0301");
365                 AssertSortKey ("#i16", new byte [] {
366                         0xE, 0x2, 1, 0x1F, 1, 0x12, 1, 1, 0},
367                         "\u1EA6");
368
369         }
370
371         [Test]
372         public void GetSortKeyIgnoreNonSpaceKana ()
373         {
374                 if (!doTest)
375                         return;
376
377                 AssertSortKey ("#i1", new byte [] {
378                         0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
379                         "\u305F");
380                 AssertSortKey ("#i2", new byte [] {
381                         0x22, 0x1A, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
382                         "\u3060");
383                 AssertSortKey ("#i3", new byte [] {
384                         0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
385                         "\u305F", CompareOptions.IgnoreNonSpace);
386                 AssertSortKey ("#i4", new byte [] {
387                         0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
388                         "\u3060", CompareOptions.IgnoreNonSpace);
389         }
390
391         [Test]
392         public void GetSortKeySpecialWeight ()
393         {
394                 if (!doTest)
395                         return;
396
397                 AssertSortKey ("#i1", new byte [] {
398                         0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
399                         "\u304B\u3042");
400                 AssertSortKey ("#i2", new byte [] {
401                         0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 5, 2, 0xFF, 0xFF, 1, 0},
402                         "\u304B\u30FC");
403                 AssertSortKey ("#i3", new byte [] {
404                         0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
405                         "\u304B\u30FC", CompareOptions.IgnoreNonSpace);
406
407                 AssertSortKey ("#i4", new byte [] {
408                         0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 2, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
409                         "\u30AB\u30AC");
410                 AssertSortKey ("#i5", new byte [] {
411                         0x22, 0xA, 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
412                         "\u30AB\u30AB\u30FC");
413                 AssertSortKey ("#i6", new byte [] {
414                         0x22, 0xA, 0x22, 2, 0x22, 2, 1, 1, 1, 0xFF, 3, 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
415                         "\u30AB\u30A2\u30FC");
416                 AssertSortKey ("#i7", new byte [] {
417                         0x22, 0xA, 0x22, 2, 0x22, 2, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
418                         "\u30AB\u30A2\u30FC\u30AB");
419                 AssertSortKey ("#i8", new byte [] {
420                         0x22, 0xA, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
421                         "\u304B\u309D");
422                 AssertSortKey ("#i9", new byte [] {
423                         0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
424                         "\u304B\u309E");
425                 AssertSortKey ("#i10", new byte [] {
426                         0x22, 0x2, 0x22, 0x2, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
427                         "\u3042\u309E");//not possible
428                 AssertSortKey ("#i11", new byte [] {
429                         0x22, 0xA, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
430                         "\u304B\u30FD");//not possible
431                 AssertSortKey ("#i12", new byte [] {
432                         0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
433                         "\u304B\u30FE");//not possible
434                 AssertSortKey ("#i13", new byte [] {
435                         0x22, 0xA, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 4, 2, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
436                         "\u30AB\u30FD");
437                 AssertSortKey ("#i14", new byte [] {
438                         0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 5, 2, 0xC4, 0xC4, 0xFF, 0xC4, 0xC4, 0xFF, 1, 0},
439                         "\uFF76\uFF70");
440                 AssertSortKey ("#i15", new byte [] {
441                         0x22, 0xA, 0x22, 0xA, 1, 2, 5, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
442                         "\u304B\u3005");
443                 AssertSortKey ("#i16", new byte [] {
444                         0xAF, 9, 0xAF, 9, 1, 2, 5, 1, 1, 1, 0},
445                         "\u5EA6\u3005");
446                 AssertSortKey ("#i17", new byte [] {
447                         0xE, 2, 0xE, 2, 1, 2, 5, 1, 1, 1, 0},
448                         "a\u3005"); // huh
449                 // Not working, but I wonder if it is really FIXME.
450 //              AssertSortKey ("#i18", new byte [] {
451 //                      0xFF, 0xFF, 1, 1, 1, 1, 0},
452 //                      "\u3005");
453                 // LAMESPEC. No one can handle \u3031 correctly.
454 //              AssertSortKey ("#i19", new byte [] {
455 //                      0x22, 0x22, 0x22, 0xC, 0x22, 0xC, 1, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
456 //                      "\u306A\u304F\u3031");
457
458                 // IgnoreWidth -> all Kana becomes half-width
459                 AssertSortKey ("#i20", new byte [] {
460                         34, 26, 34, 3, 34, 44, 1, 3, 2, 3, 1, 1, 255, 2, 196, 196, 196, 255, 196, 196, 196, 255, 1, 0},
461                         "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", CompareOptions.IgnoreWidth);
462                 AssertSortKey ("#i21", new byte [] {
463                         34, 26, 34, 3, 34, 44, 1, 3, 2, 3, 1, 1, 255, 2, 196, 196, 196, 255, 196, 196, 196, 255, 1, 0},
464                         "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
465
466                 AssertSortKey ("#i22", new byte [] {
467                         0x22, 0x2A, 0x22, 2, 0x22, 0x44, 1, 3, 1, 1, 0xFF,
468                         3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xC4, 0xC4, 0xC4,
469                         0xFF, 1, 0},
470                         "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
471                 AssertSortKey ("#i23", new byte [] {
472                         0x22, 0x2A, 0x22, 2, 0x22, 0x44, 1, 3, 1, 1, 0xFF,
473                         3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xC4, 0xC4, 0xC4,
474                         0xFF, 1, 0},
475                         "\uFF8A\uFF9E\uFF70\uFF99", CompareOptions.IgnoreWidth);
476                 // extender + IgnoreNonSpace
477                 AssertSortKey ("#i24", new byte [] {
478                         0x22, 2, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
479                         "\u3042\u309D", CompareOptions.IgnoreNonSpace);
480         }
481
482         [Test]
483         public void GetSortKeyLevel5 ()
484         {
485                 if (!doTest)
486                         return;
487
488                 // shift weight
489                 AssertSortKeyLevel5 ("#8", new byte [] {
490                         0x80, 7, 6, 0x82, 0x80, 0x2F, 6, 0x82, 0},
491                         '-' + new string ('A', 10) + '-');
492                 AssertSortKeyLevel5 ("#9", new byte [] {
493                         0x80, 7, 6, 0x82, 0x80, 0xFF, 6, 0x82, 0},
494                         '-' + new string ('A', 62) + '-');
495                 AssertSortKeyLevel5 ("#10", new byte [] {
496                         0x80, 7, 6, 0x82, 0x81, 3, 6, 0x82, 0},
497                         '-' + new string ('A', 63) + '-');
498                 AssertSortKeyLevel5 ("#11", new byte [] {
499                         0x80, 7, 6, 0x82, 0x81, 0x97, 6, 0x82, 0},
500                         '-' + new string ('A', 100) + '-');
501                 AssertSortKeyLevel5 ("#12", new byte [] {
502                         0x80, 7, 6, 0x82, 0x8F, 0xA7, 6, 0x82, 0},
503                         '-' + new string ('A', 1000) + '-');
504                 AssertSortKeyLevel5 ("#13", new byte [] {
505                         0x80, 7, 6, 0x82, 0x9A, 0x87, 6, 0x82, 0},
506                         '-' + new string ('A', 100000) + '-');
507                 // This shows how Windows is broken.
508 //              AssertSortKeyLevel5 ("#14",
509 //                      0x80, 7, 6, 0x82, 0x89, 0x07, 6, 0x82, 0},
510 //                      '-' + new string ('A', 1000000) + '-');
511
512         }
513
514         [Test]
515 #if NET_2_0
516         [Category ("NotDotNet")]
517 #endif
518         public void FrenchSort ()
519         {
520                 if (!doTest)
521                         return;
522
523                 // invariant
524                 AssertSortKey ("#inv-1", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "c\u00F4te");
525                 AssertSortKey ("#inv-1-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "co\u0302te");
526                 AssertSortKey ("#inv-1-3", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 2, 2, 0x15, 1, 1, 1, 0}, "cote\u0306");
527                 AssertSortKey ("#inv-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 2, 2, 0xE, 1, 1, 1, 0}, "cot\u00E9");
528                 AssertSortKey ("#inv-2-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x14, 1, 1, 1, 0}, "co\u030Cte");
529 // They are all bugs in 2.0:
530 // #inv-3: should not be 0 since those sortkey values differ.
531 // #inv-4: should not be -1 since co\u0302te sortkey is bigger than cote\u0306.
532                 AssertCompare ("#inv-3", 1, "c\u00F4te", "cot\u00E9");
533                 AssertCompare ("#inv-4", 1, "co\u0302te", "cote\u0306");
534                 AssertCompare ("#inv-5", 1, "co\u030Cte", "cote\u0306");
535
536                 // french
537                 AssertSortKey ("#fr-1", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 2, 0x12, 1, 1, 1, 0}, "c\u00F4te", CompareOptions.None, french);
538                 AssertSortKey ("#fr-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 0xE, 1, 1, 1, 0}, "cot\u00E9", CompareOptions.None, french);
539                 AssertCompare ("#fr-3", -1, "c\u00F4te", "cot\u00E9", CompareOptions.None, french);
540                 // FIXME: why does .NET return 1 ?
541 //              AssertCompare ("#fr-4", -1, "co\u0302te", "cote\u0306", CompareOptions.None, french);
542 //              AssertCompare ("#fr-4", -1, "co\u030Cte", "cote\u0306", CompareOptions.None, french);
543         }
544
545         [Test]
546         public void GetSortKeyThai ()
547         {
548                 if (!doTest)
549                         return;
550
551                 AssertSortKey ("#i1", new byte [] {
552                         0x1E, 7, 0x1F, 0x28, 1, 3, 3, 1, 1, 1, 0},
553                         "\u0E01\u0E3A");
554                 AssertSortKey ("#i2", new byte [] {
555                         0x1E, 7, 1, 3, 1, 1, 1, 0},
556                         "\u0E01\u0E3B");
557 // FIXME: not working (table fix required)
558 //              AssertSortKey ("#i6", new byte [] {
559 //                      0x1E, 7, 0xA, 0xF9, 1, 3, 1, 1, 1, 0},
560 //                      "\u0E01\u0E3F");
561                 AssertSortKey ("#i7", new byte [] {
562                         0x1E, 7, 0x1E, 2, 1, 3, 3, 1, 1, 1, 0},
563                         "\u0E01\u0E40");
564                 AssertSortKey ("#i8", new byte [] {
565                         0x1E, 7, 0x1E, 3, 1, 3, 3, 1, 1, 1, 0},
566                         "\u0E01\u0E41");
567                 AssertSortKey ("#i9", new byte [] {
568                         0x1E, 7, 0x1E, 4, 1, 3, 3, 1, 1, 1, 0},
569                         "\u0E01\u0E42");
570                 AssertSortKey ("#i10", new byte [] {
571                         0x1E, 7, 0x1E, 5, 1, 3, 3, 1, 1, 1, 0},
572                         "\u0E01\u0E43");
573                 AssertSortKey ("#i11", new byte [] {
574                         0x1E, 7, 0x1E, 6, 1, 3, 3, 1, 1, 1, 0},
575                         "\u0E01\u0E44");
576                 AssertSortKey ("#i12", new byte [] {
577                         0x1E, 7, 0x1F, 0x29, 1, 3, 3, 1, 1, 1, 0},
578                         "\u0E01\u0E45");
579                 AssertSortKey ("#i13", new byte [] {
580                         0x1E, 7, 0x1F, 0x2A, 1, 3, 3, 1, 1, 1, 0},
581                         "\u0E01\u0E46");
582 // FIXME: not working (U+E47 table fix required)
583 //              AssertSortKey ("#i14", new byte [] {
584 //                      0x1E, 7, 1, 5, 1, 1, 1, 0},
585 //                      "\u0E01\u0E47");
586                 AssertSortKey ("#i15", new byte [] {
587                         0x1E, 7, 1, 6, 1, 1, 1, 0},
588                         "\u0E01\u0E48");
589                 AssertSortKey ("#i16", new byte [] {
590                         0x1E, 7, 1, 7, 1, 1, 1, 0},
591                         "\u0E01\u0E49");
592                 AssertSortKey ("#i17", new byte [] {
593                         0x1E, 7, 1, 8, 1, 1, 1, 0},
594                         "\u0E01\u0E4A");
595                 AssertSortKey ("#i18", new byte [] {
596                         0x1E, 7, 1, 9, 1, 1, 1, 0},
597                         "\u0E01\u0E4B");
598 // FIXME: not working (U+E47 table fix required)
599 //              AssertSortKey ("#i19", new byte [] {
600 //                      0x1E, 7, 1, 8, 1, 1, 1, 0},
601 //                      "\u0E01\u0E48\u0E47");
602                 AssertSortKey ("#i20", new byte [] {
603                         0x1E, 7, 0x1E, 4, 0x1E, 0xD, 1, 3, 3, 3, 1, 1, 1, 0},
604                         "\u0E01\u0E42\u0E02");
605                 AssertSortKey ("#i21", new byte [] {
606                         0x1E, 7, 0x1E, 0xD, 1, 3, 3, 1, 1, 1, 0},
607                         "\u0E01\u0E02");
608         }
609
610         [Test]
611         public void GetSortKeyCzechTailoring ()
612         {
613                 if (!doTest)
614                         return;
615
616                 AssertSortKey ("#i1", new byte [] {
617                         0xE, 0xA, 0xE, 0x2C, 1, 1, 1, 1, 0},
618                         "ch");
619                 AssertSortKey ("#cs1", new byte [] {
620                         0xE, 0x2E, 1, 1, 1, 1, 0},
621                         "ch", CompareOptions.None, czech);
622                 AssertSortKey ("#i2", new byte [] {
623                         0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
624                         "r\u030C");
625                 AssertSortKey ("#cs2", new byte [] {
626                         0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
627                         "r\u030C", CompareOptions.None, czech);
628         }
629
630         [Test]
631         public void GetSortKeyHungarianTailoring ()
632         {
633                 if (!doTest)
634                         return;
635
636                 AssertSortKey ("#1", new byte [] {
637                         0xE, 0xE, 1, 1, 0x1A, 1, 1, 0},
638                         "CS", CompareOptions.None, hungarian);
639                 AssertSortKey ("#2", new byte [] {
640                         0xE, 0xE, 1, 1, 0x12, 1, 1, 0},
641                         "Cs", CompareOptions.None, hungarian);
642                 AssertSortKey ("#3", new byte [] {
643                         0xE, 0xE, 1, 1, 1, 1, 0},
644                         "cs", CompareOptions.None, hungarian);
645                 AssertSortKey ("#4", new byte [] {
646                         0xE, 0x1C, 1, 1, 0x1A, 1, 1, 0},
647                         "DZ", CompareOptions.None, hungarian);
648                 AssertSortKey ("#5", new byte [] {
649                         0xE, 0x1C, 1, 1, 0x12, 1, 1, 0},
650                         "Dz", CompareOptions.None, hungarian);
651                 AssertSortKey ("#6", new byte [] {
652                         0xE, 0x1C, 1, 1, 1, 1, 0},
653                         "dz", CompareOptions.None, hungarian);
654                 AssertSortKey ("#7", new byte [] {
655                         0xE, 0x75, 1, 1, 0x1A, 1, 1, 0},
656                         "NY", CompareOptions.None, hungarian);
657                 AssertSortKey ("#8", new byte [] {
658                         0xE, 0x75, 1, 1, 0x12, 1, 1, 0},
659                         "Ny", CompareOptions.None, hungarian);
660                 AssertSortKey ("#9", new byte [] {
661                         0xE, 0x75, 1, 1, 1, 1, 0},
662                         "ny", CompareOptions.None, hungarian);
663                 AssertSortKey ("#10", new byte [] {
664                         0xE, 0xB1, 1, 1, 0x1A, 1, 1, 0},
665                         "ZS", CompareOptions.None, hungarian);
666                 AssertSortKey ("#11", new byte [] {
667                         0xE, 0xB1, 1, 1, 0x12, 1, 1, 0},
668                         "Zs", CompareOptions.None, hungarian);
669                 AssertSortKey ("#12", new byte [] {
670                         0xE, 0xB1, 1, 1, 1, 1, 0},
671                         "zs", CompareOptions.None, hungarian);
672
673                 // Windows seems to have bugs around repetitive characters
674                 // that is tailored.
675 //              AssertSortKey ("#x", new byte [] {
676 //                      0xE, 0x2E, 1, 1, 1, 1, 0},
677 //                      "CCS", CompareOptions.None, hungarian);
678
679                 // FIXME: we need to handle case insensitivity
680         }
681
682         [Test]
683         public void CustomCJKTable ()
684         {
685                 if (!doTest)
686                         return;
687
688                 AssertSortKey ("#1", new byte [] {
689                         0x9E, 9, 0x9E, 0x11, 1, 1, 1, 1, 0},
690                         "\u4E03\u4E09");
691                 AssertSortKey ("#2", new byte [] {
692                         0x84, 0xD3, 0x84, 0x61, 1, 1, 1, 1, 0},
693                         "\u4E03\u4E09", CompareOptions.None, japanese);
694         }
695
696         [Test]
697 #if NET_2_0
698         [Category ("NotDotNet")]
699 #endif
700         public void CultureSensitiveCompare ()
701         {
702                 if (!doTest)
703                         return;
704
705                 AssertCompare ("#1", -1, "1", "2");
706                 AssertCompare ("#2", 1, "A", "a");
707                 AssertCompare ("#3", 0, "A", "a", CompareOptions.IgnoreCase);
708                 AssertCompare ("#4", 0, "\uFF10", "0", CompareOptions.IgnoreWidth);
709                 AssertCompare ("#5", 0, "\uFF21", "a", ignoreCW);
710                 AssertCompare ("#6", 1, "12", "1");
711 // BUG in .NET 2.0: See GetSortKey() test that assures sortkeys for "AE" and
712 // "\u00C6" are equivalent.
713                 AssertCompare ("#7", 0, "AE", "\u00C6");
714                 AssertCompare ("#8", 0, "AB\u01c0C", "A\u01c0B\u01c0C", CompareOptions.IgnoreSymbols);
715 // BUG in .NET 2.0: ditto.
716                 AssertCompare ("#9", 0, "A\u0304", "\u0100");
717                 AssertCompare ("#10", 1, "ABCABC", 5, 1, "1", 0, 1, CompareOptions.IgnoreCase, invariant);
718                 AssertCompare ("#11", 0, "-d:NET_2_0", 0, 1, "-", 0, 1);
719
720 // BUG in .NET 2.0: ditto.
721                 AssertCompare ("#12", 0, "ae", "\u00E6");
722                 AssertCompare ("#13", 0, "\u00E6", "ae");
723                 AssertCompare ("#14", 0, "\u00E6s", 0, 1, "ae", 0, 2);
724
725                 // target is "empty" (in culture-sensitive context).
726 // BUG in .NET 2.0: \u3007 is totally-ignored character as a GetSortKey()
727 // result, while it is not in Compare().
728                 AssertCompare ("#17", 0, String.Empty, "\u3007");
729                 AssertCompare ("#18", 1, "A", "\u3007");
730                 AssertCompare ("#19", 1, "ABC", "\u3007");
731
732                 // shift weight comparison 
733                 AssertCompare ("#20", 1, "--start", "--");
734                 // expansion
735 // BUG in .NET 2.0: the same 00C6/00E6 issue.
736                 AssertCompare ("#21", -1, "\u00E6", "aes");
737         }
738
739         [Test]
740 #if NET_2_0
741         [Category ("NotDotNet")]
742 #endif
743         public void CompareSpecialWeight ()
744         {
745                 if (!doTest)
746                         return;
747
748                 // Japanese (in invariant)
749 // BUG in .NET 2.0 : half-width kana should be bigger.
750                 AssertCompare ("#1", 1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
751                 AssertCompare ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
752                 AssertCompare ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", 
753                         "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
754                 AssertCompare ("#4", 1, "\u3042\u309D", "\u3042\u3042");
755                 AssertCompare ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
756                 AssertCompare ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
757                         "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
758
759                 // extender in target
760 // BUG in .NET 2.0 : an extender should result in bigger sortkey
761                 AssertCompare ("#7", -1, "\u30D1\u30A2", "\u30D1\u30FC");
762                 AssertCompare ("#8", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
763                 // extender in source
764 // BUG in .NET 2.0 : vice versa
765                 AssertCompare ("#9", 1, "\u30D1\u30FC", "\u30D1\u30A2");
766                 AssertCompare ("#10", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
767         }
768
769         [Test]
770         public void IndexOfChar ()
771         {
772                 if (!doTest)
773                         return;
774
775                 AssertIndexOf ("#1", -1, "ABC", '1');
776                 AssertIndexOf ("#2", 2, "ABCABC", 'c', CompareOptions.IgnoreCase);
777                 AssertIndexOf ("#3", 1, "ABCABC", '\uFF22', ignoreCW);
778                 AssertIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN);
779                 AssertIndexOf ("#5", 1, "ABCABC", 'B', 1, 5, CompareOptions.IgnoreCase, invariant);
780                 AssertIndexOf ("#6", 4, "ABCABC", 'B', 2, 4, CompareOptions.IgnoreCase, invariant);
781                 AssertIndexOf ("#7", 1, "\u30D1\u30FC", '\u30A2', CompareOptions.IgnoreNonSpace);
782                 AssertIndexOf ("#8", 1, "UAE", '\u00C6');
783                 AssertIndexOf ("#8-2", 1, "AAE", '\u00C6');
784                 AssertIndexOf ("#9", -1, "UA", '\u00C6');
785                 AssertIndexOf ("#10", -1, "UE", '\u00C6');
786         }
787
788         [Test]
789         [Category ("NotDotNet")]
790         public void IndexOfCharMSBug ()
791         {
792                 if (!doTest)
793                         return;
794
795                 AssertIndexOf ("#1", 0, "\u00E6", 'a');
796         }
797
798         [Test]
799         public void LastIndexOfChar ()
800         {
801                 if (!doTest)
802                         return;
803
804                 AssertLastIndexOf ("#1", -1, "ABC", '1');
805                 AssertLastIndexOf ("#2", 5, "ABCABC", 'c', CompareOptions.IgnoreCase);
806                 AssertLastIndexOf ("#3", 4, "ABCABC", '\uFF22', ignoreCW);
807                 AssertLastIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN);
808                 AssertLastIndexOf ("#5", 1, "ABCABC", 'B', 3, 3);
809                 AssertLastIndexOf ("#6", 4, "ABCABC", 'B', 4, 4);
810                 AssertLastIndexOf ("#7", -1, "ABCABC", 'B', 5, 1);
811                 AssertLastIndexOf ("#8", 1, "UAE", '\u00C6');
812                 AssertLastIndexOf ("#8-2", 1, "UAEE", '\u00C6');
813                 AssertLastIndexOf ("#9", -1, "UA", '\u00C6');
814                 AssertLastIndexOf ("#10", -1, "UE", '\u00C6');
815                 AssertLastIndexOf ("#11", 0, "\\", '\\');
816                 AssertEquals ("#11en", 0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\", '\\'));
817                 AssertEquals ("#11ja", 0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\", '\\'));
818         }
819
820         [Test]
821         [Category ("NotDotNet")]
822         public void LastIndexOfCharMSBug ()
823         {
824                 if (!doTest)
825                         return;
826
827                 AssertIndexOf ("#1", 0, "\u00E6", 'a');
828         }
829
830         [Test]
831 #if NET_2_0
832         [Category ("NotDotNet")]
833 #endif
834         public void IsPrefix ()
835         {
836                 if (!doTest)
837                         return;
838
839                 AssertIsPrefix ("#1", false, "ABC", "c", CompareOptions.IgnoreCase);
840                 AssertIsPrefix ("#2", false, "BC", "c", CompareOptions.IgnoreCase);
841                 AssertIsPrefix ("#3", true, "C", "c", CompareOptions.IgnoreCase);
842                 AssertIsPrefix ("#4", true, "EDCBA", "\u0117", ignoreCN);
843                 AssertIsPrefix ("#5", true, "ABC", "AB", CompareOptions.IgnoreCase);
844 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
845                 AssertIsPrefix ("#6", true, "ae", "\u00E6", CompareOptions.None);
846                 AssertIsPrefix ("#7", true, "\u00E6", "ae", CompareOptions.None);
847
848 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
849                 AssertIsPrefix ("#8", true, "\u00E6", "a", CompareOptions.None);
850                 AssertIsPrefix ("#9", true, "\u00E6s", "ae", CompareOptions.None);
851                 AssertIsPrefix ("#10", false, "\u00E6", "aes", CompareOptions.None);
852                 AssertIsPrefix ("#11", true, "--start", "--", CompareOptions.None);
853                 AssertIsPrefix ("#12", true, "-d:NET_1_1", "-", CompareOptions.None);
854                 AssertIsPrefix ("#13", false, "-d:NET_1_1", "@", CompareOptions.None);
855                 // U+3007 is completely ignored character.
856                 AssertIsPrefix ("#14", true, "\uff21\uff21", "\uff21", CompareOptions.None);
857 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
858                 AssertIsPrefix ("#15", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
859                 AssertIsPrefix ("#16", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
860                 AssertIsPrefix ("#17", true, "\\b\\a a", "\\b\\a a");
861                 Assert ("#17en", new CultureInfo ("en").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"));
862                 Assert ("#17ja", new CultureInfo ("ja").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"));
863         }
864
865         [Test]
866         public void IsPrefixSpecialWeight ()
867         {
868                 if (!doTest)
869                         return;
870
871                 // Japanese (in invariant)
872                 AssertIsPrefix ("#1", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
873                 AssertIsPrefix ("#2", true, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
874                 AssertIsPrefix ("#2-2", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
875                 AssertIsPrefix ("#3", true, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", 
876                         "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
877                 AssertIsPrefix ("#3-2", false, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", 
878                         "\u30C0\u30A4\u30D6");
879                 AssertIsPrefix ("#4", false, "\u3042\u309D", "\u3042\u3042");
880                 AssertIsPrefix ("#5", true, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
881                 AssertIsPrefix ("#6", true, "\uFF8A\uFF9E\uFF70\uFF99",
882                         "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
883
884                 // extender in target
885                 AssertIsPrefix ("#7", false, "\u30D1\u30A2", "\u30D1\u30FC");
886                 AssertIsPrefix ("#8", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
887                 // extender in source
888                 AssertIsPrefix ("#9", false, "\u30D1\u30FC", "\u30D1\u30A2");
889                 AssertIsPrefix ("#10", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
890
891                 // empty suffix always matches the source.
892                 AssertIsPrefix ("#11", true, "", "");
893                 AssertIsPrefix ("#12", true, "/test.css", "");
894
895                 // bug #76243
896                 AssertIsPrefix ("#13", false, "\u00e4_", "a");
897         }
898
899         [Test]
900 #if NET_2_0
901         [Category ("NotDotNet")]
902 #endif
903         public void IsSuffix ()
904         {
905                 if (!doTest)
906                         return;
907
908                 AssertIsSuffix ("#1", true, "ABC", "c", CompareOptions.IgnoreCase);
909                 AssertIsSuffix ("#2", true, "BC", "c", CompareOptions.IgnoreCase);
910                 AssertIsSuffix ("#3", false, "CBA", "c", CompareOptions.IgnoreCase);
911                 AssertIsSuffix ("#4", true, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
912                 AssertIsSuffix ("#5", false, "\u00E6", "a", CompareOptions.None);
913 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
914                 AssertIsSuffix ("#6", true, "\u00E6", "ae", CompareOptions.None);
915                 AssertIsSuffix ("#7", true, "ae", "\u00E6", CompareOptions.None);
916                 AssertIsSuffix ("#8", false, "e", "\u00E6", CompareOptions.None);
917                 // U+3007 is completely ignored character.
918                 AssertIsSuffix ("#9", true, "\uff21\uff21", "\uff21", CompareOptions.None);
919 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
920                 AssertIsSuffix ("#10", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
921                 AssertIsSuffix ("#11", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
922                 // extender in target
923                 AssertIsSuffix ("#12", false, "\u30D1\u30A2", "\u30D1\u30FC");
924                 AssertIsSuffix ("#13", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
925                 // extender in source
926                 AssertIsSuffix ("#14", false, "\u30D1\u30FC", "\u30D1\u30A2");
927                 AssertIsSuffix ("#15", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
928                 // optimization sanity check
929                 AssertIsSuffix ("#16", true,
930                         "/configuration/system.runtime.remoting",
931                         "system.runtime.remoting");
932
933                 // empty suffix always matches the source.
934                 AssertIsSuffix ("#17", true, "", "");
935                 AssertIsSuffix ("#18", true, "/test.css", "");
936                 AssertIsSuffix ("#19", true, "/test.css", "/test.css");
937                 AssertIsSuffix ("#20", true, "\\b\\a a", "\\b\\a a");
938                 Assert ("#20en", new CultureInfo ("en").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"));
939                 Assert ("#20ja", new CultureInfo ("ja").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"));
940         }
941
942         [Test]
943         [Category ("NotDotNet")]
944         [Category ("NotWorking")]
945         public void IsSuffixMSBug ()
946         {
947                 if (!doTest)
948                         return;
949
950                 AssertIsSuffix ("#1", true, "\u00E6", "e", CompareOptions.None);
951         }
952
953         [Test]
954 #if NET_2_0
955         [Category ("NotDotNet")]
956 #endif
957         public void IndexOfString ()
958         {
959                 if (!doTest)
960                         return;
961
962                 AssertIndexOf ("#1", -1, "ABC", "1", CompareOptions.None);
963                 AssertIndexOf ("#2", 2, "ABCABC", "c", CompareOptions.IgnoreCase);
964                 AssertIndexOf ("#3", 1, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
965                 AssertIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
966                 AssertIndexOf ("#5", 1, "ABCABC", "BC", CompareOptions.IgnoreCase);
967                 AssertIndexOf ("#6", 1, "BBCBBC", "BC", CompareOptions.IgnoreCase);
968                 AssertIndexOf ("#7", -1, "ABCDEF", "BCD", 0, 3, CompareOptions.IgnoreCase, invariant);
969                 AssertIndexOf ("#8", 0, "-ABC", "-", CompareOptions.None);
970                 AssertIndexOf ("#9", 0, "--ABC", "--", CompareOptions.None);
971                 AssertIndexOf ("#10", -1, "--ABC", "--", 1, 2, CompareOptions.None, invariant);
972 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
973                 AssertIndexOf ("#11", 0, "AE", "\u00C6", CompareOptions.None);
974                 // U+3007 is completely ignored character.
975                 AssertIndexOf ("#12", 0, "\uff21\uff21", "\uff21", CompareOptions.None);
976 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
977                 AssertIndexOf ("#13", 0, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
978                 AssertIndexOf ("#14", 0, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
979                 AssertIndexOf ("#15", 0, "\uff21\uff21", "\u3007", CompareOptions.None);
980                 AssertIndexOf ("#15-2", 1, "\u3007\uff21", "\uff21", CompareOptions.None);
981                 // target is "empty" (in culture-sensitive context).
982                 AssertIndexOf ("#16", -1, String.Empty, "\u3007");
983 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
984                 AssertIndexOf ("#17", 0, "A", "\u3007");
985                 AssertIndexOf ("#18", 0, "ABC", "\u3007");
986
987                 AssertIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
988                 AssertEquals ("#19en", 0, new CultureInfo ("en").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"));
989                 AssertEquals ("#19ja", 0, new CultureInfo ("ja").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"));
990         }
991
992         [Test]
993         public void IndexOfSpecialWeight ()
994         {
995                 if (!doTest)
996                         return;
997
998                 // Japanese (in invariant)
999                 AssertIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1000                 // extender in target
1001                 AssertIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
1002                 AssertIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
1003                 // extender in source
1004                 AssertIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
1005                 AssertIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
1006                 AssertIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
1007                 AssertIndexOf ("#2-2", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1008                 AssertIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", 
1009                         "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
1010                 AssertIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
1011                 AssertIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
1012                 AssertIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
1013                         "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
1014
1015         }
1016
1017         [Test]
1018 #if NET_2_0
1019         [Category ("NotDotNet")]
1020 #endif
1021         public void LastIndexOfString ()
1022         {
1023                 if (!doTest)
1024                         return;
1025
1026                 AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions.None);
1027                 AssertLastIndexOf ("#2", 5, "ABCABC", "c", CompareOptions.IgnoreCase);
1028                 AssertLastIndexOf ("#3", 4, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
1029                 AssertLastIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
1030                 AssertLastIndexOf ("#5", 4, "ABCABC", "BC", CompareOptions.IgnoreCase);
1031                 AssertLastIndexOf ("#6", 4, "BBCBBC", "BC", CompareOptions.IgnoreCase);
1032                 AssertLastIndexOf ("#7", 1, "original", "rig", CompareOptions.None);
1033 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1034                 AssertLastIndexOf ("#8", 0, "\u00E6", "ae", CompareOptions.None);
1035                 AssertLastIndexOf ("#9", 0, "-ABC", "-", CompareOptions.None);
1036                 AssertLastIndexOf ("#10", 0, "--ABC", "--", CompareOptions.None);
1037                 AssertLastIndexOf ("#11", -1, "--ABC", "--", 2, 2, CompareOptions.None, invariant);
1038                 AssertLastIndexOf ("#12", -1, "--ABC", "--", 4, 2, CompareOptions.None, invariant);
1039 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1040                 AssertLastIndexOf ("#13", 0, "AE", "\u00C6", CompareOptions.None);
1041                 // U+3007 is completely ignored character.
1042                 AssertLastIndexOf ("#14", 1, "\uff21\uff21", "\uff21", CompareOptions.None);
1043 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1044                 AssertLastIndexOf ("#15", 1, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
1045                 AssertLastIndexOf ("#16", 1, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
1046                 AssertLastIndexOf ("#17", 1, "\uff21\uff21", "\u3007", CompareOptions.None);
1047                 AssertLastIndexOf ("#18", 1, "\u3007\uff21", "\uff21", CompareOptions.None);
1048                 AssertLastIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
1049                 AssertEquals ("#19en", 0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"));
1050                 AssertEquals ("#19ja", 0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"));
1051         }
1052
1053         [Test]
1054         public void LastIndexOfSpecialWeight ()
1055         {
1056                 if (!doTest)
1057                         return;
1058
1059                 // Japanese (in invariant)
1060                 AssertLastIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1061                 // extender in target
1062                 AssertLastIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
1063                 AssertLastIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
1064                 // extender in source
1065                 AssertLastIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
1066                 // FIXME: not working (extender support is not complete. 
1067                 // Currently private IsPrefix() cannot handle heading
1068                 // extenders to consume previous primary char.)
1069 //              AssertLastIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
1070                 // this shows that Windows accesses beyond the length and
1071                 // acquires the corresponding character to expand.
1072 //              AssertLastIndexOf ("#1-6", 1, "\u30D1\u30FC", "\u30A2", 1, 1, CompareOptions.IgnoreNonSpace, invariant);
1073                 AssertLastIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
1074                 AssertLastIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", 
1075                         "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
1076                 AssertLastIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
1077                 AssertLastIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
1078                 AssertLastIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
1079                         "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
1080         }
1081
1082         [Test]
1083         // for bug #76702
1084         public void NullCharacter ()
1085         {
1086                 AssertEquals ("#1", -1, "MONO".IndexOf ("\0\0\0"));
1087                 AssertEquals ("#2", -1, "MONO".LastIndexOf ("\0\0\0"));
1088                 AssertEquals ("#3", 1, "MONO".CompareTo ("\0\0\0"));
1089         }
1090
1091         [Test]
1092         [Category ("NotDotNet")]
1093         // MS.NET treats it as equivalent, while in IndexOf() it does not match.
1094         public void NullCharacterWeird ()
1095         {
1096                 AssertEquals ("#4", -1, "MONO".CompareTo ("MONO\0\0\0"));
1097         }
1098
1099 #if NET_2_0
1100         [Test]
1101         [Category ("NotDotNet")]
1102         public void OrdinalIgnoreCaseCompare ()
1103         {
1104                 if (!doTest)
1105                         return;
1106
1107                 // matches
1108 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1109                 AssertCompare ("#1", 0, "AE", "\u00C6", CompareOptions.None);
1110 // BUG in .NET 2.0 : It raises inappropriate ArgumentException.
1111                 // should not match since it is Ordinal
1112                 AssertCompare ("#2", -133, "AE", "\u00C6", CompareOptions.OrdinalIgnoreCase);
1113 return;
1114
1115                 AssertCompare ("#3", 1, "AE", "\u00E6", CompareOptions.None);
1116                 // matches
1117                 AssertCompare ("#4", 0, "AE", "\u00E6", CompareOptions.IgnoreCase);
1118                 // should not match since it is Ordinal
1119                 AssertCompare ("#5", -133, "AE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
1120
1121                 AssertCompare ("#6", 0, "AE", "ae", CompareOptions.OrdinalIgnoreCase);
1122                 AssertCompare ("#7", 0, "aE", "ae", CompareOptions.OrdinalIgnoreCase);
1123                 AssertCompare ("#8", 0, "aE", "ae", CompareOptions.OrdinalIgnoreCase);
1124                 AssertCompare ("#9", 0, "ae", "ae", CompareOptions.OrdinalIgnoreCase);
1125                 AssertCompare ("#10", 0, "AE", "AE", CompareOptions.OrdinalIgnoreCase);
1126                 AssertCompare ("#11", 0, "aE", "AE", CompareOptions.OrdinalIgnoreCase);
1127                 AssertCompare ("#12", 0, "aE", "AE", CompareOptions.OrdinalIgnoreCase);
1128                 AssertCompare ("#13", 0, "ae", "AE", CompareOptions.OrdinalIgnoreCase);
1129         }
1130 #endif
1131 }
1132
1133 }