1 // CompareInfoTest.cs - NUnit Test Cases for the
2 // System.Globalization.CompareInfo class
4 // Dick Porter <dick@ximian.com>
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2003-2005 Novell, Inc. http://www.novell.com
10 using NUnit.Framework;
12 using System.Globalization;
14 namespace MonoTests.System.Globalization
18 public class CompareInfoTest : Assertion
20 static bool doTest = Environment.GetEnvironmentVariable ("MONO_DISABLE_MANAGED_COLLATION") != "yes";
22 public CompareInfoTest() {}
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));
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));
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));
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));
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));
51 // Culture-sensitive collation tests
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;
59 CompareOptions ignoreCW =
60 CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase;
61 CompareOptions ignoreCN =
62 CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase;
64 void AssertSortKey (string message, byte [] expected, string test)
66 AssertSortKey (message, expected, test, CompareOptions.None);
69 void AssertSortKey (string message, byte [] expected, string test, CompareOptions opt)
71 AssertSortKey (message, expected, test, opt, invariant);
74 void AssertSortKey (string message, byte [] expected, string test, CompareOptions opt, CompareInfo ci)
76 byte [] actual = ci.GetSortKey (test, opt).KeyData;
77 AssertEquals (message, expected, actual);
80 void AssertSortKeyLevel5 (string message, byte [] expected, string test)
82 byte [] tmp = invariant.GetSortKey (test).KeyData;
84 for (int i = 0; i < 4; i++, idx++)
85 for (; tmp [idx] != 1; idx++)
87 byte [] actual = new byte [tmp.Length - idx];
88 Array.Copy (tmp, idx, actual, 0, actual.Length);
89 AssertEquals (message, expected, actual);
92 void AssertCompare (string message, int result, string s1, string s2)
94 AssertCompare (message, result, s1, s2, CompareOptions.None);
97 void AssertCompare (string message, int result, string s1, string s2,
100 AssertCompare (message, result, s1, s2, opt, invariant);
103 void AssertCompare (string message, int result, string s1, string s2,
104 CompareOptions opt, CompareInfo ci)
106 int ret = ci.Compare (s1, s2, opt);
108 AssertEquals (message, 0, ret);
110 Assert (message + String.Format ("(neg: {0})", ret), ret < 0);
112 Assert (message + String.Format ("(pos: {0})", ret), ret > 0);
115 void AssertCompare (string message, int result,
116 string s1, int idx1, int len1, string s2, int idx2, int len2)
118 int ret = invariant.Compare (s1, idx1, len1, s2, idx2, len2);
120 AssertEquals (message, 0, ret);
122 Assert (message, ret < 0);
124 Assert (message, ret > 0);
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)
131 int ret = ci.Compare (s1, idx1, len1, s2, idx2, len2, opt);
133 AssertEquals (message, 0, ret);
135 Assert (message, ret < 0);
137 Assert (message, ret > 0);
140 void AssertIndexOf (string message, int expected,
141 string source, char target)
143 AssertEquals (message, expected,
144 invariant.IndexOf (source, target));
147 void AssertIndexOf (string message, int expected, string source,
148 char target, CompareOptions opt)
150 AssertEquals (message, expected,
151 invariant.IndexOf (source, target, opt));
154 void AssertIndexOf (string message, int expected, string source,
155 char target, int idx, int len, CompareOptions opt, CompareInfo ci)
157 AssertEquals (message, expected,
158 ci.IndexOf (source, target, idx, len, opt));
161 void AssertIndexOf (string message, int expected,
162 string source, string target)
164 AssertEquals (message, expected,
165 invariant.IndexOf (source, target));
168 void AssertIndexOf (string message, int expected, string source,
169 string target, CompareOptions opt)
171 AssertEquals (message, expected,
172 invariant.IndexOf (source, target, opt));
175 void AssertIndexOf (string message, int expected, string source,
176 string target, int idx, int len, CompareOptions opt, CompareInfo ci)
178 AssertEquals (message, expected,
179 ci.IndexOf (source, target, idx, len, opt));
182 void AssertLastIndexOf (string message, int expected,
183 string source, char target)
185 AssertEquals (message, expected,
186 invariant.LastIndexOf (source, target));
189 void AssertLastIndexOf (string message, int expected, string source,
190 char target, CompareOptions opt)
192 AssertEquals (message, expected,
193 invariant.LastIndexOf (source, target, opt));
196 void AssertLastIndexOf (string message, int expected, string source,
197 char target, int idx, int len)
199 AssertEquals (message, expected,
200 invariant.LastIndexOf (source, target, idx, len));
203 void AssertLastIndexOf (string message, int expected, string source,
204 char target, int idx, int len, CompareOptions opt, CompareInfo ci)
206 AssertEquals (message, expected,
207 ci.LastIndexOf (source, target, idx, len, opt));
210 void AssertLastIndexOf (string message, int expected,
211 string source, string target)
213 AssertEquals (message, expected,
214 invariant.LastIndexOf (source, target));
217 void AssertLastIndexOf (string message, int expected, string source,
218 string target, CompareOptions opt)
220 AssertEquals (message, expected,
221 invariant.LastIndexOf (source, target, opt));
224 void AssertLastIndexOf (string message, int expected, string source,
225 string target, int idx, int len)
227 AssertEquals (message, expected,
228 invariant.LastIndexOf (source, target, idx, len));
231 void AssertLastIndexOf (string message, int expected, string source,
232 string target, int idx, int len, CompareOptions opt, CompareInfo ci)
234 AssertEquals (message, expected,
235 ci.LastIndexOf (source, target, idx, len, opt));
238 void AssertIsPrefix (string message, bool expected, string source,
241 Assert (message, expected == invariant.IsPrefix (
245 void AssertIsPrefix (string message, bool expected, string source,
246 string target, CompareOptions opt)
248 Assert (message, expected == invariant.IsPrefix (
249 source, target, opt));
252 void AssertIsSuffix (string message, bool expected, string source,
255 Assert (message, expected == invariant.IsSuffix (
259 void AssertIsSuffix (string message, bool expected, string source,
260 string target, CompareOptions opt)
262 Assert (message, expected == invariant.IsSuffix (
263 source, target, opt));
267 public void GetSortKey ()
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");
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);
298 AssertSortKey ("#10", new byte [] {1, 1, 1, 1, 0}, "\u3007");
303 public void GetSortKeyIgnoreWidth ()
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);
319 public void GetSortKeyDiacritical ()
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");
344 AssertSortKey ("#i10", new byte [] {
345 0xE, 0x2, 1, 0x12, 1, 0x12, 1, 1, 0},
347 AssertSortKey ("#i11", new byte [] {
348 0xE, 0x2, 1, 0x65, 1, 0x12, 1, 1, 0},
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},
361 // LAMESPEC: It should not be equivalent to \u1EA6
362 AssertSortKey ("#i15", new byte [] {
363 0xE, 0x2, 1, 0x1F, 1, 0x12, 1, 1, 0},
365 AssertSortKey ("#i16", new byte [] {
366 0xE, 0x2, 1, 0x1F, 1, 0x12, 1, 1, 0},
372 public void GetSortKeyIgnoreNonSpaceKana ()
377 AssertSortKey ("#i1", new byte [] {
378 0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
380 AssertSortKey ("#i2", new byte [] {
381 0x22, 0x1A, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
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);
392 public void GetSortKeySpecialWeight ()
397 AssertSortKey ("#i1", new byte [] {
398 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
400 AssertSortKey ("#i2", new byte [] {
401 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 5, 2, 0xFF, 0xFF, 1, 0},
403 AssertSortKey ("#i3", new byte [] {
404 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
405 "\u304B\u30FC", CompareOptions.IgnoreNonSpace);
407 AssertSortKey ("#i4", new byte [] {
408 0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 2, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
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},
422 AssertSortKey ("#i9", new byte [] {
423 0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
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},
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},
440 AssertSortKey ("#i15", new byte [] {
441 0x22, 0xA, 0x22, 0xA, 1, 2, 5, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
443 AssertSortKey ("#i16", new byte [] {
444 0xAF, 9, 0xAF, 9, 1, 2, 5, 1, 1, 1, 0},
446 AssertSortKey ("#i17", new byte [] {
447 0xE, 2, 0xE, 2, 1, 2, 5, 1, 1, 1, 0},
449 // Not working, but I wonder if it is really FIXME.
450 // AssertSortKey ("#i18", new byte [] {
451 // 0xFF, 0xFF, 1, 1, 1, 1, 0},
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");
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);
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,
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,
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);
483 public void GetSortKeyLevel5 ()
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) + '-');
515 public void GetSortKey_Options ()
517 Array values = Enum.GetValues (typeof (CompareOptions));
518 foreach (int i in values) {
519 CompareOptions option = (CompareOptions) i;
521 if (option == CompareOptions.OrdinalIgnoreCase || option == CompareOptions.Ordinal) {
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);
533 french.GetSortKey ("foo", option);
536 french.GetSortKey ("foo", option);
543 [Category ("NotDotNet")]
545 public void FrenchSort ()
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");
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);
573 public void GetSortKeyThai ()
578 AssertSortKey ("#i1", new byte [] {
579 0x1E, 7, 0x1F, 0x28, 1, 3, 3, 1, 1, 1, 0},
581 AssertSortKey ("#i2", new byte [] {
582 0x1E, 7, 1, 3, 1, 1, 1, 0},
584 // FIXME: not working (table fix required)
585 // AssertSortKey ("#i6", new byte [] {
586 // 0x1E, 7, 0xA, 0xF9, 1, 3, 1, 1, 1, 0},
588 AssertSortKey ("#i7", new byte [] {
589 0x1E, 7, 0x1E, 2, 1, 3, 3, 1, 1, 1, 0},
591 AssertSortKey ("#i8", new byte [] {
592 0x1E, 7, 0x1E, 3, 1, 3, 3, 1, 1, 1, 0},
594 AssertSortKey ("#i9", new byte [] {
595 0x1E, 7, 0x1E, 4, 1, 3, 3, 1, 1, 1, 0},
597 AssertSortKey ("#i10", new byte [] {
598 0x1E, 7, 0x1E, 5, 1, 3, 3, 1, 1, 1, 0},
600 AssertSortKey ("#i11", new byte [] {
601 0x1E, 7, 0x1E, 6, 1, 3, 3, 1, 1, 1, 0},
603 AssertSortKey ("#i12", new byte [] {
604 0x1E, 7, 0x1F, 0x29, 1, 3, 3, 1, 1, 1, 0},
606 AssertSortKey ("#i13", new byte [] {
607 0x1E, 7, 0x1F, 0x2A, 1, 3, 3, 1, 1, 1, 0},
609 // FIXME: not working (U+E47 table fix required)
610 // AssertSortKey ("#i14", new byte [] {
611 // 0x1E, 7, 1, 5, 1, 1, 1, 0},
613 AssertSortKey ("#i15", new byte [] {
614 0x1E, 7, 1, 6, 1, 1, 1, 0},
616 AssertSortKey ("#i16", new byte [] {
617 0x1E, 7, 1, 7, 1, 1, 1, 0},
619 AssertSortKey ("#i17", new byte [] {
620 0x1E, 7, 1, 8, 1, 1, 1, 0},
622 AssertSortKey ("#i18", new byte [] {
623 0x1E, 7, 1, 9, 1, 1, 1, 0},
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},
638 public void GetSortKeyCzechTailoring ()
643 AssertSortKey ("#i1", new byte [] {
644 0xE, 0xA, 0xE, 0x2C, 1, 1, 1, 1, 0},
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},
652 AssertSortKey ("#cs2", new byte [] {
653 0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
654 "r\u030C", CompareOptions.None, czech);
658 public void GetSortKeyHungarianTailoring ()
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);
700 // Windows seems to have bugs around repetitive characters
702 // AssertSortKey ("#x", new byte [] {
703 // 0xE, 0x2E, 1, 1, 1, 1, 0},
704 // "CCS", CompareOptions.None, hungarian);
706 // FIXME: we need to handle case insensitivity
710 public void CustomCJKTable ()
715 AssertSortKey ("#1", new byte [] {
716 0x9E, 9, 0x9E, 0x11, 1, 1, 1, 1, 0},
718 AssertSortKey ("#2", new byte [] {
719 0x84, 0xD3, 0x84, 0x61, 1, 1, 1, 1, 0},
720 "\u4E03\u4E09", CompareOptions.None, japanese);
725 [Category ("NotDotNet")]
727 public void CultureSensitiveCompare ()
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);
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);
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");
759 // shift weight comparison
760 AssertCompare ("#20", 1, "--start", "--");
762 // BUG in .NET 2.0: the same 00C6/00E6 issue.
763 AssertCompare ("#21", -1, "\u00E6", "aes");
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, "++)", "-+-+)");
777 [Category ("NotDotNet")]
779 public void CompareSpecialWeight ()
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);
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);
806 public void IndexOfChar ()
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');
825 [Category ("NotDotNet")]
826 public void IndexOfCharMSBug ()
831 AssertIndexOf ("#1", 0, "\u00E6", 'a');
835 public void LastIndexOfChar ()
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'));
859 [Category ("NotDotNet")]
860 public void LastIndexOfCharMSBug ()
865 AssertIndexOf ("#1", 0, "\u00E6", 'a');
870 [Category ("NotDotNet")]
872 public void IsPrefix ()
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);
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"));
904 public void IsPrefixSpecialWeight ()
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);
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);
929 // empty suffix always matches the source.
930 AssertIsPrefix ("#11", true, "", "");
931 AssertIsPrefix ("#12", true, "/test.css", "");
934 AssertIsPrefix ("#13", false, "\u00e4_", "a");
939 [Category ("NotDotNet")]
941 public void IsSuffix ()
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");
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"));
981 [Category ("NotDotNet")]
982 [Category ("NotWorking")]
983 public void IsSuffixMSBug ()
988 AssertIsSuffix ("#1", true, "\u00E6", "e", CompareOptions.None);
993 [Category ("NotDotNet")]
995 public void IndexOfString ()
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");
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"));
1031 public void IndexOfSpecialWeight ()
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);
1057 [Category ("NotDotNet")]
1059 public void LastIndexOfString ()
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"));
1090 AssertLastIndexOf ("#20", 8, "/system/web", "w");
1091 AssertEquals ("#20sv", 8, new CultureInfo ("sv").CompareInfo.LastIndexOf ("/system/web", "w"));
1095 public void LastIndexOfSpecialWeight ()
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);
1124 public void LastIndexOfOrdinalString ()
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);
1140 public void NullCharacter ()
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"));
1148 [Category ("NotDotNet")]
1149 // MS.NET treats it as equivalent, while in IndexOf() it does not match.
1150 public void NullCharacterWeird ()
1152 AssertEquals ("#4", -1, "MONO".CompareTo ("MONO\0\0\0"));
1157 [Category ("NotDotNet")]
1158 public void OrdinalIgnoreCaseCompare ()
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);
1170 AssertCompare ("#3", 1, "AE", "\u00E6", CompareOptions.None);
1172 AssertCompare ("#4", 0, "AE", "\u00E6", CompareOptions.IgnoreCase);
1173 // should not match since it is Ordinal
1174 AssertCompare ("#5", -133, "AE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
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);
1188 public void OrdinalIgnoreCaseIndexOf ()
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);
1196 public void OrdinalIgnoreCaseIndexOfChar ()
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);
1204 public void OrdinalIgnoreCaseLastIndexOf ()
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);
1214 public void OrdinalIgnoreCaseLastIndexOfChar ()
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);
1221 [Test] // bug #80865
1222 public void IsPrefixOrdinalIgnoreCase ()
1224 Assert ("aaaa".StartsWith ("A", StringComparison.OrdinalIgnoreCase));