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) + '-');
516 [Category ("NotDotNet")]
518 public void FrenchSort ()
524 AssertSortKey ("#inv-1", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "c\u00F4te");
525 AssertSortKey ("#inv-1-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "co\u0302te");
526 AssertSortKey ("#inv-1-3", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 2, 2, 0x15, 1, 1, 1, 0}, "cote\u0306");
527 AssertSortKey ("#inv-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 2, 2, 0xE, 1, 1, 1, 0}, "cot\u00E9");
528 AssertSortKey ("#inv-2-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x14, 1, 1, 1, 0}, "co\u030Cte");
529 // They are all bugs in 2.0:
530 // #inv-3: should not be 0 since those sortkey values differ.
531 // #inv-4: should not be -1 since co\u0302te sortkey is bigger than cote\u0306.
532 AssertCompare ("#inv-3", 1, "c\u00F4te", "cot\u00E9");
533 AssertCompare ("#inv-4", 1, "co\u0302te", "cote\u0306");
534 AssertCompare ("#inv-5", 1, "co\u030Cte", "cote\u0306");
537 AssertSortKey ("#fr-1", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 2, 0x12, 1, 1, 1, 0}, "c\u00F4te", CompareOptions.None, french);
538 AssertSortKey ("#fr-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 0xE, 1, 1, 1, 0}, "cot\u00E9", CompareOptions.None, french);
539 AssertCompare ("#fr-3", -1, "c\u00F4te", "cot\u00E9", CompareOptions.None, french);
540 // FIXME: why does .NET return 1 ?
541 // AssertCompare ("#fr-4", -1, "co\u0302te", "cote\u0306", CompareOptions.None, french);
542 // AssertCompare ("#fr-4", -1, "co\u030Cte", "cote\u0306", CompareOptions.None, french);
546 public void GetSortKeyThai ()
551 AssertSortKey ("#i1", new byte [] {
552 0x1E, 7, 0x1F, 0x28, 1, 3, 3, 1, 1, 1, 0},
554 AssertSortKey ("#i2", new byte [] {
555 0x1E, 7, 1, 3, 1, 1, 1, 0},
557 // FIXME: not working (table fix required)
558 // AssertSortKey ("#i6", new byte [] {
559 // 0x1E, 7, 0xA, 0xF9, 1, 3, 1, 1, 1, 0},
561 AssertSortKey ("#i7", new byte [] {
562 0x1E, 7, 0x1E, 2, 1, 3, 3, 1, 1, 1, 0},
564 AssertSortKey ("#i8", new byte [] {
565 0x1E, 7, 0x1E, 3, 1, 3, 3, 1, 1, 1, 0},
567 AssertSortKey ("#i9", new byte [] {
568 0x1E, 7, 0x1E, 4, 1, 3, 3, 1, 1, 1, 0},
570 AssertSortKey ("#i10", new byte [] {
571 0x1E, 7, 0x1E, 5, 1, 3, 3, 1, 1, 1, 0},
573 AssertSortKey ("#i11", new byte [] {
574 0x1E, 7, 0x1E, 6, 1, 3, 3, 1, 1, 1, 0},
576 AssertSortKey ("#i12", new byte [] {
577 0x1E, 7, 0x1F, 0x29, 1, 3, 3, 1, 1, 1, 0},
579 AssertSortKey ("#i13", new byte [] {
580 0x1E, 7, 0x1F, 0x2A, 1, 3, 3, 1, 1, 1, 0},
582 // FIXME: not working (U+E47 table fix required)
583 // AssertSortKey ("#i14", new byte [] {
584 // 0x1E, 7, 1, 5, 1, 1, 1, 0},
586 AssertSortKey ("#i15", new byte [] {
587 0x1E, 7, 1, 6, 1, 1, 1, 0},
589 AssertSortKey ("#i16", new byte [] {
590 0x1E, 7, 1, 7, 1, 1, 1, 0},
592 AssertSortKey ("#i17", new byte [] {
593 0x1E, 7, 1, 8, 1, 1, 1, 0},
595 AssertSortKey ("#i18", new byte [] {
596 0x1E, 7, 1, 9, 1, 1, 1, 0},
598 // FIXME: not working (U+E47 table fix required)
599 // AssertSortKey ("#i19", new byte [] {
600 // 0x1E, 7, 1, 8, 1, 1, 1, 0},
601 // "\u0E01\u0E48\u0E47");
602 AssertSortKey ("#i20", new byte [] {
603 0x1E, 7, 0x1E, 4, 0x1E, 0xD, 1, 3, 3, 3, 1, 1, 1, 0},
604 "\u0E01\u0E42\u0E02");
605 AssertSortKey ("#i21", new byte [] {
606 0x1E, 7, 0x1E, 0xD, 1, 3, 3, 1, 1, 1, 0},
611 public void GetSortKeyCzechTailoring ()
616 AssertSortKey ("#i1", new byte [] {
617 0xE, 0xA, 0xE, 0x2C, 1, 1, 1, 1, 0},
619 AssertSortKey ("#cs1", new byte [] {
620 0xE, 0x2E, 1, 1, 1, 1, 0},
621 "ch", CompareOptions.None, czech);
622 AssertSortKey ("#i2", new byte [] {
623 0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
625 AssertSortKey ("#cs2", new byte [] {
626 0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
627 "r\u030C", CompareOptions.None, czech);
631 public void GetSortKeyHungarianTailoring ()
636 AssertSortKey ("#1", new byte [] {
637 0xE, 0xE, 1, 1, 0x1A, 1, 1, 0},
638 "CS", CompareOptions.None, hungarian);
639 AssertSortKey ("#2", new byte [] {
640 0xE, 0xE, 1, 1, 0x12, 1, 1, 0},
641 "Cs", CompareOptions.None, hungarian);
642 AssertSortKey ("#3", new byte [] {
643 0xE, 0xE, 1, 1, 1, 1, 0},
644 "cs", CompareOptions.None, hungarian);
645 AssertSortKey ("#4", new byte [] {
646 0xE, 0x1C, 1, 1, 0x1A, 1, 1, 0},
647 "DZ", CompareOptions.None, hungarian);
648 AssertSortKey ("#5", new byte [] {
649 0xE, 0x1C, 1, 1, 0x12, 1, 1, 0},
650 "Dz", CompareOptions.None, hungarian);
651 AssertSortKey ("#6", new byte [] {
652 0xE, 0x1C, 1, 1, 1, 1, 0},
653 "dz", CompareOptions.None, hungarian);
654 AssertSortKey ("#7", new byte [] {
655 0xE, 0x75, 1, 1, 0x1A, 1, 1, 0},
656 "NY", CompareOptions.None, hungarian);
657 AssertSortKey ("#8", new byte [] {
658 0xE, 0x75, 1, 1, 0x12, 1, 1, 0},
659 "Ny", CompareOptions.None, hungarian);
660 AssertSortKey ("#9", new byte [] {
661 0xE, 0x75, 1, 1, 1, 1, 0},
662 "ny", CompareOptions.None, hungarian);
663 AssertSortKey ("#10", new byte [] {
664 0xE, 0xB1, 1, 1, 0x1A, 1, 1, 0},
665 "ZS", CompareOptions.None, hungarian);
666 AssertSortKey ("#11", new byte [] {
667 0xE, 0xB1, 1, 1, 0x12, 1, 1, 0},
668 "Zs", CompareOptions.None, hungarian);
669 AssertSortKey ("#12", new byte [] {
670 0xE, 0xB1, 1, 1, 1, 1, 0},
671 "zs", CompareOptions.None, hungarian);
673 // Windows seems to have bugs around repetitive characters
675 // AssertSortKey ("#x", new byte [] {
676 // 0xE, 0x2E, 1, 1, 1, 1, 0},
677 // "CCS", CompareOptions.None, hungarian);
679 // FIXME: we need to handle case insensitivity
683 public void CustomCJKTable ()
688 AssertSortKey ("#1", new byte [] {
689 0x9E, 9, 0x9E, 0x11, 1, 1, 1, 1, 0},
691 AssertSortKey ("#2", new byte [] {
692 0x84, 0xD3, 0x84, 0x61, 1, 1, 1, 1, 0},
693 "\u4E03\u4E09", CompareOptions.None, japanese);
698 [Category ("NotDotNet")]
700 public void CultureSensitiveCompare ()
705 AssertCompare ("#1", -1, "1", "2");
706 AssertCompare ("#2", 1, "A", "a");
707 AssertCompare ("#3", 0, "A", "a", CompareOptions.IgnoreCase);
708 AssertCompare ("#4", 0, "\uFF10", "0", CompareOptions.IgnoreWidth);
709 AssertCompare ("#5", 0, "\uFF21", "a", ignoreCW);
710 AssertCompare ("#6", 1, "12", "1");
711 // BUG in .NET 2.0: See GetSortKey() test that assures sortkeys for "AE" and
712 // "\u00C6" are equivalent.
713 AssertCompare ("#7", 0, "AE", "\u00C6");
714 AssertCompare ("#8", 0, "AB\u01c0C", "A\u01c0B\u01c0C", CompareOptions.IgnoreSymbols);
715 // BUG in .NET 2.0: ditto.
716 AssertCompare ("#9", 0, "A\u0304", "\u0100");
717 AssertCompare ("#10", 1, "ABCABC", 5, 1, "1", 0, 1, CompareOptions.IgnoreCase, invariant);
718 AssertCompare ("#11", 0, "-d:NET_2_0", 0, 1, "-", 0, 1);
720 // BUG in .NET 2.0: ditto.
721 AssertCompare ("#12", 0, "ae", "\u00E6");
722 AssertCompare ("#13", 0, "\u00E6", "ae");
723 AssertCompare ("#14", 0, "\u00E6s", 0, 1, "ae", 0, 2);
725 // target is "empty" (in culture-sensitive context).
726 // BUG in .NET 2.0: \u3007 is totally-ignored character as a GetSortKey()
727 // result, while it is not in Compare().
728 AssertCompare ("#17", 0, String.Empty, "\u3007");
729 AssertCompare ("#18", 1, "A", "\u3007");
730 AssertCompare ("#19", 1, "ABC", "\u3007");
732 // shift weight comparison
733 AssertCompare ("#20", 1, "--start", "--");
735 // BUG in .NET 2.0: the same 00C6/00E6 issue.
736 AssertCompare ("#21", -1, "\u00E6", "aes");
741 [Category ("NotDotNet")]
743 public void CompareSpecialWeight ()
748 // Japanese (in invariant)
749 // BUG in .NET 2.0 : half-width kana should be bigger.
750 AssertCompare ("#1", 1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
751 AssertCompare ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
752 AssertCompare ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
753 "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
754 AssertCompare ("#4", 1, "\u3042\u309D", "\u3042\u3042");
755 AssertCompare ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
756 AssertCompare ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
757 "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
759 // extender in target
760 // BUG in .NET 2.0 : an extender should result in bigger sortkey
761 AssertCompare ("#7", -1, "\u30D1\u30A2", "\u30D1\u30FC");
762 AssertCompare ("#8", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
763 // extender in source
764 // BUG in .NET 2.0 : vice versa
765 AssertCompare ("#9", 1, "\u30D1\u30FC", "\u30D1\u30A2");
766 AssertCompare ("#10", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
770 public void IndexOfChar ()
775 AssertIndexOf ("#1", -1, "ABC", '1');
776 AssertIndexOf ("#2", 2, "ABCABC", 'c', CompareOptions.IgnoreCase);
777 AssertIndexOf ("#3", 1, "ABCABC", '\uFF22', ignoreCW);
778 AssertIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN);
779 AssertIndexOf ("#5", 1, "ABCABC", 'B', 1, 5, CompareOptions.IgnoreCase, invariant);
780 AssertIndexOf ("#6", 4, "ABCABC", 'B', 2, 4, CompareOptions.IgnoreCase, invariant);
781 AssertIndexOf ("#7", 1, "\u30D1\u30FC", '\u30A2', CompareOptions.IgnoreNonSpace);
782 AssertIndexOf ("#8", 1, "UAE", '\u00C6');
783 AssertIndexOf ("#8-2", 1, "AAE", '\u00C6');
784 AssertIndexOf ("#9", -1, "UA", '\u00C6');
785 AssertIndexOf ("#10", -1, "UE", '\u00C6');
789 [Category ("NotDotNet")]
790 public void IndexOfCharMSBug ()
795 AssertIndexOf ("#1", 0, "\u00E6", 'a');
799 public void LastIndexOfChar ()
804 AssertLastIndexOf ("#1", -1, "ABC", '1');
805 AssertLastIndexOf ("#2", 5, "ABCABC", 'c', CompareOptions.IgnoreCase);
806 AssertLastIndexOf ("#3", 4, "ABCABC", '\uFF22', ignoreCW);
807 AssertLastIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN);
808 AssertLastIndexOf ("#5", 1, "ABCABC", 'B', 3, 3);
809 AssertLastIndexOf ("#6", 4, "ABCABC", 'B', 4, 4);
810 AssertLastIndexOf ("#7", -1, "ABCABC", 'B', 5, 1);
811 AssertLastIndexOf ("#8", 1, "UAE", '\u00C6');
812 AssertLastIndexOf ("#8-2", 1, "UAEE", '\u00C6');
813 AssertLastIndexOf ("#9", -1, "UA", '\u00C6');
814 AssertLastIndexOf ("#10", -1, "UE", '\u00C6');
815 AssertLastIndexOf ("#11", 0, "\\", '\\');
816 AssertEquals ("#11en", 0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\", '\\'));
817 AssertEquals ("#11ja", 0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\", '\\'));
821 [Category ("NotDotNet")]
822 public void LastIndexOfCharMSBug ()
827 AssertIndexOf ("#1", 0, "\u00E6", 'a');
832 [Category ("NotDotNet")]
834 public void IsPrefix ()
839 AssertIsPrefix ("#1", false, "ABC", "c", CompareOptions.IgnoreCase);
840 AssertIsPrefix ("#2", false, "BC", "c", CompareOptions.IgnoreCase);
841 AssertIsPrefix ("#3", true, "C", "c", CompareOptions.IgnoreCase);
842 AssertIsPrefix ("#4", true, "EDCBA", "\u0117", ignoreCN);
843 AssertIsPrefix ("#5", true, "ABC", "AB", CompareOptions.IgnoreCase);
844 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
845 AssertIsPrefix ("#6", true, "ae", "\u00E6", CompareOptions.None);
846 AssertIsPrefix ("#7", true, "\u00E6", "ae", CompareOptions.None);
848 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
849 AssertIsPrefix ("#8", true, "\u00E6", "a", CompareOptions.None);
850 AssertIsPrefix ("#9", true, "\u00E6s", "ae", CompareOptions.None);
851 AssertIsPrefix ("#10", false, "\u00E6", "aes", CompareOptions.None);
852 AssertIsPrefix ("#11", true, "--start", "--", CompareOptions.None);
853 AssertIsPrefix ("#12", true, "-d:NET_1_1", "-", CompareOptions.None);
854 AssertIsPrefix ("#13", false, "-d:NET_1_1", "@", CompareOptions.None);
855 // U+3007 is completely ignored character.
856 AssertIsPrefix ("#14", true, "\uff21\uff21", "\uff21", CompareOptions.None);
857 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
858 AssertIsPrefix ("#15", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
859 AssertIsPrefix ("#16", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
860 AssertIsPrefix ("#17", true, "\\b\\a a", "\\b\\a a");
861 Assert ("#17en", new CultureInfo ("en").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"));
862 Assert ("#17ja", new CultureInfo ("ja").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"));
866 public void IsPrefixSpecialWeight ()
871 // Japanese (in invariant)
872 AssertIsPrefix ("#1", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
873 AssertIsPrefix ("#2", true, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
874 AssertIsPrefix ("#2-2", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
875 AssertIsPrefix ("#3", true, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
876 "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
877 AssertIsPrefix ("#3-2", false, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
878 "\u30C0\u30A4\u30D6");
879 AssertIsPrefix ("#4", false, "\u3042\u309D", "\u3042\u3042");
880 AssertIsPrefix ("#5", true, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
881 AssertIsPrefix ("#6", true, "\uFF8A\uFF9E\uFF70\uFF99",
882 "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
884 // extender in target
885 AssertIsPrefix ("#7", false, "\u30D1\u30A2", "\u30D1\u30FC");
886 AssertIsPrefix ("#8", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
887 // extender in source
888 AssertIsPrefix ("#9", false, "\u30D1\u30FC", "\u30D1\u30A2");
889 AssertIsPrefix ("#10", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
891 // empty suffix always matches the source.
892 AssertIsPrefix ("#11", true, "", "");
893 AssertIsPrefix ("#12", true, "/test.css", "");
896 AssertIsPrefix ("#13", false, "\u00e4_", "a");
901 [Category ("NotDotNet")]
903 public void IsSuffix ()
908 AssertIsSuffix ("#1", true, "ABC", "c", CompareOptions.IgnoreCase);
909 AssertIsSuffix ("#2", true, "BC", "c", CompareOptions.IgnoreCase);
910 AssertIsSuffix ("#3", false, "CBA", "c", CompareOptions.IgnoreCase);
911 AssertIsSuffix ("#4", true, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
912 AssertIsSuffix ("#5", false, "\u00E6", "a", CompareOptions.None);
913 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
914 AssertIsSuffix ("#6", true, "\u00E6", "ae", CompareOptions.None);
915 AssertIsSuffix ("#7", true, "ae", "\u00E6", CompareOptions.None);
916 AssertIsSuffix ("#8", false, "e", "\u00E6", CompareOptions.None);
917 // U+3007 is completely ignored character.
918 AssertIsSuffix ("#9", true, "\uff21\uff21", "\uff21", CompareOptions.None);
919 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
920 AssertIsSuffix ("#10", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
921 AssertIsSuffix ("#11", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
922 // extender in target
923 AssertIsSuffix ("#12", false, "\u30D1\u30A2", "\u30D1\u30FC");
924 AssertIsSuffix ("#13", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
925 // extender in source
926 AssertIsSuffix ("#14", false, "\u30D1\u30FC", "\u30D1\u30A2");
927 AssertIsSuffix ("#15", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
928 // optimization sanity check
929 AssertIsSuffix ("#16", true,
930 "/configuration/system.runtime.remoting",
931 "system.runtime.remoting");
933 // empty suffix always matches the source.
934 AssertIsSuffix ("#17", true, "", "");
935 AssertIsSuffix ("#18", true, "/test.css", "");
936 AssertIsSuffix ("#19", true, "/test.css", "/test.css");
937 AssertIsSuffix ("#20", true, "\\b\\a a", "\\b\\a a");
938 Assert ("#20en", new CultureInfo ("en").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"));
939 Assert ("#20ja", new CultureInfo ("ja").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"));
943 [Category ("NotDotNet")]
944 [Category ("NotWorking")]
945 public void IsSuffixMSBug ()
950 AssertIsSuffix ("#1", true, "\u00E6", "e", CompareOptions.None);
955 [Category ("NotDotNet")]
957 public void IndexOfString ()
962 AssertIndexOf ("#1", -1, "ABC", "1", CompareOptions.None);
963 AssertIndexOf ("#2", 2, "ABCABC", "c", CompareOptions.IgnoreCase);
964 AssertIndexOf ("#3", 1, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
965 AssertIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
966 AssertIndexOf ("#5", 1, "ABCABC", "BC", CompareOptions.IgnoreCase);
967 AssertIndexOf ("#6", 1, "BBCBBC", "BC", CompareOptions.IgnoreCase);
968 AssertIndexOf ("#7", -1, "ABCDEF", "BCD", 0, 3, CompareOptions.IgnoreCase, invariant);
969 AssertIndexOf ("#8", 0, "-ABC", "-", CompareOptions.None);
970 AssertIndexOf ("#9", 0, "--ABC", "--", CompareOptions.None);
971 AssertIndexOf ("#10", -1, "--ABC", "--", 1, 2, CompareOptions.None, invariant);
972 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
973 AssertIndexOf ("#11", 0, "AE", "\u00C6", CompareOptions.None);
974 // U+3007 is completely ignored character.
975 AssertIndexOf ("#12", 0, "\uff21\uff21", "\uff21", CompareOptions.None);
976 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
977 AssertIndexOf ("#13", 0, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
978 AssertIndexOf ("#14", 0, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
979 AssertIndexOf ("#15", 0, "\uff21\uff21", "\u3007", CompareOptions.None);
980 AssertIndexOf ("#15-2", 1, "\u3007\uff21", "\uff21", CompareOptions.None);
981 // target is "empty" (in culture-sensitive context).
982 AssertIndexOf ("#16", -1, String.Empty, "\u3007");
983 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
984 AssertIndexOf ("#17", 0, "A", "\u3007");
985 AssertIndexOf ("#18", 0, "ABC", "\u3007");
987 AssertIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
988 AssertEquals ("#19en", 0, new CultureInfo ("en").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"));
989 AssertEquals ("#19ja", 0, new CultureInfo ("ja").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"));
993 public void IndexOfSpecialWeight ()
998 // Japanese (in invariant)
999 AssertIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1000 // extender in target
1001 AssertIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
1002 AssertIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
1003 // extender in source
1004 AssertIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
1005 AssertIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
1006 AssertIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
1007 AssertIndexOf ("#2-2", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1008 AssertIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
1009 "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
1010 AssertIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
1011 AssertIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
1012 AssertIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
1013 "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
1019 [Category ("NotDotNet")]
1021 public void LastIndexOfString ()
1026 AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions.None);
1027 AssertLastIndexOf ("#2", 5, "ABCABC", "c", CompareOptions.IgnoreCase);
1028 AssertLastIndexOf ("#3", 4, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
1029 AssertLastIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
1030 AssertLastIndexOf ("#5", 4, "ABCABC", "BC", CompareOptions.IgnoreCase);
1031 AssertLastIndexOf ("#6", 4, "BBCBBC", "BC", CompareOptions.IgnoreCase);
1032 AssertLastIndexOf ("#7", 1, "original", "rig", CompareOptions.None);
1033 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1034 AssertLastIndexOf ("#8", 0, "\u00E6", "ae", CompareOptions.None);
1035 AssertLastIndexOf ("#9", 0, "-ABC", "-", CompareOptions.None);
1036 AssertLastIndexOf ("#10", 0, "--ABC", "--", CompareOptions.None);
1037 AssertLastIndexOf ("#11", -1, "--ABC", "--", 2, 2, CompareOptions.None, invariant);
1038 AssertLastIndexOf ("#12", -1, "--ABC", "--", 4, 2, CompareOptions.None, invariant);
1039 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1040 AssertLastIndexOf ("#13", 0, "AE", "\u00C6", CompareOptions.None);
1041 // U+3007 is completely ignored character.
1042 AssertLastIndexOf ("#14", 1, "\uff21\uff21", "\uff21", CompareOptions.None);
1043 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1044 AssertLastIndexOf ("#15", 1, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
1045 AssertLastIndexOf ("#16", 1, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
1046 AssertLastIndexOf ("#17", 1, "\uff21\uff21", "\u3007", CompareOptions.None);
1047 AssertLastIndexOf ("#18", 1, "\u3007\uff21", "\uff21", CompareOptions.None);
1048 AssertLastIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
1049 AssertEquals ("#19en", 0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"));
1050 AssertEquals ("#19ja", 0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"));
1054 public void LastIndexOfSpecialWeight ()
1059 // Japanese (in invariant)
1060 AssertLastIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1061 // extender in target
1062 AssertLastIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
1063 AssertLastIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
1064 // extender in source
1065 AssertLastIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
1066 // FIXME: not working (extender support is not complete.
1067 // Currently private IsPrefix() cannot handle heading
1068 // extenders to consume previous primary char.)
1069 // AssertLastIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
1070 // this shows that Windows accesses beyond the length and
1071 // acquires the corresponding character to expand.
1072 // AssertLastIndexOf ("#1-6", 1, "\u30D1\u30FC", "\u30A2", 1, 1, CompareOptions.IgnoreNonSpace, invariant);
1073 AssertLastIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
1074 AssertLastIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
1075 "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
1076 AssertLastIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
1077 AssertLastIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
1078 AssertLastIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
1079 "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
1084 public void NullCharacter ()
1086 AssertEquals ("#1", -1, "MONO".IndexOf ("\0\0\0"));
1087 AssertEquals ("#2", -1, "MONO".LastIndexOf ("\0\0\0"));
1088 AssertEquals ("#3", 1, "MONO".CompareTo ("\0\0\0"));
1092 [Category ("NotDotNet")]
1093 // MS.NET treats it as equivalent, while in IndexOf() it does not match.
1094 public void NullCharacterWeird ()
1096 AssertEquals ("#4", -1, "MONO".CompareTo ("MONO\0\0\0"));
1101 [Category ("NotDotNet")]
1102 public void OrdinalIgnoreCaseCompare ()
1108 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1109 AssertCompare ("#1", 0, "AE", "\u00C6", CompareOptions.None);
1110 // BUG in .NET 2.0 : It raises inappropriate ArgumentException.
1111 // should not match since it is Ordinal
1112 AssertCompare ("#2", -133, "AE", "\u00C6", CompareOptions.OrdinalIgnoreCase);
1115 AssertCompare ("#3", 1, "AE", "\u00E6", CompareOptions.None);
1117 AssertCompare ("#4", 0, "AE", "\u00E6", CompareOptions.IgnoreCase);
1118 // should not match since it is Ordinal
1119 AssertCompare ("#5", -133, "AE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
1121 AssertCompare ("#6", 0, "AE", "ae", CompareOptions.OrdinalIgnoreCase);
1122 AssertCompare ("#7", 0, "aE", "ae", CompareOptions.OrdinalIgnoreCase);
1123 AssertCompare ("#8", 0, "aE", "ae", CompareOptions.OrdinalIgnoreCase);
1124 AssertCompare ("#9", 0, "ae", "ae", CompareOptions.OrdinalIgnoreCase);
1125 AssertCompare ("#10", 0, "AE", "AE", CompareOptions.OrdinalIgnoreCase);
1126 AssertCompare ("#11", 0, "aE", "AE", CompareOptions.OrdinalIgnoreCase);
1127 AssertCompare ("#12", 0, "aE", "AE", CompareOptions.OrdinalIgnoreCase);
1128 AssertCompare ("#13", 0, "ae", "AE", CompareOptions.OrdinalIgnoreCase);