fixed tests
[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         public void GetSortKey_Options ()
516         {
517                 Array values = Enum.GetValues (typeof (CompareOptions));
518                 foreach (int i in values) {
519                         CompareOptions option = (CompareOptions) i;
520 #if NET_2_0
521                         if (option == CompareOptions.OrdinalIgnoreCase || option == CompareOptions.Ordinal) {
522                                 try {
523                                         french.GetSortKey ("foo", option);
524                                         Fail ("#1: " + option.ToString ());
525                                 } catch (ArgumentException ex) {
526                                         AssertEquals ("#2: " + option.ToString (), typeof (ArgumentException), ex.GetType ());
527                                         AssertNotNull ("#2: " + option.ToString (), ex.Message);
528                                         AssertNotNull ("#3: " + option.ToString (), ex.ParamName);
529                                         AssertEquals ("#4: " + option.ToString (), "options", ex.ParamName);
530                                         AssertNull ("#5: " + option.ToString (), ex.InnerException);
531                                 }
532                         } else {
533                                 french.GetSortKey ("foo", option);
534                         }
535 #else
536                         french.GetSortKey ("foo", option);
537 #endif
538                 }
539         }
540
541         [Test]
542 #if NET_2_0
543         [Category ("NotDotNet")]
544 #endif
545         public void FrenchSort ()
546         {
547                 if (!doTest)
548                         return;
549
550                 // invariant
551                 AssertSortKey ("#inv-1", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "c\u00F4te");
552                 AssertSortKey ("#inv-1-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "co\u0302te");
553                 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");
554                 AssertSortKey ("#inv-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 2, 2, 0xE, 1, 1, 1, 0}, "cot\u00E9");
555                 AssertSortKey ("#inv-2-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x14, 1, 1, 1, 0}, "co\u030Cte");
556 // They are all bugs in 2.0:
557 // #inv-3: should not be 0 since those sortkey values differ.
558 // #inv-4: should not be -1 since co\u0302te sortkey is bigger than cote\u0306.
559                 AssertCompare ("#inv-3", 1, "c\u00F4te", "cot\u00E9");
560                 AssertCompare ("#inv-4", 1, "co\u0302te", "cote\u0306");
561                 AssertCompare ("#inv-5", 1, "co\u030Cte", "cote\u0306");
562
563                 // french
564                 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);
565                 AssertSortKey ("#fr-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 0xE, 1, 1, 1, 0}, "cot\u00E9", CompareOptions.None, french);
566                 AssertCompare ("#fr-3", -1, "c\u00F4te", "cot\u00E9", CompareOptions.None, french);
567                 // FIXME: why does .NET return 1 ?
568 //              AssertCompare ("#fr-4", -1, "co\u0302te", "cote\u0306", CompareOptions.None, french);
569 //              AssertCompare ("#fr-4", -1, "co\u030Cte", "cote\u0306", CompareOptions.None, french);
570         }
571
572         [Test]
573         public void GetSortKeyThai ()
574         {
575                 if (!doTest)
576                         return;
577
578                 AssertSortKey ("#i1", new byte [] {
579                         0x1E, 7, 0x1F, 0x28, 1, 3, 3, 1, 1, 1, 0},
580                         "\u0E01\u0E3A");
581                 AssertSortKey ("#i2", new byte [] {
582                         0x1E, 7, 1, 3, 1, 1, 1, 0},
583                         "\u0E01\u0E3B");
584 // FIXME: not working (table fix required)
585 //              AssertSortKey ("#i6", new byte [] {
586 //                      0x1E, 7, 0xA, 0xF9, 1, 3, 1, 1, 1, 0},
587 //                      "\u0E01\u0E3F");
588                 AssertSortKey ("#i7", new byte [] {
589                         0x1E, 7, 0x1E, 2, 1, 3, 3, 1, 1, 1, 0},
590                         "\u0E01\u0E40");
591                 AssertSortKey ("#i8", new byte [] {
592                         0x1E, 7, 0x1E, 3, 1, 3, 3, 1, 1, 1, 0},
593                         "\u0E01\u0E41");
594                 AssertSortKey ("#i9", new byte [] {
595                         0x1E, 7, 0x1E, 4, 1, 3, 3, 1, 1, 1, 0},
596                         "\u0E01\u0E42");
597                 AssertSortKey ("#i10", new byte [] {
598                         0x1E, 7, 0x1E, 5, 1, 3, 3, 1, 1, 1, 0},
599                         "\u0E01\u0E43");
600                 AssertSortKey ("#i11", new byte [] {
601                         0x1E, 7, 0x1E, 6, 1, 3, 3, 1, 1, 1, 0},
602                         "\u0E01\u0E44");
603                 AssertSortKey ("#i12", new byte [] {
604                         0x1E, 7, 0x1F, 0x29, 1, 3, 3, 1, 1, 1, 0},
605                         "\u0E01\u0E45");
606                 AssertSortKey ("#i13", new byte [] {
607                         0x1E, 7, 0x1F, 0x2A, 1, 3, 3, 1, 1, 1, 0},
608                         "\u0E01\u0E46");
609 // FIXME: not working (U+E47 table fix required)
610 //              AssertSortKey ("#i14", new byte [] {
611 //                      0x1E, 7, 1, 5, 1, 1, 1, 0},
612 //                      "\u0E01\u0E47");
613                 AssertSortKey ("#i15", new byte [] {
614                         0x1E, 7, 1, 6, 1, 1, 1, 0},
615                         "\u0E01\u0E48");
616                 AssertSortKey ("#i16", new byte [] {
617                         0x1E, 7, 1, 7, 1, 1, 1, 0},
618                         "\u0E01\u0E49");
619                 AssertSortKey ("#i17", new byte [] {
620                         0x1E, 7, 1, 8, 1, 1, 1, 0},
621                         "\u0E01\u0E4A");
622                 AssertSortKey ("#i18", new byte [] {
623                         0x1E, 7, 1, 9, 1, 1, 1, 0},
624                         "\u0E01\u0E4B");
625 // FIXME: not working (U+E47 table fix required)
626 //              AssertSortKey ("#i19", new byte [] {
627 //                      0x1E, 7, 1, 8, 1, 1, 1, 0},
628 //                      "\u0E01\u0E48\u0E47");
629                 AssertSortKey ("#i20", new byte [] {
630                         0x1E, 7, 0x1E, 4, 0x1E, 0xD, 1, 3, 3, 3, 1, 1, 1, 0},
631                         "\u0E01\u0E42\u0E02");
632                 AssertSortKey ("#i21", new byte [] {
633                         0x1E, 7, 0x1E, 0xD, 1, 3, 3, 1, 1, 1, 0},
634                         "\u0E01\u0E02");
635         }
636
637         [Test]
638         public void GetSortKeyCzechTailoring ()
639         {
640                 if (!doTest)
641                         return;
642
643                 AssertSortKey ("#i1", new byte [] {
644                         0xE, 0xA, 0xE, 0x2C, 1, 1, 1, 1, 0},
645                         "ch");
646                 AssertSortKey ("#cs1", new byte [] {
647                         0xE, 0x2E, 1, 1, 1, 1, 0},
648                         "ch", CompareOptions.None, czech);
649                 AssertSortKey ("#i2", new byte [] {
650                         0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
651                         "r\u030C");
652                 AssertSortKey ("#cs2", new byte [] {
653                         0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
654                         "r\u030C", CompareOptions.None, czech);
655         }
656
657         [Test]
658         public void GetSortKeyHungarianTailoring ()
659         {
660                 if (!doTest)
661                         return;
662
663                 AssertSortKey ("#1", new byte [] {
664                         0xE, 0xE, 1, 1, 0x1A, 1, 1, 0},
665                         "CS", CompareOptions.None, hungarian);
666                 AssertSortKey ("#2", new byte [] {
667                         0xE, 0xE, 1, 1, 0x12, 1, 1, 0},
668                         "Cs", CompareOptions.None, hungarian);
669                 AssertSortKey ("#3", new byte [] {
670                         0xE, 0xE, 1, 1, 1, 1, 0},
671                         "cs", CompareOptions.None, hungarian);
672                 AssertSortKey ("#4", new byte [] {
673                         0xE, 0x1C, 1, 1, 0x1A, 1, 1, 0},
674                         "DZ", CompareOptions.None, hungarian);
675                 AssertSortKey ("#5", new byte [] {
676                         0xE, 0x1C, 1, 1, 0x12, 1, 1, 0},
677                         "Dz", CompareOptions.None, hungarian);
678                 AssertSortKey ("#6", new byte [] {
679                         0xE, 0x1C, 1, 1, 1, 1, 0},
680                         "dz", CompareOptions.None, hungarian);
681                 AssertSortKey ("#7", new byte [] {
682                         0xE, 0x75, 1, 1, 0x1A, 1, 1, 0},
683                         "NY", CompareOptions.None, hungarian);
684                 AssertSortKey ("#8", new byte [] {
685                         0xE, 0x75, 1, 1, 0x12, 1, 1, 0},
686                         "Ny", CompareOptions.None, hungarian);
687                 AssertSortKey ("#9", new byte [] {
688                         0xE, 0x75, 1, 1, 1, 1, 0},
689                         "ny", CompareOptions.None, hungarian);
690                 AssertSortKey ("#10", new byte [] {
691                         0xE, 0xB1, 1, 1, 0x1A, 1, 1, 0},
692                         "ZS", CompareOptions.None, hungarian);
693                 AssertSortKey ("#11", new byte [] {
694                         0xE, 0xB1, 1, 1, 0x12, 1, 1, 0},
695                         "Zs", CompareOptions.None, hungarian);
696                 AssertSortKey ("#12", new byte [] {
697                         0xE, 0xB1, 1, 1, 1, 1, 0},
698                         "zs", CompareOptions.None, hungarian);
699
700                 // Windows seems to have bugs around repetitive characters
701                 // that is tailored.
702 //              AssertSortKey ("#x", new byte [] {
703 //                      0xE, 0x2E, 1, 1, 1, 1, 0},
704 //                      "CCS", CompareOptions.None, hungarian);
705
706                 // FIXME: we need to handle case insensitivity
707         }
708
709         [Test]
710         public void CustomCJKTable ()
711         {
712                 if (!doTest)
713                         return;
714
715                 AssertSortKey ("#1", new byte [] {
716                         0x9E, 9, 0x9E, 0x11, 1, 1, 1, 1, 0},
717                         "\u4E03\u4E09");
718                 AssertSortKey ("#2", new byte [] {
719                         0x84, 0xD3, 0x84, 0x61, 1, 1, 1, 1, 0},
720                         "\u4E03\u4E09", CompareOptions.None, japanese);
721         }
722
723         [Test]
724 #if NET_2_0
725         [Category ("NotDotNet")]
726 #endif
727         public void CultureSensitiveCompare ()
728         {
729                 if (!doTest)
730                         return;
731
732                 AssertCompare ("#1", -1, "1", "2");
733                 AssertCompare ("#2", 1, "A", "a");
734                 AssertCompare ("#3", 0, "A", "a", CompareOptions.IgnoreCase);
735                 AssertCompare ("#4", 0, "\uFF10", "0", CompareOptions.IgnoreWidth);
736                 AssertCompare ("#5", 0, "\uFF21", "a", ignoreCW);
737                 AssertCompare ("#6", 1, "12", "1");
738 // BUG in .NET 2.0: See GetSortKey() test that assures sortkeys for "AE" and
739 // "\u00C6" are equivalent.
740                 AssertCompare ("#7", 0, "AE", "\u00C6");
741                 AssertCompare ("#8", 0, "AB\u01c0C", "A\u01c0B\u01c0C", CompareOptions.IgnoreSymbols);
742 // BUG in .NET 2.0: ditto.
743                 AssertCompare ("#9", 0, "A\u0304", "\u0100");
744                 AssertCompare ("#10", 1, "ABCABC", 5, 1, "1", 0, 1, CompareOptions.IgnoreCase, invariant);
745                 AssertCompare ("#11", 0, "-d:NET_2_0", 0, 1, "-", 0, 1);
746
747 // BUG in .NET 2.0: ditto.
748                 AssertCompare ("#12", 0, "ae", "\u00E6");
749                 AssertCompare ("#13", 0, "\u00E6", "ae");
750                 AssertCompare ("#14", 0, "\u00E6s", 0, 1, "ae", 0, 2);
751
752                 // target is "empty" (in culture-sensitive context).
753 // BUG in .NET 2.0: \u3007 is totally-ignored character as a GetSortKey()
754 // result, while it is not in Compare().
755                 AssertCompare ("#17", 0, String.Empty, "\u3007");
756                 AssertCompare ("#18", 1, "A", "\u3007");
757                 AssertCompare ("#19", 1, "ABC", "\u3007");
758
759                 // shift weight comparison 
760                 AssertCompare ("#20", 1, "--start", "--");
761                 // expansion
762 // BUG in .NET 2.0: the same 00C6/00E6 issue.
763                 AssertCompare ("#21", -1, "\u00E6", "aes");
764
765 // bug #78748
766                 AssertCompare ("#22", -1, "++)", "+-+)");
767                 AssertCompare ("#23", -1, "+-+)", "+-+-)");
768                 AssertCompare ("#24", 1, "+-+-)", "++)");
769                 // BUG in .NET: it returns 1
770                 AssertCompare ("#25", -1, "+-+-)", "-+-+)");
771                 AssertCompare ("#26", -1, "+-+)", "-+-+)");
772                 AssertCompare ("#27", -1, "++)", "-+-+)");
773         }
774
775         [Test]
776 #if NET_2_0
777         [Category ("NotDotNet")]
778 #endif
779         public void CompareSpecialWeight ()
780         {
781                 if (!doTest)
782                         return;
783
784                 // Japanese (in invariant)
785 // BUG in .NET 2.0 : half-width kana should be bigger.
786                 AssertCompare ("#1", 1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
787                 AssertCompare ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
788                 AssertCompare ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", 
789                         "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
790                 AssertCompare ("#4", 1, "\u3042\u309D", "\u3042\u3042");
791                 AssertCompare ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
792                 AssertCompare ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
793                         "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
794
795                 // extender in target
796 // BUG in .NET 2.0 : an extender should result in bigger sortkey
797                 AssertCompare ("#7", -1, "\u30D1\u30A2", "\u30D1\u30FC");
798                 AssertCompare ("#8", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
799                 // extender in source
800 // BUG in .NET 2.0 : vice versa
801                 AssertCompare ("#9", 1, "\u30D1\u30FC", "\u30D1\u30A2");
802                 AssertCompare ("#10", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
803         }
804
805         [Test]
806         public void IndexOfChar ()
807         {
808                 if (!doTest)
809                         return;
810
811                 AssertIndexOf ("#1", -1, "ABC", '1');
812                 AssertIndexOf ("#2", 2, "ABCABC", 'c', CompareOptions.IgnoreCase);
813                 AssertIndexOf ("#3", 1, "ABCABC", '\uFF22', ignoreCW);
814                 AssertIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN);
815                 AssertIndexOf ("#5", 1, "ABCABC", 'B', 1, 5, CompareOptions.IgnoreCase, invariant);
816                 AssertIndexOf ("#6", 4, "ABCABC", 'B', 2, 4, CompareOptions.IgnoreCase, invariant);
817                 AssertIndexOf ("#7", 1, "\u30D1\u30FC", '\u30A2', CompareOptions.IgnoreNonSpace);
818                 AssertIndexOf ("#8", 1, "UAE", '\u00C6');
819                 AssertIndexOf ("#8-2", 1, "AAE", '\u00C6');
820                 AssertIndexOf ("#9", -1, "UA", '\u00C6');
821                 AssertIndexOf ("#10", -1, "UE", '\u00C6');
822         }
823
824         [Test]
825         [Category ("NotDotNet")]
826         public void IndexOfCharMSBug ()
827         {
828                 if (!doTest)
829                         return;
830
831                 AssertIndexOf ("#1", 0, "\u00E6", 'a');
832         }
833
834         [Test]
835         public void LastIndexOfChar ()
836         {
837                 if (!doTest)
838                         return;
839
840                 AssertLastIndexOf ("#1", -1, "ABC", '1');
841                 AssertLastIndexOf ("#2", 5, "ABCABC", 'c', CompareOptions.IgnoreCase);
842                 AssertLastIndexOf ("#3", 4, "ABCABC", '\uFF22', ignoreCW);
843                 AssertLastIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN);
844                 AssertLastIndexOf ("#5", 1, "ABCABC", 'B', 3, 3);
845                 AssertLastIndexOf ("#6", 4, "ABCABC", 'B', 4, 4);
846                 AssertLastIndexOf ("#7", -1, "ABCABC", 'B', 5, 1);
847                 AssertLastIndexOf ("#8", 1, "UAE", '\u00C6');
848                 AssertLastIndexOf ("#8-2", 1, "UAEE", '\u00C6');
849                 AssertLastIndexOf ("#9", -1, "UA", '\u00C6');
850                 AssertLastIndexOf ("#10", -1, "UE", '\u00C6');
851                 AssertLastIndexOf ("#11", 0, "\\", '\\');
852                 AssertEquals ("#11en", 0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\", '\\'));
853                 AssertEquals ("#11ja", 0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\", '\\'));
854                 AssertLastIndexOf ("#12", 8, "/system/web", 'w');
855                 AssertEquals ("#12sv", 8, new CultureInfo ("sv").CompareInfo.LastIndexOf ("/system/web", 'w'));
856         }
857
858         [Test]
859         [Category ("NotDotNet")]
860         public void LastIndexOfCharMSBug ()
861         {
862                 if (!doTest)
863                         return;
864
865                 AssertIndexOf ("#1", 0, "\u00E6", 'a');
866         }
867
868         [Test]
869 #if NET_2_0
870         [Category ("NotDotNet")]
871 #endif
872         public void IsPrefix ()
873         {
874                 if (!doTest)
875                         return;
876
877                 AssertIsPrefix ("#1", false, "ABC", "c", CompareOptions.IgnoreCase);
878                 AssertIsPrefix ("#2", false, "BC", "c", CompareOptions.IgnoreCase);
879                 AssertIsPrefix ("#3", true, "C", "c", CompareOptions.IgnoreCase);
880                 AssertIsPrefix ("#4", true, "EDCBA", "\u0117", ignoreCN);
881                 AssertIsPrefix ("#5", true, "ABC", "AB", CompareOptions.IgnoreCase);
882 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
883                 AssertIsPrefix ("#6", true, "ae", "\u00E6", CompareOptions.None);
884                 AssertIsPrefix ("#7", true, "\u00E6", "ae", CompareOptions.None);
885
886 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
887                 AssertIsPrefix ("#8", true, "\u00E6", "a", CompareOptions.None);
888                 AssertIsPrefix ("#9", true, "\u00E6s", "ae", CompareOptions.None);
889                 AssertIsPrefix ("#10", false, "\u00E6", "aes", CompareOptions.None);
890                 AssertIsPrefix ("#11", true, "--start", "--", CompareOptions.None);
891                 AssertIsPrefix ("#12", true, "-d:NET_1_1", "-", CompareOptions.None);
892                 AssertIsPrefix ("#13", false, "-d:NET_1_1", "@", CompareOptions.None);
893                 // U+3007 is completely ignored character.
894                 AssertIsPrefix ("#14", true, "\uff21\uff21", "\uff21", CompareOptions.None);
895 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
896                 AssertIsPrefix ("#15", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
897                 AssertIsPrefix ("#16", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
898                 AssertIsPrefix ("#17", true, "\\b\\a a", "\\b\\a a");
899                 Assert ("#17en", new CultureInfo ("en").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"));
900                 Assert ("#17ja", new CultureInfo ("ja").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"));
901         }
902
903         [Test]
904         public void IsPrefixSpecialWeight ()
905         {
906                 if (!doTest)
907                         return;
908
909                 // Japanese (in invariant)
910                 AssertIsPrefix ("#1", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
911                 AssertIsPrefix ("#2", true, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
912                 AssertIsPrefix ("#2-2", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
913                 AssertIsPrefix ("#3", true, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", 
914                         "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
915                 AssertIsPrefix ("#3-2", false, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", 
916                         "\u30C0\u30A4\u30D6");
917                 AssertIsPrefix ("#4", false, "\u3042\u309D", "\u3042\u3042");
918                 AssertIsPrefix ("#5", true, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
919                 AssertIsPrefix ("#6", true, "\uFF8A\uFF9E\uFF70\uFF99",
920                         "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
921
922                 // extender in target
923                 AssertIsPrefix ("#7", false, "\u30D1\u30A2", "\u30D1\u30FC");
924                 AssertIsPrefix ("#8", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
925                 // extender in source
926                 AssertIsPrefix ("#9", false, "\u30D1\u30FC", "\u30D1\u30A2");
927                 AssertIsPrefix ("#10", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
928
929                 // empty suffix always matches the source.
930                 AssertIsPrefix ("#11", true, "", "");
931                 AssertIsPrefix ("#12", true, "/test.css", "");
932
933                 // bug #76243
934                 AssertIsPrefix ("#13", false, "\u00e4_", "a");
935         }
936
937         [Test]
938 #if NET_2_0
939         [Category ("NotDotNet")]
940 #endif
941         public void IsSuffix ()
942         {
943                 if (!doTest)
944                         return;
945
946                 AssertIsSuffix ("#1", true, "ABC", "c", CompareOptions.IgnoreCase);
947                 AssertIsSuffix ("#2", true, "BC", "c", CompareOptions.IgnoreCase);
948                 AssertIsSuffix ("#3", false, "CBA", "c", CompareOptions.IgnoreCase);
949                 AssertIsSuffix ("#4", true, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
950                 AssertIsSuffix ("#5", false, "\u00E6", "a", CompareOptions.None);
951 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
952                 AssertIsSuffix ("#6", true, "\u00E6", "ae", CompareOptions.None);
953                 AssertIsSuffix ("#7", true, "ae", "\u00E6", CompareOptions.None);
954                 AssertIsSuffix ("#8", false, "e", "\u00E6", CompareOptions.None);
955                 // U+3007 is completely ignored character.
956                 AssertIsSuffix ("#9", true, "\uff21\uff21", "\uff21", CompareOptions.None);
957 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
958                 AssertIsSuffix ("#10", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
959                 AssertIsSuffix ("#11", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
960                 // extender in target
961                 AssertIsSuffix ("#12", false, "\u30D1\u30A2", "\u30D1\u30FC");
962                 AssertIsSuffix ("#13", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
963                 // extender in source
964                 AssertIsSuffix ("#14", false, "\u30D1\u30FC", "\u30D1\u30A2");
965                 AssertIsSuffix ("#15", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
966                 // optimization sanity check
967                 AssertIsSuffix ("#16", true,
968                         "/configuration/system.runtime.remoting",
969                         "system.runtime.remoting");
970
971                 // empty suffix always matches the source.
972                 AssertIsSuffix ("#17", true, "", "");
973                 AssertIsSuffix ("#18", true, "/test.css", "");
974                 AssertIsSuffix ("#19", true, "/test.css", "/test.css");
975                 AssertIsSuffix ("#20", true, "\\b\\a a", "\\b\\a a");
976                 Assert ("#20en", new CultureInfo ("en").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"));
977                 Assert ("#20ja", new CultureInfo ("ja").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"));
978         }
979
980         [Test]
981         [Category ("NotDotNet")]
982         [Category ("NotWorking")]
983         public void IsSuffixMSBug ()
984         {
985                 if (!doTest)
986                         return;
987
988                 AssertIsSuffix ("#1", true, "\u00E6", "e", CompareOptions.None);
989         }
990
991         [Test]
992 #if NET_2_0
993         [Category ("NotDotNet")]
994 #endif
995         public void IndexOfString ()
996         {
997                 if (!doTest)
998                         return;
999
1000                 AssertIndexOf ("#1", -1, "ABC", "1", CompareOptions.None);
1001                 AssertIndexOf ("#2", 2, "ABCABC", "c", CompareOptions.IgnoreCase);
1002                 AssertIndexOf ("#3", 1, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
1003                 AssertIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
1004                 AssertIndexOf ("#5", 1, "ABCABC", "BC", CompareOptions.IgnoreCase);
1005                 AssertIndexOf ("#6", 1, "BBCBBC", "BC", CompareOptions.IgnoreCase);
1006                 AssertIndexOf ("#7", -1, "ABCDEF", "BCD", 0, 3, CompareOptions.IgnoreCase, invariant);
1007                 AssertIndexOf ("#8", 0, "-ABC", "-", CompareOptions.None);
1008                 AssertIndexOf ("#9", 0, "--ABC", "--", CompareOptions.None);
1009                 AssertIndexOf ("#10", -1, "--ABC", "--", 1, 2, CompareOptions.None, invariant);
1010 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1011                 AssertIndexOf ("#11", 0, "AE", "\u00C6", CompareOptions.None);
1012                 // U+3007 is completely ignored character.
1013                 AssertIndexOf ("#12", 0, "\uff21\uff21", "\uff21", CompareOptions.None);
1014 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1015                 AssertIndexOf ("#13", 0, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
1016                 AssertIndexOf ("#14", 0, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
1017                 AssertIndexOf ("#15", 0, "\uff21\uff21", "\u3007", CompareOptions.None);
1018                 AssertIndexOf ("#15-2", 1, "\u3007\uff21", "\uff21", CompareOptions.None);
1019                 // target is "empty" (in culture-sensitive context).
1020                 AssertIndexOf ("#16", -1, String.Empty, "\u3007");
1021 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1022                 AssertIndexOf ("#17", 0, "A", "\u3007");
1023                 AssertIndexOf ("#18", 0, "ABC", "\u3007");
1024
1025                 AssertIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
1026                 AssertEquals ("#19en", 0, new CultureInfo ("en").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"));
1027                 AssertEquals ("#19ja", 0, new CultureInfo ("ja").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"));
1028         }
1029
1030         [Test]
1031         public void IndexOfSpecialWeight ()
1032         {
1033                 if (!doTest)
1034                         return;
1035
1036                 // Japanese (in invariant)
1037                 AssertIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1038                 // extender in target
1039                 AssertIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
1040                 AssertIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
1041                 // extender in source
1042                 AssertIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
1043                 AssertIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
1044                 AssertIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
1045                 AssertIndexOf ("#2-2", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1046                 AssertIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", 
1047                         "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
1048                 AssertIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
1049                 AssertIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
1050                 AssertIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
1051                         "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
1052
1053         }
1054
1055         [Test]
1056 #if NET_2_0
1057         [Category ("NotDotNet")]
1058 #endif
1059         public void LastIndexOfString ()
1060         {
1061                 if (!doTest)
1062                         return;
1063
1064                 AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions.None);
1065                 AssertLastIndexOf ("#2", 5, "ABCABC", "c", CompareOptions.IgnoreCase);
1066                 AssertLastIndexOf ("#3", 4, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
1067                 AssertLastIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
1068                 AssertLastIndexOf ("#5", 4, "ABCABC", "BC", CompareOptions.IgnoreCase);
1069                 AssertLastIndexOf ("#6", 4, "BBCBBC", "BC", CompareOptions.IgnoreCase);
1070                 AssertLastIndexOf ("#7", 1, "original", "rig", CompareOptions.None);
1071 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1072                 AssertLastIndexOf ("#8", 0, "\u00E6", "ae", CompareOptions.None);
1073                 AssertLastIndexOf ("#9", 0, "-ABC", "-", CompareOptions.None);
1074                 AssertLastIndexOf ("#10", 0, "--ABC", "--", CompareOptions.None);
1075                 AssertLastIndexOf ("#11", -1, "--ABC", "--", 2, 2, CompareOptions.None, invariant);
1076                 AssertLastIndexOf ("#12", -1, "--ABC", "--", 4, 2, CompareOptions.None, invariant);
1077 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1078                 AssertLastIndexOf ("#13", 0, "AE", "\u00C6", CompareOptions.None);
1079                 // U+3007 is completely ignored character.
1080                 AssertLastIndexOf ("#14", 1, "\uff21\uff21", "\uff21", CompareOptions.None);
1081 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1082                 AssertLastIndexOf ("#15", 1, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
1083                 AssertLastIndexOf ("#16", 1, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
1084                 AssertLastIndexOf ("#17", 1, "\uff21\uff21", "\u3007", CompareOptions.None);
1085                 AssertLastIndexOf ("#18", 1, "\u3007\uff21", "\uff21", CompareOptions.None);
1086                 AssertLastIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
1087                 AssertEquals ("#19en", 0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"));
1088                 AssertEquals ("#19ja", 0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"));
1089                 // bug #80612
1090                 AssertLastIndexOf ("#20", 8, "/system/web", "w");
1091                 AssertEquals ("#20sv", 8, new CultureInfo ("sv").CompareInfo.LastIndexOf ("/system/web", "w"));
1092         }
1093
1094         [Test]
1095         public void LastIndexOfSpecialWeight ()
1096         {
1097                 if (!doTest)
1098                         return;
1099
1100                 // Japanese (in invariant)
1101                 AssertLastIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1102                 // extender in target
1103                 AssertLastIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
1104                 AssertLastIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
1105                 // extender in source
1106                 AssertLastIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
1107                 // FIXME: not working (extender support is not complete. 
1108                 // Currently private IsPrefix() cannot handle heading
1109                 // extenders to consume previous primary char.)
1110 //              AssertLastIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
1111                 // this shows that Windows accesses beyond the length and
1112                 // acquires the corresponding character to expand.
1113 //              AssertLastIndexOf ("#1-6", 1, "\u30D1\u30FC", "\u30A2", 1, 1, CompareOptions.IgnoreNonSpace, invariant);
1114                 AssertLastIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
1115                 AssertLastIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", 
1116                         "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
1117                 AssertLastIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
1118                 AssertLastIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
1119                 AssertLastIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
1120                         "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
1121         }
1122
1123         [Test]
1124         public void LastIndexOfOrdinalString ()
1125         {
1126                 if (!doTest)
1127                         return;
1128
1129                 AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions.Ordinal);
1130                 AssertLastIndexOf ("#2", 5, "ABCABC", "C", CompareOptions.Ordinal);
1131                 AssertLastIndexOf ("#3", -1, "ABCABC", "\uFF22", CompareOptions.Ordinal);
1132                 AssertLastIndexOf ("#4", 4, "ABCABC", "BC", CompareOptions.Ordinal);
1133                 AssertLastIndexOf ("#5", 4, "BBCBBC", "BC", CompareOptions.Ordinal);
1134                 AssertLastIndexOf ("#6", 1, "original", "rig", CompareOptions.Ordinal);
1135                 AssertLastIndexOf ("#7", 0, "\\b\\a a", "\\b\\a a", CompareOptions.Ordinal);
1136         }
1137
1138         [Test]
1139         // for bug #76702
1140         public void NullCharacter ()
1141         {
1142                 AssertEquals ("#1", -1, "MONO".IndexOf ("\0\0\0"));
1143                 AssertEquals ("#2", -1, "MONO".LastIndexOf ("\0\0\0"));
1144                 AssertEquals ("#3", 1, "MONO".CompareTo ("\0\0\0"));
1145         }
1146
1147         [Test]
1148         [Category ("NotDotNet")]
1149         // MS.NET treats it as equivalent, while in IndexOf() it does not match.
1150         public void NullCharacterWeird ()
1151         {
1152                 AssertEquals ("#4", -1, "MONO".CompareTo ("MONO\0\0\0"));
1153         }
1154
1155 #if NET_2_0
1156         [Test]
1157         [Category ("NotDotNet")]
1158         public void OrdinalIgnoreCaseCompare ()
1159         {
1160                 if (!doTest)
1161                         return;
1162
1163                 // matches
1164 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1165                 AssertCompare ("#1", 0, "AE", "\u00C6", CompareOptions.None);
1166 // BUG in .NET 2.0 : It raises inappropriate ArgumentException.
1167                 // should not match since it is Ordinal
1168                 AssertCompare ("#2", -133, "AE", "\u00C6", CompareOptions.OrdinalIgnoreCase);
1169
1170                 AssertCompare ("#3", 1, "AE", "\u00E6", CompareOptions.None);
1171                 // matches
1172                 AssertCompare ("#4", 0, "AE", "\u00E6", CompareOptions.IgnoreCase);
1173                 // should not match since it is Ordinal
1174                 AssertCompare ("#5", -133, "AE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
1175
1176                 AssertCompare ("#6", 0, "AE", "ae", CompareOptions.OrdinalIgnoreCase);
1177                 AssertCompare ("#7", 0, "aE", "ae", CompareOptions.OrdinalIgnoreCase);
1178                 AssertCompare ("#8", 0, "aE", "ae", CompareOptions.OrdinalIgnoreCase);
1179                 AssertCompare ("#9", 0, "ae", "ae", CompareOptions.OrdinalIgnoreCase);
1180                 AssertCompare ("#10", 0, "AE", "AE", CompareOptions.OrdinalIgnoreCase);
1181                 AssertCompare ("#11", 0, "aE", "AE", CompareOptions.OrdinalIgnoreCase);
1182                 AssertCompare ("#12", 0, "aE", "AE", CompareOptions.OrdinalIgnoreCase);
1183                 AssertCompare ("#13", 0, "ae", "AE", CompareOptions.OrdinalIgnoreCase);
1184                 AssertCompare ("#14", 0, "ola", "OLA", CompareOptions.OrdinalIgnoreCase);
1185         }
1186
1187         [Test]
1188         public void OrdinalIgnoreCaseIndexOf ()
1189         {
1190                 AssertIndexOf ("#1-1", 0, "ABC", "abc", CompareOptions.OrdinalIgnoreCase);
1191                 AssertIndexOf ("#1-2", -1, "AEBECE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
1192                 AssertIndexOf ("#1-3", -1, "@_@", "`_`", CompareOptions.OrdinalIgnoreCase);
1193         }
1194
1195         [Test]
1196         public void OrdinalIgnoreCaseIndexOfChar ()
1197         {
1198                 AssertIndexOf ("#2-1", 0, "ABC", 'a', CompareOptions.OrdinalIgnoreCase);
1199                 AssertIndexOf ("#2-2", -1, "AEBECE", '\u00C0', CompareOptions.OrdinalIgnoreCase);
1200                 AssertIndexOf ("#2-3", -1, "@_@", '`', CompareOptions.OrdinalIgnoreCase);
1201         }
1202
1203         [Test]
1204         public void OrdinalIgnoreCaseLastIndexOf ()
1205         {
1206                 AssertLastIndexOf ("#1-1", 0, "ABC", "abc", CompareOptions.OrdinalIgnoreCase);
1207                 AssertLastIndexOf ("#1-2", -1, "AEBECE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
1208                 AssertLastIndexOf ("#1-3", -1, "@_@", "`_`", CompareOptions.OrdinalIgnoreCase);
1209                 AssertLastIndexOf ("#1-4", 1, "ABCDE", "bc", CompareOptions.OrdinalIgnoreCase);
1210                 AssertLastIndexOf ("#1-5", -1, "BBBBB", "ab", CompareOptions.OrdinalIgnoreCase);
1211         }
1212
1213         [Test]
1214         public void OrdinalIgnoreCaseLastIndexOfChar ()
1215         {
1216                 AssertLastIndexOf ("#2-1", 0, "ABC", 'a', CompareOptions.OrdinalIgnoreCase);
1217                 AssertLastIndexOf ("#2-2", -1, "AEBECE", '\u00C0', CompareOptions.OrdinalIgnoreCase);
1218                 AssertLastIndexOf ("#2-3", -1, "@_@", '`', CompareOptions.OrdinalIgnoreCase);
1219         }
1220
1221         [Test] // bug #80865
1222         public void IsPrefixOrdinalIgnoreCase ()
1223         {
1224                 Assert ("aaaa".StartsWith ("A", StringComparison.OrdinalIgnoreCase));
1225         }
1226 #endif
1227 }
1228
1229 }