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