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
20 static bool doTest = Environment.GetEnvironmentVariable ("MONO_DISABLE_MANAGED_COLLATION") != "yes";
22 public CompareInfoTest() {}
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");
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");
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");
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");
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");
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");
54 // Culture-sensitive collation tests
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;
62 CompareOptions ignoreCW =
63 CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase;
64 CompareOptions ignoreCN =
65 CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase;
67 void AssertSortKey (string message, byte [] expected, string test)
69 AssertSortKey (message, expected, test, CompareOptions.None);
72 void AssertSortKey (string message, byte [] expected, string test, CompareOptions opt)
74 AssertSortKey (message, expected, test, opt, invariant);
77 void AssertSortKey (string message, byte [] expected, string test, CompareOptions opt, CompareInfo ci)
79 byte [] actual = ci.GetSortKey (test, opt).KeyData;
80 Assert.AreEqual (expected, actual, message);
83 void AssertSortKeyLevel5 (string message, byte [] expected, string test)
85 byte [] tmp = invariant.GetSortKey (test).KeyData;
87 for (int i = 0; i < 4; i++, idx++)
88 for (; tmp [idx] != 1; idx++)
90 byte [] actual = new byte [tmp.Length - idx];
91 Array.Copy (tmp, idx, actual, 0, actual.Length);
92 Assert.AreEqual (expected, actual, message);
95 void AssertCompare (string message, int result, string s1, string s2)
97 AssertCompare (message, result, s1, s2, CompareOptions.None);
100 void AssertCompare (string message, int result, string s1, string s2,
103 AssertCompare (message, result, s1, s2, opt, invariant);
106 void AssertCompare (string message, int result, string s1, string s2,
107 CompareOptions opt, CompareInfo ci)
109 int ret = ci.Compare (s1, s2, opt);
111 Assert.AreEqual (0, ret, message);
113 Assert.IsTrue (ret < 0, message + String.Format ("(neg: {0})", ret));
115 Assert.IsTrue (ret > 0, message + String.Format ("(pos: {0})", ret));
118 void AssertCompare (string message, int result,
119 string s1, int idx1, int len1, string s2, int idx2, int len2)
121 int ret = invariant.Compare (s1, idx1, len1, s2, idx2, len2);
123 Assert.AreEqual (0, ret, message);
125 Assert.IsTrue (ret < 0, message);
127 Assert.IsTrue (ret > 0, message);
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)
134 int ret = ci.Compare (s1, idx1, len1, s2, idx2, len2, opt);
136 Assert.AreEqual (0, ret, message);
138 Assert.IsTrue (ret < 0, message);
140 Assert.IsTrue (ret > 0, message);
143 void AssertIndexOf (string message, int expected,
144 string source, char target)
146 Assert.AreEqual (expected, invariant.IndexOf (source, target), message);
149 void AssertIndexOf (string message, int expected, string source,
150 char target, CompareOptions opt)
152 Assert.AreEqual (expected, invariant.IndexOf (source, target, opt), message);
155 void AssertIndexOf (string message, int expected, string source,
156 char target, int idx, int len, CompareOptions opt, CompareInfo ci)
158 Assert.AreEqual (expected, ci.IndexOf (source, target, idx, len, opt), message);
161 void AssertIndexOf (string message, int expected,
162 string source, string target)
164 Assert.AreEqual (expected, invariant.IndexOf (source, target), message);
167 void AssertIndexOf (string message, int expected, string source,
168 string target, CompareOptions opt)
170 Assert.AreEqual (expected, invariant.IndexOf (source, target, opt), message);
173 void AssertIndexOf (string message, int expected, string source,
174 string target, int idx, int len, CompareOptions opt, CompareInfo ci)
176 Assert.AreEqual (expected, ci.IndexOf (source, target, idx, len, opt), message);
179 void AssertLastIndexOf (string message, int expected,
180 string source, char target)
182 Assert.AreEqual (expected, invariant.LastIndexOf (source, target), message);
185 void AssertLastIndexOf (string message, int expected, string source,
186 char target, CompareOptions opt)
188 Assert.AreEqual (expected, invariant.LastIndexOf (source, target, opt), message);
191 void AssertLastIndexOf (string message, int expected, string source,
192 char target, int idx, int len)
194 Assert.AreEqual (expected, invariant.LastIndexOf (source, target, idx, len), message);
197 void AssertLastIndexOf (string message, int expected, string source,
198 char target, int idx, int len, CompareOptions opt, CompareInfo ci)
200 Assert.AreEqual (expected, ci.LastIndexOf (source, target, idx, len, opt), message);
203 void AssertLastIndexOf (string message, int expected,
204 string source, string target)
206 Assert.AreEqual (expected, invariant.LastIndexOf (source, target), message);
209 void AssertLastIndexOf (string message, int expected, string source,
210 string target, CompareOptions opt)
212 Assert.AreEqual (expected, invariant.LastIndexOf (source, target, opt), message);
215 void AssertLastIndexOf (string message, int expected, string source,
216 string target, int idx, int len)
218 Assert.AreEqual (expected, invariant.LastIndexOf (source, target, idx, len), message);
221 void AssertLastIndexOf (string message, int expected, string source,
222 string target, int idx, int len, CompareOptions opt, CompareInfo ci)
224 Assert.AreEqual (expected, ci.LastIndexOf (source, target, idx, len, opt), message);
227 void AssertIsPrefix (string message, bool expected, string source,
230 Assert.IsTrue (expected == invariant.IsPrefix (source, target), message);
233 void AssertIsPrefix (string message, bool expected, string source,
234 string target, CompareOptions opt)
236 Assert.IsTrue (expected == invariant.IsPrefix (source, target, opt), message);
239 void AssertIsSuffix (string message, bool expected, string source,
242 Assert.IsTrue (expected == invariant.IsSuffix (source, target), message);
245 void AssertIsSuffix (string message, bool expected, string source,
246 string target, CompareOptions opt)
248 Assert.IsTrue (expected == invariant.IsSuffix (source, target, opt), message);
252 public void GetSortKey ()
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");
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);
283 AssertSortKey ("#10", new byte [] {1, 1, 1, 1, 0}, "\u3007");
288 public void GetSortKeyIgnoreWidth ()
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);
304 public void GetSortKeyDiacritical ()
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");
329 AssertSortKey ("#i10", new byte [] {
330 0xE, 0x2, 1, 0x12, 1, 0x12, 1, 1, 0},
332 AssertSortKey ("#i11", new byte [] {
333 0xE, 0x2, 1, 0x65, 1, 0x12, 1, 1, 0},
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},
346 // LAMESPEC: It should not be equivalent to \u1EA6
347 AssertSortKey ("#i15", new byte [] {
348 0xE, 0x2, 1, 0x1F, 1, 0x12, 1, 1, 0},
350 AssertSortKey ("#i16", new byte [] {
351 0xE, 0x2, 1, 0x1F, 1, 0x12, 1, 1, 0},
357 public void GetSortKeyIgnoreNonSpaceKana ()
362 AssertSortKey ("#i1", new byte [] {
363 0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
365 AssertSortKey ("#i2", new byte [] {
366 0x22, 0x1A, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
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);
377 public void GetSortKeySpecialWeight ()
382 AssertSortKey ("#i1", new byte [] {
383 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
385 AssertSortKey ("#i2", new byte [] {
386 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 5, 2, 0xFF, 0xFF, 1, 0},
388 AssertSortKey ("#i3", new byte [] {
389 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
390 "\u304B\u30FC", CompareOptions.IgnoreNonSpace);
392 AssertSortKey ("#i4", new byte [] {
393 0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 2, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
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},
407 AssertSortKey ("#i9", new byte [] {
408 0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
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},
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},
425 AssertSortKey ("#i15", new byte [] {
426 0x22, 0xA, 0x22, 0xA, 1, 2, 5, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
428 AssertSortKey ("#i16", new byte [] {
429 0xAF, 9, 0xAF, 9, 1, 2, 5, 1, 1, 1, 0},
431 AssertSortKey ("#i17", new byte [] {
432 0xE, 2, 0xE, 2, 1, 2, 5, 1, 1, 1, 0},
434 // Not working, but I wonder if it is really FIXME.
435 // AssertSortKey ("#i18", new byte [] {
436 // 0xFF, 0xFF, 1, 1, 1, 1, 0},
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");
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);
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,
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,
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);
468 public void GetSortKeyLevel5 ()
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) + '-');
500 public void GetSortKey_Options ()
502 Array values = Enum.GetValues (typeof (CompareOptions));
503 foreach (int i in values) {
504 CompareOptions option = (CompareOptions) i;
506 if (option == CompareOptions.OrdinalIgnoreCase || option == CompareOptions.Ordinal) {
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 ());
518 french.GetSortKey ("foo", option);
521 french.GetSortKey ("foo", option);
528 [Category ("NotDotNet")]
530 public void FrenchSort ()
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");
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);
558 public void GetSortKeyThai ()
563 AssertSortKey ("#i1", new byte [] {
564 0x1E, 7, 0x1F, 0x28, 1, 3, 3, 1, 1, 1, 0},
566 AssertSortKey ("#i2", new byte [] {
567 0x1E, 7, 1, 3, 1, 1, 1, 0},
569 // FIXME: not working (table fix required)
570 // AssertSortKey ("#i6", new byte [] {
571 // 0x1E, 7, 0xA, 0xF9, 1, 3, 1, 1, 1, 0},
573 AssertSortKey ("#i7", new byte [] {
574 0x1E, 7, 0x1E, 2, 1, 3, 3, 1, 1, 1, 0},
576 AssertSortKey ("#i8", new byte [] {
577 0x1E, 7, 0x1E, 3, 1, 3, 3, 1, 1, 1, 0},
579 AssertSortKey ("#i9", new byte [] {
580 0x1E, 7, 0x1E, 4, 1, 3, 3, 1, 1, 1, 0},
582 AssertSortKey ("#i10", new byte [] {
583 0x1E, 7, 0x1E, 5, 1, 3, 3, 1, 1, 1, 0},
585 AssertSortKey ("#i11", new byte [] {
586 0x1E, 7, 0x1E, 6, 1, 3, 3, 1, 1, 1, 0},
588 AssertSortKey ("#i12", new byte [] {
589 0x1E, 7, 0x1F, 0x29, 1, 3, 3, 1, 1, 1, 0},
591 AssertSortKey ("#i13", new byte [] {
592 0x1E, 7, 0x1F, 0x2A, 1, 3, 3, 1, 1, 1, 0},
594 // FIXME: not working (U+E47 table fix required)
595 // AssertSortKey ("#i14", new byte [] {
596 // 0x1E, 7, 1, 5, 1, 1, 1, 0},
598 AssertSortKey ("#i15", new byte [] {
599 0x1E, 7, 1, 6, 1, 1, 1, 0},
601 AssertSortKey ("#i16", new byte [] {
602 0x1E, 7, 1, 7, 1, 1, 1, 0},
604 AssertSortKey ("#i17", new byte [] {
605 0x1E, 7, 1, 8, 1, 1, 1, 0},
607 AssertSortKey ("#i18", new byte [] {
608 0x1E, 7, 1, 9, 1, 1, 1, 0},
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},
623 public void GetSortKeyCzechTailoring ()
628 AssertSortKey ("#i1", new byte [] {
629 0xE, 0xA, 0xE, 0x2C, 1, 1, 1, 1, 0},
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},
637 AssertSortKey ("#cs2", new byte [] {
638 0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
639 "r\u030C", CompareOptions.None, czech);
643 public void GetSortKeyHungarianTailoring ()
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);
685 // Windows seems to have bugs around repetitive characters
687 // AssertSortKey ("#x", new byte [] {
688 // 0xE, 0x2E, 1, 1, 1, 1, 0},
689 // "CCS", CompareOptions.None, hungarian);
691 // FIXME: we need to handle case insensitivity
695 public void CustomCJKTable ()
700 AssertSortKey ("#1", new byte [] {
701 0x9E, 9, 0x9E, 0x11, 1, 1, 1, 1, 0},
703 AssertSortKey ("#2", new byte [] {
704 0x84, 0xD3, 0x84, 0x61, 1, 1, 1, 1, 0},
705 "\u4E03\u4E09", CompareOptions.None, japanese);
710 [Category ("NotDotNet")]
712 public void CultureSensitiveCompare ()
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);
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);
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");
744 // shift weight comparison
745 AssertCompare ("#20", 1, "--start", "--");
747 // BUG in .NET 2.0: the same 00C6/00E6 issue.
748 AssertCompare ("#21", -1, "\u00E6", "aes");
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, "++)", "-+-+)");
759 AssertCompare ("#28", 1, "aa ", "A");
764 [Category ("NotDotNet")]
766 public void CompareSpecialWeight ()
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);
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);
793 public void IndexOfChar ()
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');
812 [Category ("NotDotNet")]
813 public void IndexOfCharMSBug ()
818 AssertIndexOf ("#1", 0, "\u00E6", 'a');
822 public void LastIndexOfChar ()
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");
846 [Category ("NotDotNet")]
847 public void LastIndexOfCharMSBug ()
852 AssertIndexOf ("#1", 0, "\u00E6", 'a');
857 [Category ("NotDotNet")]
859 public void IsPrefix ()
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);
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");
891 public void IsPrefixSpecialWeight ()
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);
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);
916 // empty suffix always matches the source.
917 AssertIsPrefix ("#11", true, "", "");
918 AssertIsPrefix ("#12", true, "/test.css", "");
921 AssertIsPrefix ("#13", false, "\u00e4_", "a");
926 [Category ("NotDotNet")]
928 public void IsSuffix ()
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");
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");
968 [Category ("NotDotNet")]
969 [Category ("NotWorking")]
970 public void IsSuffixMSBug ()
975 AssertIsSuffix ("#1", true, "\u00E6", "e", CompareOptions.None);
979 public void IndexOfString ()
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);
996 // U+3007 is completely ignored character.
997 AssertIndexOf ("#12", 0, "\uff21\uff21", "\uff21", CompareOptions.None);
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");
1005 AssertIndexOf ("#18", 0, "ABC", "\u3007");
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");
1014 [Category ("NotDotNet")]
1016 public void IndexOfStringWeird ()
1018 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1019 AssertIndexOf ("#11", 0, "AE", "\u00C6", CompareOptions.None);
1021 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1022 AssertIndexOf ("#13", 0, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
1024 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1025 AssertIndexOf ("#17", 0, "A", "\u3007");
1029 public void IndexOfSpecialWeight ()
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);
1054 public void LastIndexOfString ()
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);
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);
1072 // U+3007 is completely ignored character.
1073 AssertLastIndexOf ("#14", 1, "\uff21\uff21", "\uff21", CompareOptions.None);
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");
1082 AssertLastIndexOf ("#20", 8, "/system/web", "w");
1083 Assert.AreEqual (8, new CultureInfo ("sv").CompareInfo.LastIndexOf ("/system/web", "w"), "#20sv");
1085 AssertLastIndexOf ("#21", 2, "foo", String.Empty);
1089 [Category ("NotDotNet")]
1090 public void LastIndexOfStringDotnetWeird ()
1095 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1096 AssertLastIndexOf ("#8", 0, "\u00E6", "ae", CompareOptions.None);
1098 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1099 AssertLastIndexOf ("#13", 0, "AE", "\u00C6", CompareOptions.None);
1101 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1102 AssertLastIndexOf ("#15", 1, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
1106 public void LastIndexOfSpecialWeight ()
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);
1135 public void LastIndexOfOrdinalString ()
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);
1150 public void NullCharacter ()
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");
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");
1167 // LAMESPEC: MS.NET treats it as equivalent, while in IndexOf() it does not match.
1168 public void NullCharacterWeird ()
1170 Assert.AreEqual (0, "MONO".CompareTo ("MONO\0\0\0"), "#4");
1175 [Category ("NotDotNet")]
1176 public void OrdinalIgnoreCaseCompare ()
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);
1188 AssertCompare ("#3", 1, "AE", "\u00E6", CompareOptions.None);
1190 AssertCompare ("#4", 0, "AE", "\u00E6", CompareOptions.IgnoreCase);
1191 // should not match since it is Ordinal
1192 AssertCompare ("#5", -133, "AE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
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);
1206 public void OrdinalIgnoreCaseIndexOf ()
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);
1214 public void OrdinalIgnoreCaseIndexOfChar ()
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);
1222 public void OrdinalIgnoreCaseLastIndexOf ()
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);
1232 public void OrdinalIgnoreCaseLastIndexOfChar ()
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);
1239 [Test] // bug #80865
1240 public void IsPrefixOrdinalIgnoreCase ()
1242 Assert.IsTrue ("aaaa".StartsWith ("A", StringComparison.OrdinalIgnoreCase));
1247 [ExpectedException (typeof (ArgumentNullException))]
1248 public void IsPrefix_SourceNull ()
1250 invariant.IsPrefix (null, "b");
1254 [ExpectedException (typeof (ArgumentNullException))]
1255 public void IsPrefix_PrefixNull ()
1257 invariant.IsPrefix ("a", null, CompareOptions.None);
1261 public void IsPrefix_PrefixEmpty ()
1263 Assert.IsTrue (invariant.IsPrefix ("a", String.Empty));
1267 [ExpectedException (typeof (ArgumentException))]
1268 public void IsPrefix_CompareOptions_Invalid ()
1270 invariant.IsPrefix ("a", "b", (CompareOptions) Int32.MinValue);
1274 [ExpectedException (typeof (ArgumentException))]
1275 public void IsPrefix_CompareOptions_StringSort ()
1277 invariant.IsPrefix ("a", "b", CompareOptions.StringSort);
1281 [ExpectedException (typeof (ArgumentNullException))]
1282 public void IsSuffix_SourceNull ()
1284 invariant.IsSuffix (null, "b");
1288 [ExpectedException (typeof (ArgumentNullException))]
1289 public void IsSuffix_SuffixNull ()
1291 invariant.IsSuffix ("a", null, CompareOptions.None);
1295 public void IsSuffix_PrefixEmpty ()
1297 Assert.IsTrue (invariant.IsSuffix ("a", String.Empty));
1301 [ExpectedException (typeof (ArgumentException))]
1302 public void IsSuffix_CompareOptions_Invalid ()
1304 invariant.IsSuffix ("a", "b", (CompareOptions) Int32.MinValue);
1308 [ExpectedException (typeof (ArgumentException))]
1309 public void IsSuffix_CompareOptions_StringSort ()
1311 invariant.IsSuffix ("a", "b", CompareOptions.StringSort);
1315 [ExpectedException (typeof (ArgumentException))]
1316 public void Compare_String_String_CompareOptions_Invalid ()
1318 // validation of CompareOptions is made before null checks
1319 invariant.Compare (null, null, (CompareOptions) Int32.MinValue);
1323 public void Compare_String_String_CompareOptions_StringSort ()
1325 // StringSort is valid for Compare only
1326 Assert.AreEqual (-1, invariant.Compare ("a", "b", CompareOptions.StringSort));
1330 [ExpectedException (typeof (ArgumentException))]
1331 public void Compare_String_Int_String_Int_CompareOptions_Invalid ()
1333 invariant.Compare (null, 0, null, 0, (CompareOptions) Int32.MinValue);
1337 [ExpectedException (typeof (ArgumentException))]
1338 public void Compare_String_Int_Int_String_Int_Int_CompareOptions_Invalid ()
1340 invariant.Compare (null, 0, 0, null, 0, 0, (CompareOptions) Int32.MinValue);
1344 [ExpectedException (typeof (ArgumentException))]
1345 public void IndexOf_String_Char_Int_Int_CompareOptions_Invalid ()
1347 invariant.IndexOf ("a", 'a', 0, 1, (CompareOptions) Int32.MinValue);
1351 [ExpectedException (typeof (ArgumentException))]
1352 public void IndexOf_String_Char_Int_Int_CompareOptions_StringSort ()
1354 invariant.IndexOf ("a", 'a', 0, 1, CompareOptions.StringSort);
1358 [ExpectedException (typeof (ArgumentException))]
1359 public void IndexOf_String_String_Int_Int_CompareOptions_Invalid ()
1361 invariant.IndexOf ("a", "a", 0, 1, (CompareOptions) Int32.MinValue);
1365 [ExpectedException (typeof (ArgumentException))]
1366 public void IndexOf_String_String_Int_Int_CompareOptions_StringSort ()
1368 invariant.IndexOf ("a", "a", 0, 1, CompareOptions.StringSort);
1372 [ExpectedException (typeof (ArgumentException))]
1373 public void LastIndexOf_String_Char_Int_Int_CompareOptions_Invalid ()
1375 invariant.LastIndexOf ("a", 'a', 0, 1, (CompareOptions) Int32.MinValue);
1379 [ExpectedException (typeof (ArgumentException))]
1380 public void LastIndexOf_String_Char_Int_Int_CompareOptions_StringSort ()
1382 invariant.LastIndexOf ("a", 'a', 0, 1, CompareOptions.StringSort);
1386 [ExpectedException (typeof (ArgumentException))]
1387 public void LastIndexOf_String_String_Int_Int_CompareOptions_Invalid ()
1389 invariant.LastIndexOf ("a", "a", 0, 1, (CompareOptions) Int32.MinValue);
1393 [ExpectedException (typeof (ArgumentException))]
1394 public void LastIndexOf_String_String_Int_Int_CompareOptions_StringSort ()
1396 invariant.LastIndexOf ("a", "a", 0, 1, CompareOptions.StringSort);