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 ()
255 Assert.Ignore ("Test is disabled.");
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 ()
291 Assert.Ignore ("Test is disabled.");
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 ()
307 Assert.Ignore ("Test is disabled.");
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 ()
360 Assert.Ignore ("Test is disabled.");
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 ()
380 Assert.Ignore ("Test is disabled.");
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 ()
471 Assert.Ignore ("Test is disabled.");
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;
505 if (option == CompareOptions.OrdinalIgnoreCase || option == CompareOptions.Ordinal) {
507 french.GetSortKey ("foo", option);
508 Assert.Fail ("#1: " + option.ToString ());
509 } catch (ArgumentException ex) {
510 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2: " + option.ToString ());
511 Assert.IsNotNull (ex.Message, "#2: " + option.ToString ());
512 Assert.IsNotNull (ex.ParamName, "#3: " + option.ToString ());
513 Assert.AreEqual ("options", ex.ParamName, "#4: " + option.ToString ());
514 Assert.IsNull (ex.InnerException, "#5: " + option.ToString ());
517 french.GetSortKey ("foo", option);
523 [Category ("NotDotNet")]
524 public void FrenchSort ()
527 Assert.Ignore ("Test is disabled.");
530 AssertSortKey ("#inv-1", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "c\u00F4te");
531 AssertSortKey ("#inv-1-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "co\u0302te");
532 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");
533 AssertSortKey ("#inv-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 2, 2, 0xE, 1, 1, 1, 0}, "cot\u00E9");
534 AssertSortKey ("#inv-2-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x14, 1, 1, 1, 0}, "co\u030Cte");
535 // They are all bugs in 2.0:
536 // #inv-3: should not be 0 since those sortkey values differ.
537 // #inv-4: should not be -1 since co\u0302te sortkey is bigger than cote\u0306.
538 AssertCompare ("#inv-3", 1, "c\u00F4te", "cot\u00E9");
539 AssertCompare ("#inv-4", 1, "co\u0302te", "cote\u0306");
540 AssertCompare ("#inv-5", 1, "co\u030Cte", "cote\u0306");
543 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);
544 AssertSortKey ("#fr-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 0xE, 1, 1, 1, 0}, "cot\u00E9", CompareOptions.None, french);
545 AssertCompare ("#fr-3", -1, "c\u00F4te", "cot\u00E9", CompareOptions.None, french);
546 // FIXME: why does .NET return 1 ?
547 // AssertCompare ("#fr-4", -1, "co\u0302te", "cote\u0306", CompareOptions.None, french);
548 // AssertCompare ("#fr-4", -1, "co\u030Cte", "cote\u0306", CompareOptions.None, french);
552 public void GetSortKeyThai ()
555 Assert.Ignore ("Test is disabled.");
557 AssertSortKey ("#i1", new byte [] {
558 0x1E, 7, 0x1F, 0x28, 1, 3, 3, 1, 1, 1, 0},
560 AssertSortKey ("#i2", new byte [] {
561 0x1E, 7, 1, 3, 1, 1, 1, 0},
563 // FIXME: not working (table fix required)
564 // AssertSortKey ("#i6", new byte [] {
565 // 0x1E, 7, 0xA, 0xF9, 1, 3, 1, 1, 1, 0},
567 AssertSortKey ("#i7", new byte [] {
568 0x1E, 7, 0x1E, 2, 1, 3, 3, 1, 1, 1, 0},
570 AssertSortKey ("#i8", new byte [] {
571 0x1E, 7, 0x1E, 3, 1, 3, 3, 1, 1, 1, 0},
573 AssertSortKey ("#i9", new byte [] {
574 0x1E, 7, 0x1E, 4, 1, 3, 3, 1, 1, 1, 0},
576 AssertSortKey ("#i10", new byte [] {
577 0x1E, 7, 0x1E, 5, 1, 3, 3, 1, 1, 1, 0},
579 AssertSortKey ("#i11", new byte [] {
580 0x1E, 7, 0x1E, 6, 1, 3, 3, 1, 1, 1, 0},
582 AssertSortKey ("#i12", new byte [] {
583 0x1E, 7, 0x1F, 0x29, 1, 3, 3, 1, 1, 1, 0},
585 AssertSortKey ("#i13", new byte [] {
586 0x1E, 7, 0x1F, 0x2A, 1, 3, 3, 1, 1, 1, 0},
588 // FIXME: not working (U+E47 table fix required)
589 // AssertSortKey ("#i14", new byte [] {
590 // 0x1E, 7, 1, 5, 1, 1, 1, 0},
592 AssertSortKey ("#i15", new byte [] {
593 0x1E, 7, 1, 6, 1, 1, 1, 0},
595 AssertSortKey ("#i16", new byte [] {
596 0x1E, 7, 1, 7, 1, 1, 1, 0},
598 AssertSortKey ("#i17", new byte [] {
599 0x1E, 7, 1, 8, 1, 1, 1, 0},
601 AssertSortKey ("#i18", new byte [] {
602 0x1E, 7, 1, 9, 1, 1, 1, 0},
604 // FIXME: not working (U+E47 table fix required)
605 // AssertSortKey ("#i19", new byte [] {
606 // 0x1E, 7, 1, 8, 1, 1, 1, 0},
607 // "\u0E01\u0E48\u0E47");
608 AssertSortKey ("#i20", new byte [] {
609 0x1E, 7, 0x1E, 4, 0x1E, 0xD, 1, 3, 3, 3, 1, 1, 1, 0},
610 "\u0E01\u0E42\u0E02");
611 AssertSortKey ("#i21", new byte [] {
612 0x1E, 7, 0x1E, 0xD, 1, 3, 3, 1, 1, 1, 0},
617 public void GetSortKeyCzechTailoring ()
620 Assert.Ignore ("Test is disabled.");
622 AssertSortKey ("#i1", new byte [] {
623 0xE, 0xA, 0xE, 0x2C, 1, 1, 1, 1, 0},
625 AssertSortKey ("#cs1", new byte [] {
626 0xE, 0x2E, 1, 1, 1, 1, 0},
627 "ch", CompareOptions.None, czech);
628 AssertSortKey ("#i2", new byte [] {
629 0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
631 AssertSortKey ("#cs2", new byte [] {
632 0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
633 "r\u030C", CompareOptions.None, czech);
637 public void GetSortKeyHungarianTailoring ()
640 Assert.Ignore ("Test is disabled.");
642 AssertSortKey ("#1", new byte [] {
643 0xE, 0xE, 1, 1, 0x1A, 1, 1, 0},
644 "CS", CompareOptions.None, hungarian);
645 AssertSortKey ("#2", new byte [] {
646 0xE, 0xE, 1, 1, 0x12, 1, 1, 0},
647 "Cs", CompareOptions.None, hungarian);
648 AssertSortKey ("#3", new byte [] {
649 0xE, 0xE, 1, 1, 1, 1, 0},
650 "cs", CompareOptions.None, hungarian);
651 AssertSortKey ("#4", new byte [] {
652 0xE, 0x1C, 1, 1, 0x1A, 1, 1, 0},
653 "DZ", CompareOptions.None, hungarian);
654 AssertSortKey ("#5", new byte [] {
655 0xE, 0x1C, 1, 1, 0x12, 1, 1, 0},
656 "Dz", CompareOptions.None, hungarian);
657 AssertSortKey ("#6", new byte [] {
658 0xE, 0x1C, 1, 1, 1, 1, 0},
659 "dz", CompareOptions.None, hungarian);
660 AssertSortKey ("#7", new byte [] {
661 0xE, 0x75, 1, 1, 0x1A, 1, 1, 0},
662 "NY", CompareOptions.None, hungarian);
663 AssertSortKey ("#8", new byte [] {
664 0xE, 0x75, 1, 1, 0x12, 1, 1, 0},
665 "Ny", CompareOptions.None, hungarian);
666 AssertSortKey ("#9", new byte [] {
667 0xE, 0x75, 1, 1, 1, 1, 0},
668 "ny", CompareOptions.None, hungarian);
669 AssertSortKey ("#10", new byte [] {
670 0xE, 0xB1, 1, 1, 0x1A, 1, 1, 0},
671 "ZS", CompareOptions.None, hungarian);
672 AssertSortKey ("#11", new byte [] {
673 0xE, 0xB1, 1, 1, 0x12, 1, 1, 0},
674 "Zs", CompareOptions.None, hungarian);
675 AssertSortKey ("#12", new byte [] {
676 0xE, 0xB1, 1, 1, 1, 1, 0},
677 "zs", CompareOptions.None, hungarian);
679 // Windows seems to have bugs around repetitive characters
681 // AssertSortKey ("#x", new byte [] {
682 // 0xE, 0x2E, 1, 1, 1, 1, 0},
683 // "CCS", CompareOptions.None, hungarian);
685 // FIXME: we need to handle case insensitivity
689 public void CustomCJKTable ()
692 Assert.Ignore ("Test is disabled.");
694 AssertSortKey ("#1", new byte [] {
695 0x9E, 9, 0x9E, 0x11, 1, 1, 1, 1, 0},
697 AssertSortKey ("#2", new byte [] {
698 0x84, 0xD3, 0x84, 0x61, 1, 1, 1, 1, 0},
699 "\u4E03\u4E09", CompareOptions.None, japanese);
703 [Category ("NotDotNet")]
704 public void CultureSensitiveCompare ()
707 Assert.Ignore ("Test is disabled.");
709 AssertCompare ("#1", -1, "1", "2");
710 AssertCompare ("#2", 1, "A", "a");
711 AssertCompare ("#3", 0, "A", "a", CompareOptions.IgnoreCase);
712 AssertCompare ("#4", 0, "\uFF10", "0", CompareOptions.IgnoreWidth);
713 AssertCompare ("#5", 0, "\uFF21", "a", ignoreCW);
714 AssertCompare ("#6", 1, "12", "1");
715 // BUG in .NET 2.0: See GetSortKey() test that assures sortkeys for "AE" and
716 // "\u00C6" are equivalent.
717 AssertCompare ("#7", 0, "AE", "\u00C6");
718 AssertCompare ("#8", 0, "AB\u01c0C", "A\u01c0B\u01c0C", CompareOptions.IgnoreSymbols);
719 // BUG in .NET 2.0: ditto.
720 AssertCompare ("#9", 0, "A\u0304", "\u0100");
721 AssertCompare ("#10", 1, "ABCABC", 5, 1, "1", 0, 1, CompareOptions.IgnoreCase, invariant);
722 AssertCompare ("#11", 0, "-d:NET_2_0", 0, 1, "-", 0, 1);
724 // BUG in .NET 2.0: ditto.
725 AssertCompare ("#12", 0, "ae", "\u00E6");
726 AssertCompare ("#13", 0, "\u00E6", "ae");
727 AssertCompare ("#14", 0, "\u00E6s", 0, 1, "ae", 0, 2);
729 // target is "empty" (in culture-sensitive context).
730 // BUG in .NET 2.0: \u3007 is totally-ignored character as a GetSortKey()
731 // result, while it is not in Compare().
732 AssertCompare ("#17", 0, String.Empty, "\u3007");
733 AssertCompare ("#18", 1, "A", "\u3007");
734 AssertCompare ("#19", 1, "ABC", "\u3007");
736 // shift weight comparison
737 AssertCompare ("#20", 1, "--start", "--");
739 // BUG in .NET 2.0: the same 00C6/00E6 issue.
740 AssertCompare ("#21", -1, "\u00E6", "aes");
743 AssertCompare ("#22", -1, "++)", "+-+)");
744 AssertCompare ("#23", -1, "+-+)", "+-+-)");
745 AssertCompare ("#24", 1, "+-+-)", "++)");
746 // BUG in .NET: it returns 1
747 AssertCompare ("#25", -1, "+-+-)", "-+-+)");
748 AssertCompare ("#26", -1, "+-+)", "-+-+)");
749 AssertCompare ("#27", -1, "++)", "-+-+)");
751 AssertCompare ("#28", 1, "aa ", "A");
755 [Category ("NotDotNet")]
756 public void CompareSpecialWeight ()
759 Assert.Ignore ("Test is disabled.");
761 // Japanese (in invariant)
762 // BUG in .NET 2.0 : half-width kana should be bigger.
763 AssertCompare ("#1", 1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
764 AssertCompare ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
765 AssertCompare ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
766 "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
767 AssertCompare ("#4", 1, "\u3042\u309D", "\u3042\u3042");
768 AssertCompare ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
769 AssertCompare ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
770 "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
772 // extender in target
773 // BUG in .NET 2.0 : an extender should result in bigger sortkey
774 AssertCompare ("#7", -1, "\u30D1\u30A2", "\u30D1\u30FC");
775 AssertCompare ("#8", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
776 // extender in source
777 // BUG in .NET 2.0 : vice versa
778 AssertCompare ("#9", 1, "\u30D1\u30FC", "\u30D1\u30A2");
779 AssertCompare ("#10", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
783 public void IndexOfChar ()
786 Assert.Ignore ("Test is disabled.");
788 AssertIndexOf ("#1", -1, "ABC", '1');
789 AssertIndexOf ("#2", 2, "ABCABC", 'c', CompareOptions.IgnoreCase);
790 AssertIndexOf ("#3", 1, "ABCABC", '\uFF22', ignoreCW);
791 AssertIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN);
792 AssertIndexOf ("#5", 1, "ABCABC", 'B', 1, 5, CompareOptions.IgnoreCase, invariant);
793 AssertIndexOf ("#6", 4, "ABCABC", 'B', 2, 4, CompareOptions.IgnoreCase, invariant);
794 AssertIndexOf ("#7", 1, "\u30D1\u30FC", '\u30A2', CompareOptions.IgnoreNonSpace);
795 AssertIndexOf ("#8", 1, "UAE", '\u00C6');
796 AssertIndexOf ("#8-2", 1, "AAE", '\u00C6');
797 AssertIndexOf ("#9", -1, "UA", '\u00C6');
798 AssertIndexOf ("#10", -1, "UE", '\u00C6');
802 [Category ("NotDotNet")]
803 public void IndexOfCharMSBug ()
806 Assert.Ignore ("Test is disabled.");
808 AssertIndexOf ("#1", 0, "\u00E6", 'a');
812 public void LastIndexOfChar ()
815 Assert.Ignore ("Test is disabled.");
817 AssertLastIndexOf ("#1", -1, "ABC", '1');
818 AssertLastIndexOf ("#2", 5, "ABCABC", 'c', CompareOptions.IgnoreCase);
819 AssertLastIndexOf ("#3", 4, "ABCABC", '\uFF22', ignoreCW);
820 AssertLastIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN);
821 AssertLastIndexOf ("#5", 1, "ABCABC", 'B', 3, 3);
822 AssertLastIndexOf ("#6", 4, "ABCABC", 'B', 4, 4);
823 AssertLastIndexOf ("#7", -1, "ABCABC", 'B', 5, 1);
824 AssertLastIndexOf ("#8", 1, "UAE", '\u00C6');
825 AssertLastIndexOf ("#8-2", 1, "UAEE", '\u00C6');
826 AssertLastIndexOf ("#9", -1, "UA", '\u00C6');
827 AssertLastIndexOf ("#10", -1, "UE", '\u00C6');
828 AssertLastIndexOf ("#11", 0, "\\", '\\');
829 Assert.AreEqual (0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\", '\\'), "#11en");
830 Assert.AreEqual (0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\", '\\'), "#11ja");
831 AssertLastIndexOf ("#12", 8, "/system/web", 'w');
832 Assert.AreEqual (8, new CultureInfo ("sv").CompareInfo.LastIndexOf ("/system/web", 'w'), "#12sv");
836 [Category ("NotDotNet")]
837 public void LastIndexOfCharMSBug ()
840 Assert.Ignore ("Test is disabled.");
842 AssertIndexOf ("#1", 0, "\u00E6", 'a');
846 [Category ("NotDotNet")]
847 public void IsPrefix ()
850 Assert.Ignore ("Test is disabled.");
852 AssertIsPrefix ("#1", false, "ABC", "c", CompareOptions.IgnoreCase);
853 AssertIsPrefix ("#2", false, "BC", "c", CompareOptions.IgnoreCase);
854 AssertIsPrefix ("#3", true, "C", "c", CompareOptions.IgnoreCase);
855 AssertIsPrefix ("#4", true, "EDCBA", "\u0117", ignoreCN);
856 AssertIsPrefix ("#5", true, "ABC", "AB", CompareOptions.IgnoreCase);
857 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
858 AssertIsPrefix ("#6", true, "ae", "\u00E6", CompareOptions.None);
859 AssertIsPrefix ("#7", true, "\u00E6", "ae", CompareOptions.None);
861 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
862 AssertIsPrefix ("#8", true, "\u00E6", "a", CompareOptions.None);
863 AssertIsPrefix ("#9", true, "\u00E6s", "ae", CompareOptions.None);
864 AssertIsPrefix ("#10", false, "\u00E6", "aes", CompareOptions.None);
865 AssertIsPrefix ("#11", true, "--start", "--", CompareOptions.None);
866 AssertIsPrefix ("#12", true, "-d:NET_1_1", "-", CompareOptions.None);
867 AssertIsPrefix ("#13", false, "-d:NET_1_1", "@", CompareOptions.None);
868 // U+3007 is completely ignored character.
869 AssertIsPrefix ("#14", true, "\uff21\uff21", "\uff21", CompareOptions.None);
870 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
871 AssertIsPrefix ("#15", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
872 AssertIsPrefix ("#16", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
873 AssertIsPrefix ("#17", true, "\\b\\a a", "\\b\\a a");
874 Assert.IsTrue (new CultureInfo ("en").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"), "#17en");
875 Assert.IsTrue (new CultureInfo ("ja").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"), "#17ja");
879 public void IsPrefixSpecialWeight ()
882 Assert.Ignore ("Test is disabled.");
884 // Japanese (in invariant)
885 AssertIsPrefix ("#1", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
886 AssertIsPrefix ("#2", true, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
887 AssertIsPrefix ("#2-2", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
888 AssertIsPrefix ("#3", true, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
889 "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
890 AssertIsPrefix ("#3-2", false, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
891 "\u30C0\u30A4\u30D6");
892 AssertIsPrefix ("#4", false, "\u3042\u309D", "\u3042\u3042");
893 AssertIsPrefix ("#5", true, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
894 AssertIsPrefix ("#6", true, "\uFF8A\uFF9E\uFF70\uFF99",
895 "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
897 // extender in target
898 AssertIsPrefix ("#7", false, "\u30D1\u30A2", "\u30D1\u30FC");
899 AssertIsPrefix ("#8", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
900 // extender in source
901 AssertIsPrefix ("#9", false, "\u30D1\u30FC", "\u30D1\u30A2");
902 AssertIsPrefix ("#10", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
904 // empty suffix always matches the source.
905 AssertIsPrefix ("#11", true, "", "");
906 AssertIsPrefix ("#12", true, "/test.css", "");
909 AssertIsPrefix ("#13", false, "\u00e4_", "a");
913 [Category ("NotDotNet")]
914 public void IsSuffix ()
917 Assert.Ignore ("Test is disabled.");
919 AssertIsSuffix ("#1", true, "ABC", "c", CompareOptions.IgnoreCase);
920 AssertIsSuffix ("#2", true, "BC", "c", CompareOptions.IgnoreCase);
921 AssertIsSuffix ("#3", false, "CBA", "c", CompareOptions.IgnoreCase);
922 AssertIsSuffix ("#4", true, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
923 AssertIsSuffix ("#5", false, "\u00E6", "a", CompareOptions.None);
924 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
925 AssertIsSuffix ("#6", true, "\u00E6", "ae", CompareOptions.None);
926 AssertIsSuffix ("#7", true, "ae", "\u00E6", CompareOptions.None);
927 AssertIsSuffix ("#8", false, "e", "\u00E6", CompareOptions.None);
928 // U+3007 is completely ignored character.
929 AssertIsSuffix ("#9", true, "\uff21\uff21", "\uff21", CompareOptions.None);
930 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
931 AssertIsSuffix ("#10", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
932 AssertIsSuffix ("#11", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
933 // extender in target
934 AssertIsSuffix ("#12", false, "\u30D1\u30A2", "\u30D1\u30FC");
935 AssertIsSuffix ("#13", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
936 // extender in source
937 AssertIsSuffix ("#14", false, "\u30D1\u30FC", "\u30D1\u30A2");
938 AssertIsSuffix ("#15", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
939 // optimization sanity check
940 AssertIsSuffix ("#16", true,
941 "/configuration/system.runtime.remoting",
942 "system.runtime.remoting");
944 // empty suffix always matches the source.
945 AssertIsSuffix ("#17", true, "", "");
946 AssertIsSuffix ("#18", true, "/test.css", "");
947 AssertIsSuffix ("#19", true, "/test.css", "/test.css");
948 AssertIsSuffix ("#20", true, "\\b\\a a", "\\b\\a a");
949 Assert.IsTrue (new CultureInfo ("en").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"), "#20en");
950 Assert.IsTrue (new CultureInfo ("ja").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"), "#20ja");
954 [Category ("NotDotNet")]
955 [Category ("NotWorking")]
956 public void IsSuffixMSBug ()
959 Assert.Ignore ("Test is disabled.");
961 AssertIsSuffix ("#1", true, "\u00E6", "e", CompareOptions.None);
965 public void IndexOfString ()
968 Assert.Ignore ("Test is disabled.");
970 AssertIndexOf ("#0", 0, "", "", CompareOptions.None);
971 AssertIndexOf ("#1", -1, "ABC", "1", CompareOptions.None);
972 AssertIndexOf ("#2", 2, "ABCABC", "c", CompareOptions.IgnoreCase);
973 AssertIndexOf ("#3", 1, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
974 AssertIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
975 AssertIndexOf ("#5", 1, "ABCABC", "BC", CompareOptions.IgnoreCase);
976 AssertIndexOf ("#6", 1, "BBCBBC", "BC", CompareOptions.IgnoreCase);
977 AssertIndexOf ("#7", -1, "ABCDEF", "BCD", 0, 3, CompareOptions.IgnoreCase, invariant);
978 AssertIndexOf ("#8", 0, "-ABC", "-", CompareOptions.None);
979 AssertIndexOf ("#9", 0, "--ABC", "--", CompareOptions.None);
980 AssertIndexOf ("#10", -1, "--ABC", "--", 1, 2, CompareOptions.None, invariant);
982 // U+3007 is completely ignored character.
983 AssertIndexOf ("#12", 0, "\uff21\uff21", "\uff21", CompareOptions.None);
985 AssertIndexOf ("#14", 0, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
986 AssertIndexOf ("#15", 0, "\uff21\uff21", "\u3007", CompareOptions.None);
987 AssertIndexOf ("#15-2", 1, "\u3007\uff21", "\uff21", CompareOptions.None);
988 // target is "empty" (in culture-sensitive context).
989 AssertIndexOf ("#16", -1, String.Empty, "\u3007");
991 AssertIndexOf ("#18", 0, "ABC", "\u3007");
993 AssertIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
994 Assert.AreEqual (0, new CultureInfo ("en").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"), "#19en");
995 Assert.AreEqual (0, new CultureInfo ("ja").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"), "#19ja");
999 [Category ("NotDotNet")]
1000 public void IndexOfStringWeird ()
1002 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1003 AssertIndexOf ("#11", 0, "AE", "\u00C6", CompareOptions.None);
1005 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1006 AssertIndexOf ("#13", 0, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
1008 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1009 AssertIndexOf ("#17", 0, "A", "\u3007");
1013 public void IndexOfSpecialWeight ()
1016 Assert.Ignore ("Test is disabled.");
1018 // Japanese (in invariant)
1019 AssertIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1020 // extender in target
1021 AssertIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
1022 AssertIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
1023 // extender in source
1024 AssertIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
1025 AssertIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
1026 AssertIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
1027 AssertIndexOf ("#2-2", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1028 AssertIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
1029 "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
1030 AssertIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
1031 AssertIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
1032 AssertIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
1033 "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
1038 public void LastIndexOfString ()
1041 Assert.Ignore ("Test is disabled.");
1043 AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions.None);
1044 AssertLastIndexOf ("#2", 5, "ABCABC", "c", CompareOptions.IgnoreCase);
1045 AssertLastIndexOf ("#3", 4, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
1046 AssertLastIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
1047 AssertLastIndexOf ("#5", 4, "ABCABC", "BC", CompareOptions.IgnoreCase);
1048 AssertLastIndexOf ("#6", 4, "BBCBBC", "BC", CompareOptions.IgnoreCase);
1049 AssertLastIndexOf ("#7", 1, "original", "rig", CompareOptions.None);
1051 AssertLastIndexOf ("#9", 0, "-ABC", "-", CompareOptions.None);
1052 AssertLastIndexOf ("#10", 0, "--ABC", "--", CompareOptions.None);
1053 AssertLastIndexOf ("#11", -1, "--ABC", "--", 2, 2, CompareOptions.None, invariant);
1054 AssertLastIndexOf ("#12", -1, "--ABC", "--", 4, 2, CompareOptions.None, invariant);
1056 // U+3007 is completely ignored character.
1057 AssertLastIndexOf ("#14", 1, "\uff21\uff21", "\uff21", CompareOptions.None);
1059 AssertLastIndexOf ("#16", 1, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
1060 AssertLastIndexOf ("#17", 1, "\uff21\uff21", "\u3007", CompareOptions.None);
1061 AssertLastIndexOf ("#18", 1, "\u3007\uff21", "\uff21", CompareOptions.None);
1062 AssertLastIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
1063 Assert.AreEqual (0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"), "#19en");
1064 Assert.AreEqual (0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"), "#19ja");
1066 AssertLastIndexOf ("#20", 8, "/system/web", "w");
1067 Assert.AreEqual (8, new CultureInfo ("sv").CompareInfo.LastIndexOf ("/system/web", "w"), "#20sv");
1069 AssertLastIndexOf ("#21", 2, "foo", String.Empty);
1073 [Category ("NotDotNet")]
1074 public void LastIndexOfStringDotnetWeird ()
1077 Assert.Ignore ("Test is disabled.");
1079 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1080 AssertLastIndexOf ("#8", 0, "\u00E6", "ae", CompareOptions.None);
1082 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1083 AssertLastIndexOf ("#13", 0, "AE", "\u00C6", CompareOptions.None);
1085 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1086 AssertLastIndexOf ("#15", 1, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
1090 public void LastIndexOfSpecialWeight ()
1093 Assert.Ignore ("Test is disabled.");
1095 // Japanese (in invariant)
1096 AssertLastIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1097 // extender in target
1098 AssertLastIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
1099 AssertLastIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
1100 // extender in source
1101 AssertLastIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
1102 // FIXME: not working (extender support is not complete.
1103 // Currently private IsPrefix() cannot handle heading
1104 // extenders to consume previous primary char.)
1105 // AssertLastIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
1106 // this shows that Windows accesses beyond the length and
1107 // acquires the corresponding character to expand.
1108 // AssertLastIndexOf ("#1-6", 1, "\u30D1\u30FC", "\u30A2", 1, 1, CompareOptions.IgnoreNonSpace, invariant);
1109 AssertLastIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
1110 AssertLastIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
1111 "\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
1112 AssertLastIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
1113 AssertLastIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
1114 AssertLastIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
1115 "\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
1119 public void LastIndexOfOrdinalString ()
1122 Assert.Ignore ("Test is disabled.");
1124 AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions.Ordinal);
1125 AssertLastIndexOf ("#2", 5, "ABCABC", "C", CompareOptions.Ordinal);
1126 AssertLastIndexOf ("#3", -1, "ABCABC", "\uFF22", CompareOptions.Ordinal);
1127 AssertLastIndexOf ("#4", 4, "ABCABC", "BC", CompareOptions.Ordinal);
1128 AssertLastIndexOf ("#5", 4, "BBCBBC", "BC", CompareOptions.Ordinal);
1129 AssertLastIndexOf ("#6", 1, "original", "rig", CompareOptions.Ordinal);
1130 AssertLastIndexOf ("#7", 0, "\\b\\a a", "\\b\\a a", CompareOptions.Ordinal);
1134 public void NullCharacter ()
1137 Assert.AreEqual (-1, "MONO".IndexOf ("\0\0\0"), "#1");
1138 Assert.AreEqual (-1, "MONO".LastIndexOf ("\0\0\0"), "#2");
1139 Assert.AreEqual (1, "MONO".CompareTo ("\0\0\0"), "#3");
1141 // I don't really understand why they are so...
1142 AssertIndexOf ("#4", 0, "\0\0", "\0");
1143 AssertIndexOf ("#5", -1, "\0", "\0\0");
1144 AssertIndexOf ("#6", -1, "foo", "\0");
1145 AssertLastIndexOf ("#7", 1, "\0\0", "\0");
1146 AssertLastIndexOf ("#8", -1, "\0", "\0\0");
1147 AssertLastIndexOf ("#9", -1, "foo", "\0");
1151 // LAMESPEC: MS.NET treats it as equivalent, while in IndexOf() it does not match.
1152 public void NullCharacterWeird ()
1154 Assert.AreEqual (0, "MONO".CompareTo ("MONO\0\0\0"), "#4");
1158 [Category ("NotDotNet")]
1159 public void OrdinalIgnoreCaseCompare ()
1162 Assert.Ignore ("Test is disabled.");
1165 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1166 AssertCompare ("#1", 0, "AE", "\u00C6", CompareOptions.None);
1167 // BUG in .NET 2.0 : It raises inappropriate ArgumentException.
1168 // should not match since it is Ordinal
1169 AssertCompare ("#2", -133, "AE", "\u00C6", CompareOptions.OrdinalIgnoreCase);
1171 AssertCompare ("#3", 1, "AE", "\u00E6", CompareOptions.None);
1173 AssertCompare ("#4", 0, "AE", "\u00E6", CompareOptions.IgnoreCase);
1174 // should not match since it is Ordinal
1175 AssertCompare ("#5", -133, "AE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
1177 AssertCompare ("#6", 0, "AE", "ae", CompareOptions.OrdinalIgnoreCase);
1178 AssertCompare ("#7", 0, "aE", "ae", CompareOptions.OrdinalIgnoreCase);
1179 AssertCompare ("#8", 0, "aE", "ae", CompareOptions.OrdinalIgnoreCase);
1180 AssertCompare ("#9", 0, "ae", "ae", CompareOptions.OrdinalIgnoreCase);
1181 AssertCompare ("#10", 0, "AE", "AE", CompareOptions.OrdinalIgnoreCase);
1182 AssertCompare ("#11", 0, "aE", "AE", CompareOptions.OrdinalIgnoreCase);
1183 AssertCompare ("#12", 0, "aE", "AE", CompareOptions.OrdinalIgnoreCase);
1184 AssertCompare ("#13", 0, "ae", "AE", CompareOptions.OrdinalIgnoreCase);
1185 AssertCompare ("#14", 0, "ola", "OLA", CompareOptions.OrdinalIgnoreCase);
1186 // check ignorable characters
1187 AssertCompare ("#15", 0, "AE\uFFFC", "AE", CompareOptions.None);
1188 AssertCompare ("#16", 1, "AE\uFFFC", "AE", CompareOptions.OrdinalIgnoreCase);
1192 public void OrdinalIgnoreCaseIndexOf ()
1194 AssertIndexOf ("#1-1", 0, "ABC", "abc", CompareOptions.OrdinalIgnoreCase);
1195 AssertIndexOf ("#1-2", -1, "AEBECE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
1196 AssertIndexOf ("#1-3", -1, "@_@", "`_`", CompareOptions.OrdinalIgnoreCase);
1200 public void OrdinalIgnoreCaseIndexOfChar ()
1202 AssertIndexOf ("#2-1", 0, "ABC", 'a', CompareOptions.OrdinalIgnoreCase);
1203 AssertIndexOf ("#2-2", -1, "AEBECE", '\u00C0', CompareOptions.OrdinalIgnoreCase);
1204 AssertIndexOf ("#2-3", -1, "@_@", '`', CompareOptions.OrdinalIgnoreCase);
1208 public void OrdinalIgnoreCaseLastIndexOf ()
1210 AssertLastIndexOf ("#1-1", 0, "ABC", "abc", CompareOptions.OrdinalIgnoreCase);
1211 AssertLastIndexOf ("#1-2", -1, "AEBECE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
1212 AssertLastIndexOf ("#1-3", -1, "@_@", "`_`", CompareOptions.OrdinalIgnoreCase);
1213 AssertLastIndexOf ("#1-4", 1, "ABCDE", "bc", CompareOptions.OrdinalIgnoreCase);
1214 AssertLastIndexOf ("#1-5", -1, "BBBBB", "ab", CompareOptions.OrdinalIgnoreCase);
1218 public void OrdinalIgnoreCaseLastIndexOfChar ()
1220 AssertLastIndexOf ("#2-1", 0, "ABC", 'a', CompareOptions.OrdinalIgnoreCase);
1221 AssertLastIndexOf ("#2-2", -1, "AEBECE", '\u00C0', CompareOptions.OrdinalIgnoreCase);
1222 AssertLastIndexOf ("#2-3", -1, "@_@", '`', CompareOptions.OrdinalIgnoreCase);
1225 [Test] // bug #80865
1226 public void IsPrefixOrdinalIgnoreCase ()
1228 Assert.IsTrue ("aaaa".StartsWith ("A", StringComparison.OrdinalIgnoreCase));
1232 [ExpectedException (typeof (ArgumentNullException))]
1233 public void IsPrefix_SourceNull ()
1235 invariant.IsPrefix (null, "b");
1239 [ExpectedException (typeof (ArgumentNullException))]
1240 public void IsPrefix_PrefixNull ()
1242 invariant.IsPrefix ("a", null, CompareOptions.None);
1246 public void IsPrefix_PrefixEmpty ()
1248 Assert.IsTrue (invariant.IsPrefix ("a", String.Empty));
1252 [ExpectedException (typeof (ArgumentException))]
1253 public void IsPrefix_CompareOptions_Invalid ()
1255 invariant.IsPrefix ("a", "b", (CompareOptions) Int32.MinValue);
1259 [ExpectedException (typeof (ArgumentException))]
1260 public void IsPrefix_CompareOptions_StringSort ()
1262 invariant.IsPrefix ("a", "b", CompareOptions.StringSort);
1266 [ExpectedException (typeof (ArgumentNullException))]
1267 public void IsSuffix_SourceNull ()
1269 invariant.IsSuffix (null, "b");
1273 [ExpectedException (typeof (ArgumentNullException))]
1274 public void IsSuffix_SuffixNull ()
1276 invariant.IsSuffix ("a", null, CompareOptions.None);
1280 public void IsSuffix_PrefixEmpty ()
1282 Assert.IsTrue (invariant.IsSuffix ("a", String.Empty));
1286 [ExpectedException (typeof (ArgumentException))]
1287 public void IsSuffix_CompareOptions_Invalid ()
1289 invariant.IsSuffix ("a", "b", (CompareOptions) Int32.MinValue);
1293 [ExpectedException (typeof (ArgumentException))]
1294 public void IsSuffix_CompareOptions_StringSort ()
1296 invariant.IsSuffix ("a", "b", CompareOptions.StringSort);
1300 [ExpectedException (typeof (ArgumentException))]
1301 public void Compare_String_String_CompareOptions_Invalid ()
1303 // validation of CompareOptions is made before null checks
1304 invariant.Compare (null, null, (CompareOptions) Int32.MinValue);
1308 public void Compare_String_String_CompareOptions_StringSort ()
1310 // StringSort is valid for Compare only
1311 Assert.AreEqual (-1, invariant.Compare ("a", "b", CompareOptions.StringSort));
1315 [ExpectedException (typeof (ArgumentException))]
1316 public void Compare_String_Int_String_Int_CompareOptions_Invalid ()
1318 invariant.Compare (null, 0, null, 0, (CompareOptions) Int32.MinValue);
1322 [ExpectedException (typeof (ArgumentException))]
1323 public void Compare_String_Int_Int_String_Int_Int_CompareOptions_Invalid ()
1325 invariant.Compare (null, 0, 0, null, 0, 0, (CompareOptions) Int32.MinValue);
1329 [ExpectedException (typeof (ArgumentException))]
1330 public void IndexOf_String_Char_Int_Int_CompareOptions_Invalid ()
1332 invariant.IndexOf ("a", 'a', 0, 1, (CompareOptions) Int32.MinValue);
1336 [ExpectedException (typeof (ArgumentException))]
1337 public void IndexOf_String_Char_Int_Int_CompareOptions_StringSort ()
1339 invariant.IndexOf ("a", 'a', 0, 1, CompareOptions.StringSort);
1343 [ExpectedException (typeof (ArgumentException))]
1344 public void IndexOf_String_String_Int_Int_CompareOptions_Invalid ()
1346 invariant.IndexOf ("a", "a", 0, 1, (CompareOptions) Int32.MinValue);
1350 [ExpectedException (typeof (ArgumentException))]
1351 public void IndexOf_String_String_Int_Int_CompareOptions_StringSort ()
1353 invariant.IndexOf ("a", "a", 0, 1, CompareOptions.StringSort);
1357 [ExpectedException (typeof (ArgumentException))]
1358 public void LastIndexOf_String_Char_Int_Int_CompareOptions_Invalid ()
1360 invariant.LastIndexOf ("a", 'a', 0, 1, (CompareOptions) Int32.MinValue);
1364 [ExpectedException (typeof (ArgumentException))]
1365 public void LastIndexOf_String_Char_Int_Int_CompareOptions_StringSort ()
1367 invariant.LastIndexOf ("a", 'a', 0, 1, CompareOptions.StringSort);
1371 [ExpectedException (typeof (ArgumentException))]
1372 public void LastIndexOf_String_String_Int_Int_CompareOptions_Invalid ()
1374 invariant.LastIndexOf ("a", "a", 0, 1, (CompareOptions) Int32.MinValue);
1378 [ExpectedException (typeof (ArgumentException))]
1379 public void LastIndexOf_String_String_Int_Int_CompareOptions_StringSort ()
1381 invariant.LastIndexOf ("a", "a", 0, 1, CompareOptions.StringSort);