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");
55 // Culture-sensitive collation tests
57 CompareInfo invariant
= CultureInfo
.InvariantCulture
.CompareInfo
;
58 CompareInfo french
= new CultureInfo ("fr").CompareInfo
;
59 CompareInfo japanese
= new CultureInfo ("ja").CompareInfo
;
60 CompareInfo czech
= new CultureInfo ("cs").CompareInfo
;
61 CompareInfo hungarian
= new CultureInfo ("hu").CompareInfo
;
63 CompareOptions ignoreCW
=
64 CompareOptions
.IgnoreWidth
| CompareOptions
.IgnoreCase
;
65 CompareOptions ignoreCN
=
66 CompareOptions
.IgnoreNonSpace
| CompareOptions
.IgnoreCase
;
68 void AssertSortKey (string message
, byte [] expected
, string test
)
70 AssertSortKey (message
, expected
, test
, CompareOptions
.None
);
73 void AssertSortKey (string message
, byte [] expected
, string test
, CompareOptions opt
)
75 AssertSortKey (message
, expected
, test
, opt
, invariant
);
78 void AssertSortKey (string message
, byte [] expected
, string test
, CompareOptions opt
, CompareInfo ci
)
80 byte [] actual
= ci
.GetSortKey (test
, opt
).KeyData
;
81 Assert
.AreEqual (expected
, actual
, message
);
84 void AssertSortKeyLevel5 (string message
, byte [] expected
, string test
)
86 byte [] tmp
= invariant
.GetSortKey (test
).KeyData
;
88 for (int i
= 0; i
< 4; i
++, idx
++)
89 for (; tmp
[idx
] != 1; idx
++)
91 byte [] actual
= new byte [tmp
.Length
- idx
];
92 Array
.Copy (tmp
, idx
, actual
, 0, actual
.Length
);
93 Assert
.AreEqual (expected
, actual
, message
);
96 void AssertCompare (string message
, int result
, string s1
, string s2
)
98 AssertCompare (message
, result
, s1
, s2
, CompareOptions
.None
);
101 void AssertCompare (string message
, int result
, string s1
, string s2
,
104 AssertCompare (message
, result
, s1
, s2
, opt
, invariant
);
107 void AssertCompare (string message
, int result
, string s1
, string s2
,
108 CompareOptions opt
, CompareInfo ci
)
110 int ret
= ci
.Compare (s1
, s2
, opt
);
112 Assert
.AreEqual (0, ret
, message
);
114 Assert
.IsTrue (ret
< 0, message
+ String
.Format ("(neg: {0})", ret
));
116 Assert
.IsTrue (ret
> 0, message
+ String
.Format ("(pos: {0})", ret
));
119 void AssertCompare (string message
, int result
,
120 string s1
, int idx1
, int len1
, string s2
, int idx2
, int len2
)
122 int ret
= invariant
.Compare (s1
, idx1
, len1
, s2
, idx2
, len2
);
124 Assert
.AreEqual (0, ret
, message
);
126 Assert
.IsTrue (ret
< 0, message
);
128 Assert
.IsTrue (ret
> 0, message
);
131 void AssertCompare (string message
, int result
,
132 string s1
, int idx1
, int len1
, string s2
, int idx2
, int len2
,
133 CompareOptions opt
, CompareInfo ci
)
135 int ret
= ci
.Compare (s1
, idx1
, len1
, s2
, idx2
, len2
, opt
);
137 Assert
.AreEqual (0, ret
, message
);
139 Assert
.IsTrue (ret
< 0, message
);
141 Assert
.IsTrue (ret
> 0, message
);
144 void AssertIndexOf (string message
, int expected
,
145 string source
, char target
)
147 Assert
.AreEqual (expected
, invariant
.IndexOf (source
, target
), message
);
150 void AssertIndexOf (string message
, int expected
, string source
,
151 char target
, CompareOptions opt
)
153 Assert
.AreEqual (expected
, invariant
.IndexOf (source
, target
, opt
), message
);
156 void AssertIndexOf (string message
, int expected
, string source
,
157 char target
, int idx
, int len
, CompareOptions opt
, CompareInfo ci
)
159 Assert
.AreEqual (expected
, ci
.IndexOf (source
, target
, idx
, len
, opt
), message
);
162 void AssertIndexOf (string message
, int expected
,
163 string source
, string target
)
165 Assert
.AreEqual (expected
, invariant
.IndexOf (source
, target
), message
);
168 void AssertIndexOf (string message
, int expected
, string source
,
169 string target
, CompareOptions opt
)
171 Assert
.AreEqual (expected
, invariant
.IndexOf (source
, target
, opt
), message
);
174 void AssertIndexOf (string message
, int expected
, string source
,
175 string target
, int idx
, int len
, CompareOptions opt
, CompareInfo ci
)
177 Assert
.AreEqual (expected
, ci
.IndexOf (source
, target
, idx
, len
, opt
), message
);
180 void AssertLastIndexOf (string message
, int expected
,
181 string source
, char target
)
183 Assert
.AreEqual (expected
, invariant
.LastIndexOf (source
, target
), message
);
186 void AssertLastIndexOf (string message
, int expected
, string source
,
187 char target
, CompareOptions opt
)
189 Assert
.AreEqual (expected
, invariant
.LastIndexOf (source
, target
, opt
), message
);
192 void AssertLastIndexOf (string message
, int expected
, string source
,
193 char target
, int idx
, int len
)
195 Assert
.AreEqual (expected
, invariant
.LastIndexOf (source
, target
, idx
, len
), message
);
198 void AssertLastIndexOf (string message
, int expected
, string source
,
199 char target
, int idx
, int len
, CompareOptions opt
, CompareInfo ci
)
201 Assert
.AreEqual (expected
, ci
.LastIndexOf (source
, target
, idx
, len
, opt
), message
);
204 void AssertLastIndexOf (string message
, int expected
,
205 string source
, string target
)
207 Assert
.AreEqual (expected
, invariant
.LastIndexOf (source
, target
), message
);
210 void AssertLastIndexOf (string message
, int expected
, string source
,
211 string target
, CompareOptions opt
)
213 Assert
.AreEqual (expected
, invariant
.LastIndexOf (source
, target
, opt
), message
);
216 void AssertLastIndexOf (string message
, int expected
, string source
,
217 string target
, int idx
, int len
)
219 Assert
.AreEqual (expected
, invariant
.LastIndexOf (source
, target
, idx
, len
), message
);
222 void AssertLastIndexOf (string message
, int expected
, string source
,
223 string target
, int idx
, int len
, CompareOptions opt
, CompareInfo ci
)
225 Assert
.AreEqual (expected
, ci
.LastIndexOf (source
, target
, idx
, len
, opt
), message
);
228 void AssertIsPrefix (string message
, bool expected
, string source
,
231 Assert
.IsTrue (expected
== invariant
.IsPrefix (source
, target
), message
);
234 void AssertIsPrefix (string message
, bool expected
, string source
,
235 string target
, CompareOptions opt
)
237 Assert
.IsTrue (expected
== invariant
.IsPrefix (source
, target
, opt
), message
);
240 void AssertIsSuffix (string message
, bool expected
, string source
,
243 Assert
.IsTrue (expected
== invariant
.IsSuffix (source
, target
), message
);
246 void AssertIsSuffix (string message
, bool expected
, string source
,
247 string target
, CompareOptions opt
)
249 Assert
.IsTrue (expected
== invariant
.IsSuffix (source
, target
, opt
), message
);
253 public void GetSortKey ()
259 AssertSortKey ("#1", new byte [] {0xE, 2, 0xE, 0x21, 1, 1,
260 0x12, 0x12, 1, 1, 0}, "AE");
261 AssertSortKey ("#2", new byte [] {0xE, 2, 0xE, 0x21, 1, 1,
262 0x12, 0x12, 1, 1, 0}, "\u00C6");
263 AssertSortKey ("#3", new byte [] {1, 1, 1, 1,
264 0x80, 7, 6, 0x82, 0}, "-");
265 AssertSortKey ("#4", new byte [] {1, 1, 1, 1,
266 0x80, 7, 6, 0x82, 0x80, 7, 6, 0x82, 0}, "--");
267 AssertSortKey ("#4", new byte [] {0xE, 2, 0xE, 9,
268 0xE, 0xA, 1, 1, 0x12, 0x12, 0x12, 1, 1, 0x80, 0xB,
269 6, 0x82, 0x80, 0xF, 6, 0x82, 0}, "A-B-C");
270 AssertSortKey ("#6", new byte [] {0xE, 2, 1,
271 0x17, 1, 0x12, 1, 1, 0}, "A\u0304");
272 AssertSortKey ("#7", new byte [] {0xE, 2, 1,
273 0x17, 1, 0x12, 1, 1, 0}, "\u0100");
276 AssertSortKey ("#8", new byte [] {
277 0xE, 2, 6, 0x82, 1, 1, 1, 1, 0},
278 "a-", CompareOptions
.StringSort
);
279 // FIXME: not working (table fix is required)
280 // AssertSortKey ("#9", new byte [] {
281 // 0xE, 2, 6, 0x82, 1, 1, 2, 0x3, 1, 1, 0},
282 // "a\uFF0D", CompareOptions.StringSort);
284 AssertSortKey ("#10", new byte [] {1, 1, 1, 1, 0}
, "\u3007");
289 public void GetSortKeyIgnoreWidth ()
294 AssertSortKey ("#i1", new byte [] {
295 0xE, 2, 1, 1, 0x13, 1, 1, 0}, "\uFF21");
296 AssertSortKey ("#i2", new byte [] {
297 0xE, 2, 1, 1, 0x12, 1, 1, 0}, "\uFF21", CompareOptions
.IgnoreWidth
);
298 AssertSortKey ("#i3", new byte [] {
299 0xE, 2, 1, 1, 0x3, 1, 1, 0}, "\uFF41");
300 AssertSortKey ("#i4", new byte [] {
301 0xE, 2, 1, 1, 1, 1, 0}, "\uFF41", CompareOptions
.IgnoreWidth
);
305 public void GetSortKeyDiacritical ()
310 AssertSortKey ("#i1", new byte [] {
311 0xE, 0x21, 1, 0xE, 1, 1, 1, 0}, "e\u0301");
312 AssertSortKey ("#i2", new byte [] {
313 0xE, 0x21, 1, 0x12, 1, 1, 1, 0}, "e\u0302");
314 AssertSortKey ("#i3", new byte [] {
315 0xE, 0x21, 1, 0x13, 1, 1, 1, 0}, "e\u0308");
316 AssertSortKey ("#i4", new byte [] {
317 0xE, 0x21, 1, 0x1F, 1, 1, 1, 0}, "e\u0308\u0301");
318 // FIXME: not working (table fix is required)
319 // AssertSortKey ("#i5", new byte [] {
320 // 0xE, 0x21, 1, 0x16, 1, 1, 1, 0}, "e\u0344");
321 AssertSortKey ("#i6", new byte [] {
322 0x22, 2, 1, 0xE, 1, 1, 0xC4, 0xFF, 2, 0xFF, 0xFF, 1, 0}, "\u3041\u0301");
323 AssertSortKey ("#i7", new byte [] {
324 0xC, 0x21, 1, 0xE, 1, 1, 1, 0}, "1\u0301");
325 AssertSortKey ("#i8", new byte [] {
326 0x22, 0xA, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0}, "\u304B\u309B");
327 AssertSortKey ("#i9", new byte [] {
328 0x22, 0xA, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0}, "\u304C");
330 AssertSortKey ("#i10", new byte [] {
331 0xE, 0x2, 1, 0x12, 1, 0x12, 1, 1, 0},
333 AssertSortKey ("#i11", new byte [] {
334 0xE, 0x2, 1, 0x65, 1, 0x12, 1, 1, 0},
336 AssertSortKey ("#i12", new byte [] {
337 0xE, 0x2, 1, 0xB8, 1, 0x12, 1, 1, 0},
338 "A\u0302\u0320\u0320");
339 // LAMESPEC: Windows just appends diacritical weight without
340 // AssertSortKey ("#i13", new byte [] {
341 // 0xE, 0x2, 1, 0xB, 1, 12, 1, 1, 0},
342 // "A\u0302\u0320\u0320\u0320");
343 // FIXME: not working (table fix is required)
344 // AssertSortKey ("#i14", new byte [] {
345 // 0xE, 0x2, 1, 0xF2, 1, 0x12, 1, 1, 0},
347 // LAMESPEC: It should not be equivalent to \u1EA6
348 AssertSortKey ("#i15", new byte [] {
349 0xE, 0x2, 1, 0x1F, 1, 0x12, 1, 1, 0},
351 AssertSortKey ("#i16", new byte [] {
352 0xE, 0x2, 1, 0x1F, 1, 0x12, 1, 1, 0},
358 public void GetSortKeyIgnoreNonSpaceKana ()
363 AssertSortKey ("#i1", new byte [] {
364 0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
366 AssertSortKey ("#i2", new byte [] {
367 0x22, 0x1A, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
369 AssertSortKey ("#i3", new byte [] {
370 0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
371 "\u305F", CompareOptions
.IgnoreNonSpace
);
372 AssertSortKey ("#i4", new byte [] {
373 0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
374 "\u3060", CompareOptions
.IgnoreNonSpace
);
378 public void GetSortKeySpecialWeight ()
383 AssertSortKey ("#i1", new byte [] {
384 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
386 AssertSortKey ("#i2", new byte [] {
387 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 5, 2, 0xFF, 0xFF, 1, 0},
389 AssertSortKey ("#i3", new byte [] {
390 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
391 "\u304B\u30FC", CompareOptions
.IgnoreNonSpace
);
393 AssertSortKey ("#i4", new byte [] {
394 0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 2, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
396 AssertSortKey ("#i5", new byte [] {
397 0x22, 0xA, 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
398 "\u30AB\u30AB\u30FC");
399 AssertSortKey ("#i6", new byte [] {
400 0x22, 0xA, 0x22, 2, 0x22, 2, 1, 1, 1, 0xFF, 3, 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
401 "\u30AB\u30A2\u30FC");
402 AssertSortKey ("#i7", new byte [] {
403 0x22, 0xA, 0x22, 2, 0x22, 2, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
404 "\u30AB\u30A2\u30FC\u30AB");
405 AssertSortKey ("#i8", new byte [] {
406 0x22, 0xA, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
408 AssertSortKey ("#i9", new byte [] {
409 0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
411 AssertSortKey ("#i10", new byte [] {
412 0x22, 0x2, 0x22, 0x2, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
413 "\u3042\u309E");//not possible
414 AssertSortKey ("#i11", new byte [] {
415 0x22, 0xA, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
416 "\u304B\u30FD");//not possible
417 AssertSortKey ("#i12", new byte [] {
418 0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
419 "\u304B\u30FE");//not possible
420 AssertSortKey ("#i13", new byte [] {
421 0x22, 0xA, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 4, 2, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
423 AssertSortKey ("#i14", new byte [] {
424 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 5, 2, 0xC4, 0xC4, 0xFF, 0xC4, 0xC4, 0xFF, 1, 0},
426 AssertSortKey ("#i15", new byte [] {
427 0x22, 0xA, 0x22, 0xA, 1, 2, 5, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
429 AssertSortKey ("#i16", new byte [] {
430 0xAF, 9, 0xAF, 9, 1, 2, 5, 1, 1, 1, 0},
432 AssertSortKey ("#i17", new byte [] {
433 0xE, 2, 0xE, 2, 1, 2, 5, 1, 1, 1, 0},
435 // Not working, but I wonder if it is really FIXME.
436 // AssertSortKey ("#i18", new byte [] {
437 // 0xFF, 0xFF, 1, 1, 1, 1, 0},
439 // LAMESPEC. No one can handle \u3031 correctly.
440 // AssertSortKey ("#i19", new byte [] {
441 // 0x22, 0x22, 0x22, 0xC, 0x22, 0xC, 1, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
442 // "\u306A\u304F\u3031");
444 // IgnoreWidth -> all Kana becomes half-width
445 AssertSortKey ("#i20", new byte [] {
446 34, 26, 34, 3, 34, 44, 1, 3, 2, 3, 1, 1, 255, 2, 196, 196, 196, 255, 196, 196, 196, 255, 1, 0},
447 "\uFF80\uFF9E\uFF72\uFF8C\uFF9E", CompareOptions
.IgnoreWidth
);
448 AssertSortKey ("#i21", new byte [] {
449 34, 26, 34, 3, 34, 44, 1, 3, 2, 3, 1, 1, 255, 2, 196, 196, 196, 255, 196, 196, 196, 255, 1, 0},
450 "\u30C0\u30A4\u30D6", CompareOptions
.IgnoreWidth
);
452 AssertSortKey ("#i22", new byte [] {
453 0x22, 0x2A, 0x22, 2, 0x22, 0x44, 1, 3, 1, 1, 0xFF,
454 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xC4, 0xC4, 0xC4,
456 "\u30D0\u30FC\u30EB", CompareOptions
.IgnoreWidth
);
457 AssertSortKey ("#i23", new byte [] {
458 0x22, 0x2A, 0x22, 2, 0x22, 0x44, 1, 3, 1, 1, 0xFF,
459 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xC4, 0xC4, 0xC4,
461 "\uFF8A\uFF9E\uFF70\uFF99", CompareOptions
.IgnoreWidth
);
462 // extender + IgnoreNonSpace
463 AssertSortKey ("#i24", new byte [] {
464 0x22, 2, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
465 "\u3042\u309D", CompareOptions
.IgnoreNonSpace
);
469 public void GetSortKeyLevel5 ()
475 AssertSortKeyLevel5 ("#8", new byte [] {
476 0x80, 7, 6, 0x82, 0x80, 0x2F, 6, 0x82, 0},
477 '-' + new string ('A', 10) + '-');
478 AssertSortKeyLevel5 ("#9", new byte [] {
479 0x80, 7, 6, 0x82, 0x80, 0xFF, 6, 0x82, 0},
480 '-' + new string ('A', 62) + '-');
481 AssertSortKeyLevel5 ("#10", new byte [] {
482 0x80, 7, 6, 0x82, 0x81, 3, 6, 0x82, 0},
483 '-' + new string ('A', 63) + '-');
484 AssertSortKeyLevel5 ("#11", new byte [] {
485 0x80, 7, 6, 0x82, 0x81, 0x97, 6, 0x82, 0},
486 '-' + new string ('A', 100) + '-');
487 AssertSortKeyLevel5 ("#12", new byte [] {
488 0x80, 7, 6, 0x82, 0x8F, 0xA7, 6, 0x82, 0},
489 '-' + new string ('A', 1000) + '-');
490 AssertSortKeyLevel5 ("#13", new byte [] {
491 0x80, 7, 6, 0x82, 0x9A, 0x87, 6, 0x82, 0},
492 '-' + new string ('A', 100000) + '-');
493 // This shows how Windows is broken.
494 // AssertSortKeyLevel5 ("#14",
495 // 0x80, 7, 6, 0x82, 0x89, 0x07, 6, 0x82, 0},
496 // '-' + new string ('A', 1000000) + '-');
501 public void GetSortKey_Options ()
503 Array values
= Enum
.GetValues (typeof (CompareOptions
));
504 foreach (int i
in values
) {
505 CompareOptions option
= (CompareOptions
) i
;
507 if (option
== CompareOptions
.OrdinalIgnoreCase
|| option
== CompareOptions
.Ordinal
) {
509 french
.GetSortKey ("foo", option
);
510 Assert
.Fail ("#1: " + option
.ToString ());
511 } catch (ArgumentException ex
) {
512 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#2: " + option
.ToString ());
513 Assert
.IsNotNull (ex
.Message
, "#2: " + option
.ToString ());
514 Assert
.IsNotNull (ex
.ParamName
, "#3: " + option
.ToString ());
515 Assert
.AreEqual ("options", ex
.ParamName
, "#4: " + option
.ToString ());
516 Assert
.IsNull (ex
.InnerException
, "#5: " + option
.ToString ());
519 french
.GetSortKey ("foo", option
);
522 french
.GetSortKey ("foo", option
);
529 [Category ("NotDotNet")]
531 public void FrenchSort ()
537 AssertSortKey ("#inv-1", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}
, "c\u00F4te");
538 AssertSortKey ("#inv-1-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}
, "co\u0302te");
539 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");
540 AssertSortKey ("#inv-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 2, 2, 0xE, 1, 1, 1, 0}
, "cot\u00E9");
541 AssertSortKey ("#inv-2-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x14, 1, 1, 1, 0}
, "co\u030Cte");
542 // They are all bugs in 2.0:
543 // #inv-3: should not be 0 since those sortkey values differ.
544 // #inv-4: should not be -1 since co\u0302te sortkey is bigger than cote\u0306.
545 AssertCompare ("#inv-3", 1, "c\u00F4te", "cot\u00E9");
546 AssertCompare ("#inv-4", 1, "co\u0302te", "cote\u0306");
547 AssertCompare ("#inv-5", 1, "co\u030Cte", "cote\u0306");
550 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
);
551 AssertSortKey ("#fr-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 0xE, 1, 1, 1, 0}
, "cot\u00E9", CompareOptions
.None
, french
);
552 AssertCompare ("#fr-3", -1, "c\u00F4te", "cot\u00E9", CompareOptions
.None
, french
);
553 // FIXME: why does .NET return 1 ?
554 // AssertCompare ("#fr-4", -1, "co\u0302te", "cote\u0306", CompareOptions.None, french);
555 // AssertCompare ("#fr-4", -1, "co\u030Cte", "cote\u0306", CompareOptions.None, french);
559 public void GetSortKeyThai ()
564 AssertSortKey ("#i1", new byte [] {
565 0x1E, 7, 0x1F, 0x28, 1, 3, 3, 1, 1, 1, 0},
567 AssertSortKey ("#i2", new byte [] {
568 0x1E, 7, 1, 3, 1, 1, 1, 0},
570 // FIXME: not working (table fix required)
571 // AssertSortKey ("#i6", new byte [] {
572 // 0x1E, 7, 0xA, 0xF9, 1, 3, 1, 1, 1, 0},
574 AssertSortKey ("#i7", new byte [] {
575 0x1E, 7, 0x1E, 2, 1, 3, 3, 1, 1, 1, 0},
577 AssertSortKey ("#i8", new byte [] {
578 0x1E, 7, 0x1E, 3, 1, 3, 3, 1, 1, 1, 0},
580 AssertSortKey ("#i9", new byte [] {
581 0x1E, 7, 0x1E, 4, 1, 3, 3, 1, 1, 1, 0},
583 AssertSortKey ("#i10", new byte [] {
584 0x1E, 7, 0x1E, 5, 1, 3, 3, 1, 1, 1, 0},
586 AssertSortKey ("#i11", new byte [] {
587 0x1E, 7, 0x1E, 6, 1, 3, 3, 1, 1, 1, 0},
589 AssertSortKey ("#i12", new byte [] {
590 0x1E, 7, 0x1F, 0x29, 1, 3, 3, 1, 1, 1, 0},
592 AssertSortKey ("#i13", new byte [] {
593 0x1E, 7, 0x1F, 0x2A, 1, 3, 3, 1, 1, 1, 0},
595 // FIXME: not working (U+E47 table fix required)
596 // AssertSortKey ("#i14", new byte [] {
597 // 0x1E, 7, 1, 5, 1, 1, 1, 0},
599 AssertSortKey ("#i15", new byte [] {
600 0x1E, 7, 1, 6, 1, 1, 1, 0},
602 AssertSortKey ("#i16", new byte [] {
603 0x1E, 7, 1, 7, 1, 1, 1, 0},
605 AssertSortKey ("#i17", new byte [] {
606 0x1E, 7, 1, 8, 1, 1, 1, 0},
608 AssertSortKey ("#i18", new byte [] {
609 0x1E, 7, 1, 9, 1, 1, 1, 0},
611 // FIXME: not working (U+E47 table fix required)
612 // AssertSortKey ("#i19", new byte [] {
613 // 0x1E, 7, 1, 8, 1, 1, 1, 0},
614 // "\u0E01\u0E48\u0E47");
615 AssertSortKey ("#i20", new byte [] {
616 0x1E, 7, 0x1E, 4, 0x1E, 0xD, 1, 3, 3, 3, 1, 1, 1, 0},
617 "\u0E01\u0E42\u0E02");
618 AssertSortKey ("#i21", new byte [] {
619 0x1E, 7, 0x1E, 0xD, 1, 3, 3, 1, 1, 1, 0},
624 public void GetSortKeyCzechTailoring ()
629 AssertSortKey ("#i1", new byte [] {
630 0xE, 0xA, 0xE, 0x2C, 1, 1, 1, 1, 0},
632 AssertSortKey ("#cs1", new byte [] {
633 0xE, 0x2E, 1, 1, 1, 1, 0},
634 "ch", CompareOptions
.None
, czech
);
635 AssertSortKey ("#i2", new byte [] {
636 0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
638 AssertSortKey ("#cs2", new byte [] {
639 0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
640 "r\u030C", CompareOptions
.None
, czech
);
644 public void GetSortKeyHungarianTailoring ()
649 AssertSortKey ("#1", new byte [] {
650 0xE, 0xE, 1, 1, 0x1A, 1, 1, 0},
651 "CS", CompareOptions
.None
, hungarian
);
652 AssertSortKey ("#2", new byte [] {
653 0xE, 0xE, 1, 1, 0x12, 1, 1, 0},
654 "Cs", CompareOptions
.None
, hungarian
);
655 AssertSortKey ("#3", new byte [] {
656 0xE, 0xE, 1, 1, 1, 1, 0},
657 "cs", CompareOptions
.None
, hungarian
);
658 AssertSortKey ("#4", new byte [] {
659 0xE, 0x1C, 1, 1, 0x1A, 1, 1, 0},
660 "DZ", CompareOptions
.None
, hungarian
);
661 AssertSortKey ("#5", new byte [] {
662 0xE, 0x1C, 1, 1, 0x12, 1, 1, 0},
663 "Dz", CompareOptions
.None
, hungarian
);
664 AssertSortKey ("#6", new byte [] {
665 0xE, 0x1C, 1, 1, 1, 1, 0},
666 "dz", CompareOptions
.None
, hungarian
);
667 AssertSortKey ("#7", new byte [] {
668 0xE, 0x75, 1, 1, 0x1A, 1, 1, 0},
669 "NY", CompareOptions
.None
, hungarian
);
670 AssertSortKey ("#8", new byte [] {
671 0xE, 0x75, 1, 1, 0x12, 1, 1, 0},
672 "Ny", CompareOptions
.None
, hungarian
);
673 AssertSortKey ("#9", new byte [] {
674 0xE, 0x75, 1, 1, 1, 1, 0},
675 "ny", CompareOptions
.None
, hungarian
);
676 AssertSortKey ("#10", new byte [] {
677 0xE, 0xB1, 1, 1, 0x1A, 1, 1, 0},
678 "ZS", CompareOptions
.None
, hungarian
);
679 AssertSortKey ("#11", new byte [] {
680 0xE, 0xB1, 1, 1, 0x12, 1, 1, 0},
681 "Zs", CompareOptions
.None
, hungarian
);
682 AssertSortKey ("#12", new byte [] {
683 0xE, 0xB1, 1, 1, 1, 1, 0},
684 "zs", CompareOptions
.None
, hungarian
);
686 // Windows seems to have bugs around repetitive characters
688 // AssertSortKey ("#x", new byte [] {
689 // 0xE, 0x2E, 1, 1, 1, 1, 0},
690 // "CCS", CompareOptions.None, hungarian);
692 // FIXME: we need to handle case insensitivity
696 public void CustomCJKTable ()
701 AssertSortKey ("#1", new byte [] {
702 0x9E, 9, 0x9E, 0x11, 1, 1, 1, 1, 0},
704 AssertSortKey ("#2", new byte [] {
705 0x84, 0xD3, 0x84, 0x61, 1, 1, 1, 1, 0},
706 "\u4E03\u4E09", CompareOptions
.None
, japanese
);
711 [Category ("NotDotNet")]
713 public void CultureSensitiveCompare ()
718 AssertCompare ("#1", -1, "1", "2");
719 AssertCompare ("#2", 1, "A", "a");
720 AssertCompare ("#3", 0, "A", "a", CompareOptions
.IgnoreCase
);
721 AssertCompare ("#4", 0, "\uFF10", "0", CompareOptions
.IgnoreWidth
);
722 AssertCompare ("#5", 0, "\uFF21", "a", ignoreCW
);
723 AssertCompare ("#6", 1, "12", "1");
724 // BUG in .NET 2.0: See GetSortKey() test that assures sortkeys for "AE" and
725 // "\u00C6" are equivalent.
726 AssertCompare ("#7", 0, "AE", "\u00C6");
727 AssertCompare ("#8", 0, "AB\u01c0C", "A\u01c0B\u01c0C", CompareOptions
.IgnoreSymbols
);
728 // BUG in .NET 2.0: ditto.
729 AssertCompare ("#9", 0, "A\u0304", "\u0100");
730 AssertCompare ("#10", 1, "ABCABC", 5, 1, "1", 0, 1, CompareOptions
.IgnoreCase
, invariant
);
731 AssertCompare ("#11", 0, "-d:NET_2_0", 0, 1, "-", 0, 1);
733 // BUG in .NET 2.0: ditto.
734 AssertCompare ("#12", 0, "ae", "\u00E6");
735 AssertCompare ("#13", 0, "\u00E6", "ae");
736 AssertCompare ("#14", 0, "\u00E6s", 0, 1, "ae", 0, 2);
738 // target is "empty" (in culture-sensitive context).
739 // BUG in .NET 2.0: \u3007 is totally-ignored character as a GetSortKey()
740 // result, while it is not in Compare().
741 AssertCompare ("#17", 0, String
.Empty
, "\u3007");
742 AssertCompare ("#18", 1, "A", "\u3007");
743 AssertCompare ("#19", 1, "ABC", "\u3007");
745 // shift weight comparison
746 AssertCompare ("#20", 1, "--start", "--");
748 // BUG in .NET 2.0: the same 00C6/00E6 issue.
749 AssertCompare ("#21", -1, "\u00E6", "aes");
752 AssertCompare ("#22", -1, "++)", "+-+)");
753 AssertCompare ("#23", -1, "+-+)", "+-+-)");
754 AssertCompare ("#24", 1, "+-+-)", "++)");
755 // BUG in .NET: it returns 1
756 AssertCompare ("#25", -1, "+-+-)", "-+-+)");
757 AssertCompare ("#26", -1, "+-+)", "-+-+)");
758 AssertCompare ("#27", -1, "++)", "-+-+)");
760 AssertCompare ("#28", 1, "aa ", "A");
765 [Category ("NotDotNet")]
767 public void CompareSpecialWeight ()
772 // Japanese (in invariant)
773 // BUG in .NET 2.0 : half-width kana should be bigger.
774 AssertCompare ("#1", 1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
775 AssertCompare ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions
.IgnoreWidth
);
776 AssertCompare ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
777 "\u30C0\u30A4\u30D6", CompareOptions
.IgnoreWidth
);
778 AssertCompare ("#4", 1, "\u3042\u309D", "\u3042\u3042");
779 AssertCompare ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions
.IgnoreNonSpace
);
780 AssertCompare ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
781 "\u30D0\u30FC\u30EB", CompareOptions
.IgnoreWidth
);
783 // extender in target
784 // BUG in .NET 2.0 : an extender should result in bigger sortkey
785 AssertCompare ("#7", -1, "\u30D1\u30A2", "\u30D1\u30FC");
786 AssertCompare ("#8", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions
.IgnoreNonSpace
);
787 // extender in source
788 // BUG in .NET 2.0 : vice versa
789 AssertCompare ("#9", 1, "\u30D1\u30FC", "\u30D1\u30A2");
790 AssertCompare ("#10", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions
.IgnoreNonSpace
);
794 public void IndexOfChar ()
799 AssertIndexOf ("#1", -1, "ABC", '1');
800 AssertIndexOf ("#2", 2, "ABCABC", 'c', CompareOptions
.IgnoreCase
);
801 AssertIndexOf ("#3", 1, "ABCABC", '\uFF22', ignoreCW
);
802 AssertIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN
);
803 AssertIndexOf ("#5", 1, "ABCABC", 'B', 1, 5, CompareOptions
.IgnoreCase
, invariant
);
804 AssertIndexOf ("#6", 4, "ABCABC", 'B', 2, 4, CompareOptions
.IgnoreCase
, invariant
);
805 AssertIndexOf ("#7", 1, "\u30D1\u30FC", '\u30A2', CompareOptions
.IgnoreNonSpace
);
806 AssertIndexOf ("#8", 1, "UAE", '\u00C6');
807 AssertIndexOf ("#8-2", 1, "AAE", '\u00C6');
808 AssertIndexOf ("#9", -1, "UA", '\u00C6');
809 AssertIndexOf ("#10", -1, "UE", '\u00C6');
813 [Category ("NotDotNet")]
814 public void IndexOfCharMSBug ()
819 AssertIndexOf ("#1", 0, "\u00E6", 'a');
823 public void LastIndexOfChar ()
828 AssertLastIndexOf ("#1", -1, "ABC", '1');
829 AssertLastIndexOf ("#2", 5, "ABCABC", 'c', CompareOptions
.IgnoreCase
);
830 AssertLastIndexOf ("#3", 4, "ABCABC", '\uFF22', ignoreCW
);
831 AssertLastIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN
);
832 AssertLastIndexOf ("#5", 1, "ABCABC", 'B', 3, 3);
833 AssertLastIndexOf ("#6", 4, "ABCABC", 'B', 4, 4);
834 AssertLastIndexOf ("#7", -1, "ABCABC", 'B', 5, 1);
835 AssertLastIndexOf ("#8", 1, "UAE", '\u00C6');
836 AssertLastIndexOf ("#8-2", 1, "UAEE", '\u00C6');
837 AssertLastIndexOf ("#9", -1, "UA", '\u00C6');
838 AssertLastIndexOf ("#10", -1, "UE", '\u00C6');
839 AssertLastIndexOf ("#11", 0, "\\", '\\');
840 Assert
.AreEqual (0, new CultureInfo ("en").CompareInfo
.LastIndexOf ("\\", '\\'), "#11en");
841 Assert
.AreEqual (0, new CultureInfo ("ja").CompareInfo
.LastIndexOf ("\\", '\\'), "#11ja");
842 AssertLastIndexOf ("#12", 8, "/system/web", 'w');
843 Assert
.AreEqual (8, new CultureInfo ("sv").CompareInfo
.LastIndexOf ("/system/web", 'w'), "#12sv");
847 [Category ("NotDotNet")]
848 public void LastIndexOfCharMSBug ()
853 AssertIndexOf ("#1", 0, "\u00E6", 'a');
858 [Category ("NotDotNet")]
860 public void IsPrefix ()
865 AssertIsPrefix ("#1", false, "ABC", "c", CompareOptions
.IgnoreCase
);
866 AssertIsPrefix ("#2", false, "BC", "c", CompareOptions
.IgnoreCase
);
867 AssertIsPrefix ("#3", true, "C", "c", CompareOptions
.IgnoreCase
);
868 AssertIsPrefix ("#4", true, "EDCBA", "\u0117", ignoreCN
);
869 AssertIsPrefix ("#5", true, "ABC", "AB", CompareOptions
.IgnoreCase
);
870 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
871 AssertIsPrefix ("#6", true, "ae", "\u00E6", CompareOptions
.None
);
872 AssertIsPrefix ("#7", true, "\u00E6", "ae", CompareOptions
.None
);
874 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
875 AssertIsPrefix ("#8", true, "\u00E6", "a", CompareOptions
.None
);
876 AssertIsPrefix ("#9", true, "\u00E6s", "ae", CompareOptions
.None
);
877 AssertIsPrefix ("#10", false, "\u00E6", "aes", CompareOptions
.None
);
878 AssertIsPrefix ("#11", true, "--start", "--", CompareOptions
.None
);
879 AssertIsPrefix ("#12", true, "-d:NET_1_1", "-", CompareOptions
.None
);
880 AssertIsPrefix ("#13", false, "-d:NET_1_1", "@", CompareOptions
.None
);
881 // U+3007 is completely ignored character.
882 AssertIsPrefix ("#14", true, "\uff21\uff21", "\uff21", CompareOptions
.None
);
883 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
884 AssertIsPrefix ("#15", true, "\uff21\uff21", "\u3007\uff21", CompareOptions
.None
);
885 AssertIsPrefix ("#16", true, "\uff21\uff21", "\uff21\u3007", CompareOptions
.None
);
886 AssertIsPrefix ("#17", true, "\\b\\a a", "\\b\\a a");
887 Assert
.IsTrue (new CultureInfo ("en").CompareInfo
.IsPrefix ("\\b\\a a", "\\b\\a a"), "#17en");
888 Assert
.IsTrue (new CultureInfo ("ja").CompareInfo
.IsPrefix ("\\b\\a a", "\\b\\a a"), "#17ja");
892 public void IsPrefixSpecialWeight ()
897 // Japanese (in invariant)
898 AssertIsPrefix ("#1", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
899 AssertIsPrefix ("#2", true, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions
.IgnoreWidth
);
900 AssertIsPrefix ("#2-2", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
901 AssertIsPrefix ("#3", true, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
902 "\u30C0\u30A4\u30D6", CompareOptions
.IgnoreWidth
);
903 AssertIsPrefix ("#3-2", false, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
904 "\u30C0\u30A4\u30D6");
905 AssertIsPrefix ("#4", false, "\u3042\u309D", "\u3042\u3042");
906 AssertIsPrefix ("#5", true, "\u3042\u309D", "\u3042\u3042", CompareOptions
.IgnoreNonSpace
);
907 AssertIsPrefix ("#6", true, "\uFF8A\uFF9E\uFF70\uFF99",
908 "\u30D0\u30FC\u30EB", CompareOptions
.IgnoreWidth
);
910 // extender in target
911 AssertIsPrefix ("#7", false, "\u30D1\u30A2", "\u30D1\u30FC");
912 AssertIsPrefix ("#8", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions
.IgnoreNonSpace
);
913 // extender in source
914 AssertIsPrefix ("#9", false, "\u30D1\u30FC", "\u30D1\u30A2");
915 AssertIsPrefix ("#10", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions
.IgnoreNonSpace
);
917 // empty suffix always matches the source.
918 AssertIsPrefix ("#11", true, "", "");
919 AssertIsPrefix ("#12", true, "/test.css", "");
922 AssertIsPrefix ("#13", false, "\u00e4_", "a");
927 [Category ("NotDotNet")]
929 public void IsSuffix ()
934 AssertIsSuffix ("#1", true, "ABC", "c", CompareOptions
.IgnoreCase
);
935 AssertIsSuffix ("#2", true, "BC", "c", CompareOptions
.IgnoreCase
);
936 AssertIsSuffix ("#3", false, "CBA", "c", CompareOptions
.IgnoreCase
);
937 AssertIsSuffix ("#4", true, "ABCDE", "\u0117", CompareOptions
.IgnoreNonSpace
| CompareOptions
.IgnoreCase
);
938 AssertIsSuffix ("#5", false, "\u00E6", "a", CompareOptions
.None
);
939 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
940 AssertIsSuffix ("#6", true, "\u00E6", "ae", CompareOptions
.None
);
941 AssertIsSuffix ("#7", true, "ae", "\u00E6", CompareOptions
.None
);
942 AssertIsSuffix ("#8", false, "e", "\u00E6", CompareOptions
.None
);
943 // U+3007 is completely ignored character.
944 AssertIsSuffix ("#9", true, "\uff21\uff21", "\uff21", CompareOptions
.None
);
945 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
946 AssertIsSuffix ("#10", true, "\uff21\uff21", "\u3007\uff21", CompareOptions
.None
);
947 AssertIsSuffix ("#11", true, "\uff21\uff21", "\uff21\u3007", CompareOptions
.None
);
948 // extender in target
949 AssertIsSuffix ("#12", false, "\u30D1\u30A2", "\u30D1\u30FC");
950 AssertIsSuffix ("#13", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions
.IgnoreNonSpace
);
951 // extender in source
952 AssertIsSuffix ("#14", false, "\u30D1\u30FC", "\u30D1\u30A2");
953 AssertIsSuffix ("#15", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions
.IgnoreNonSpace
);
954 // optimization sanity check
955 AssertIsSuffix ("#16", true,
956 "/configuration/system.runtime.remoting",
957 "system.runtime.remoting");
959 // empty suffix always matches the source.
960 AssertIsSuffix ("#17", true, "", "");
961 AssertIsSuffix ("#18", true, "/test.css", "");
962 AssertIsSuffix ("#19", true, "/test.css", "/test.css");
963 AssertIsSuffix ("#20", true, "\\b\\a a", "\\b\\a a");
964 Assert
.IsTrue (new CultureInfo ("en").CompareInfo
.IsSuffix ("\\b\\a a", "\\b\\a a"), "#20en");
965 Assert
.IsTrue (new CultureInfo ("ja").CompareInfo
.IsSuffix ("\\b\\a a", "\\b\\a a"), "#20ja");
969 [Category ("NotDotNet")]
970 [Category ("NotWorking")]
971 public void IsSuffixMSBug ()
976 AssertIsSuffix ("#1", true, "\u00E6", "e", CompareOptions
.None
);
981 [Category ("NotDotNet")]
983 public void IndexOfString ()
988 AssertIndexOf ("#0", 0, "", "", CompareOptions
.None
);
989 AssertIndexOf ("#1", -1, "ABC", "1", CompareOptions
.None
);
990 AssertIndexOf ("#2", 2, "ABCABC", "c", CompareOptions
.IgnoreCase
);
991 AssertIndexOf ("#3", 1, "ABCABC", "\uFF22", CompareOptions
.IgnoreCase
| CompareOptions
.IgnoreWidth
);
992 AssertIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions
.IgnoreNonSpace
| CompareOptions
.IgnoreCase
);
993 AssertIndexOf ("#5", 1, "ABCABC", "BC", CompareOptions
.IgnoreCase
);
994 AssertIndexOf ("#6", 1, "BBCBBC", "BC", CompareOptions
.IgnoreCase
);
995 AssertIndexOf ("#7", -1, "ABCDEF", "BCD", 0, 3, CompareOptions
.IgnoreCase
, invariant
);
996 AssertIndexOf ("#8", 0, "-ABC", "-", CompareOptions
.None
);
997 AssertIndexOf ("#9", 0, "--ABC", "--", CompareOptions
.None
);
998 AssertIndexOf ("#10", -1, "--ABC", "--", 1, 2, CompareOptions
.None
, invariant
);
999 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1000 AssertIndexOf ("#11", 0, "AE", "\u00C6", CompareOptions
.None
);
1001 // U+3007 is completely ignored character.
1002 AssertIndexOf ("#12", 0, "\uff21\uff21", "\uff21", CompareOptions
.None
);
1003 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1004 AssertIndexOf ("#13", 0, "\uff21\uff21", "\u3007\uff21", CompareOptions
.None
);
1005 AssertIndexOf ("#14", 0, "\uff21\uff21", "\uff21\u3007", CompareOptions
.None
);
1006 AssertIndexOf ("#15", 0, "\uff21\uff21", "\u3007", CompareOptions
.None
);
1007 AssertIndexOf ("#15-2", 1, "\u3007\uff21", "\uff21", CompareOptions
.None
);
1008 // target is "empty" (in culture-sensitive context).
1009 AssertIndexOf ("#16", -1, String
.Empty
, "\u3007");
1010 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1011 AssertIndexOf ("#17", 0, "A", "\u3007");
1012 AssertIndexOf ("#18", 0, "ABC", "\u3007");
1014 AssertIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
1015 Assert
.AreEqual (0, new CultureInfo ("en").CompareInfo
.IndexOf ("\\b\\a a", "\\b\\a a"), "#19en");
1016 Assert
.AreEqual (0, new CultureInfo ("ja").CompareInfo
.IndexOf ("\\b\\a a", "\\b\\a a"), "#19ja");
1020 public void IndexOfSpecialWeight ()
1025 // Japanese (in invariant)
1026 AssertIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1027 // extender in target
1028 AssertIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
1029 AssertIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions
.IgnoreNonSpace
);
1030 // extender in source
1031 AssertIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions
.IgnoreNonSpace
);
1032 AssertIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions
.IgnoreNonSpace
);
1033 AssertIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions
.IgnoreWidth
);
1034 AssertIndexOf ("#2-2", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1035 AssertIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
1036 "\u30C0\u30A4\u30D6", CompareOptions
.IgnoreWidth
);
1037 AssertIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
1038 AssertIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions
.IgnoreNonSpace
);
1039 AssertIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
1040 "\u30D0\u30FC\u30EB", CompareOptions
.IgnoreWidth
);
1046 [Category ("NotDotNet")]
1048 public void LastIndexOfString ()
1053 AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions
.None
);
1054 AssertLastIndexOf ("#2", 5, "ABCABC", "c", CompareOptions
.IgnoreCase
);
1055 AssertLastIndexOf ("#3", 4, "ABCABC", "\uFF22", CompareOptions
.IgnoreCase
| CompareOptions
.IgnoreWidth
);
1056 AssertLastIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions
.IgnoreNonSpace
| CompareOptions
.IgnoreCase
);
1057 AssertLastIndexOf ("#5", 4, "ABCABC", "BC", CompareOptions
.IgnoreCase
);
1058 AssertLastIndexOf ("#6", 4, "BBCBBC", "BC", CompareOptions
.IgnoreCase
);
1059 AssertLastIndexOf ("#7", 1, "original", "rig", CompareOptions
.None
);
1060 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1061 AssertLastIndexOf ("#8", 0, "\u00E6", "ae", CompareOptions
.None
);
1062 AssertLastIndexOf ("#9", 0, "-ABC", "-", CompareOptions
.None
);
1063 AssertLastIndexOf ("#10", 0, "--ABC", "--", CompareOptions
.None
);
1064 AssertLastIndexOf ("#11", -1, "--ABC", "--", 2, 2, CompareOptions
.None
, invariant
);
1065 AssertLastIndexOf ("#12", -1, "--ABC", "--", 4, 2, CompareOptions
.None
, invariant
);
1066 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1067 AssertLastIndexOf ("#13", 0, "AE", "\u00C6", CompareOptions
.None
);
1068 // U+3007 is completely ignored character.
1069 AssertLastIndexOf ("#14", 1, "\uff21\uff21", "\uff21", CompareOptions
.None
);
1070 // BUG in .NET 2.0 : see \u3007 issue (mentioned above).
1071 AssertLastIndexOf ("#15", 1, "\uff21\uff21", "\u3007\uff21", CompareOptions
.None
);
1072 AssertLastIndexOf ("#16", 1, "\uff21\uff21", "\uff21\u3007", CompareOptions
.None
);
1073 AssertLastIndexOf ("#17", 1, "\uff21\uff21", "\u3007", CompareOptions
.None
);
1074 AssertLastIndexOf ("#18", 1, "\u3007\uff21", "\uff21", CompareOptions
.None
);
1075 AssertLastIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
1076 Assert
.AreEqual (0, new CultureInfo ("en").CompareInfo
.LastIndexOf ("\\b\\a a", "\\b\\a a"), "#19en");
1077 Assert
.AreEqual (0, new CultureInfo ("ja").CompareInfo
.LastIndexOf ("\\b\\a a", "\\b\\a a"), "#19ja");
1079 AssertLastIndexOf ("#20", 8, "/system/web", "w");
1080 Assert
.AreEqual (8, new CultureInfo ("sv").CompareInfo
.LastIndexOf ("/system/web", "w"), "#20sv");
1084 public void LastIndexOfSpecialWeight ()
1089 // Japanese (in invariant)
1090 AssertLastIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
1091 // extender in target
1092 AssertLastIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
1093 AssertLastIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions
.IgnoreNonSpace
);
1094 // extender in source
1095 AssertLastIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions
.IgnoreNonSpace
);
1096 // FIXME: not working (extender support is not complete.
1097 // Currently private IsPrefix() cannot handle heading
1098 // extenders to consume previous primary char.)
1099 // AssertLastIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
1100 // this shows that Windows accesses beyond the length and
1101 // acquires the corresponding character to expand.
1102 // AssertLastIndexOf ("#1-6", 1, "\u30D1\u30FC", "\u30A2", 1, 1, CompareOptions.IgnoreNonSpace, invariant);
1103 AssertLastIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions
.IgnoreWidth
);
1104 AssertLastIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
1105 "\u30C0\u30A4\u30D6", CompareOptions
.IgnoreWidth
);
1106 AssertLastIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
1107 AssertLastIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions
.IgnoreNonSpace
);
1108 AssertLastIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
1109 "\u30D0\u30FC\u30EB", CompareOptions
.IgnoreWidth
);
1113 public void LastIndexOfOrdinalString ()
1118 AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions
.Ordinal
);
1119 AssertLastIndexOf ("#2", 5, "ABCABC", "C", CompareOptions
.Ordinal
);
1120 AssertLastIndexOf ("#3", -1, "ABCABC", "\uFF22", CompareOptions
.Ordinal
);
1121 AssertLastIndexOf ("#4", 4, "ABCABC", "BC", CompareOptions
.Ordinal
);
1122 AssertLastIndexOf ("#5", 4, "BBCBBC", "BC", CompareOptions
.Ordinal
);
1123 AssertLastIndexOf ("#6", 1, "original", "rig", CompareOptions
.Ordinal
);
1124 AssertLastIndexOf ("#7", 0, "\\b\\a a", "\\b\\a a", CompareOptions
.Ordinal
);
1129 public void NullCharacter ()
1131 Assert
.AreEqual (-1, "MONO".IndexOf ("\0\0\0"), "#1");
1132 Assert
.AreEqual (-1, "MONO".LastIndexOf ("\0\0\0"), "#2");
1133 Assert
.AreEqual (1, "MONO".CompareTo ("\0\0\0"), "#3");
1137 [Category ("NotDotNet")]
1138 // MS.NET treats it as equivalent, while in IndexOf() it does not match.
1139 public void NullCharacterWeird ()
1141 Assert
.AreEqual (-1, "MONO".CompareTo ("MONO\0\0\0"), "#4");
1146 [Category ("NotDotNet")]
1147 public void OrdinalIgnoreCaseCompare ()
1153 // BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
1154 AssertCompare ("#1", 0, "AE", "\u00C6", CompareOptions
.None
);
1155 // BUG in .NET 2.0 : It raises inappropriate ArgumentException.
1156 // should not match since it is Ordinal
1157 AssertCompare ("#2", -133, "AE", "\u00C6", CompareOptions
.OrdinalIgnoreCase
);
1159 AssertCompare ("#3", 1, "AE", "\u00E6", CompareOptions
.None
);
1161 AssertCompare ("#4", 0, "AE", "\u00E6", CompareOptions
.IgnoreCase
);
1162 // should not match since it is Ordinal
1163 AssertCompare ("#5", -133, "AE", "\u00E6", CompareOptions
.OrdinalIgnoreCase
);
1165 AssertCompare ("#6", 0, "AE", "ae", CompareOptions
.OrdinalIgnoreCase
);
1166 AssertCompare ("#7", 0, "aE", "ae", CompareOptions
.OrdinalIgnoreCase
);
1167 AssertCompare ("#8", 0, "aE", "ae", CompareOptions
.OrdinalIgnoreCase
);
1168 AssertCompare ("#9", 0, "ae", "ae", CompareOptions
.OrdinalIgnoreCase
);
1169 AssertCompare ("#10", 0, "AE", "AE", CompareOptions
.OrdinalIgnoreCase
);
1170 AssertCompare ("#11", 0, "aE", "AE", CompareOptions
.OrdinalIgnoreCase
);
1171 AssertCompare ("#12", 0, "aE", "AE", CompareOptions
.OrdinalIgnoreCase
);
1172 AssertCompare ("#13", 0, "ae", "AE", CompareOptions
.OrdinalIgnoreCase
);
1173 AssertCompare ("#14", 0, "ola", "OLA", CompareOptions
.OrdinalIgnoreCase
);
1177 public void OrdinalIgnoreCaseIndexOf ()
1179 AssertIndexOf ("#1-1", 0, "ABC", "abc", CompareOptions
.OrdinalIgnoreCase
);
1180 AssertIndexOf ("#1-2", -1, "AEBECE", "\u00E6", CompareOptions
.OrdinalIgnoreCase
);
1181 AssertIndexOf ("#1-3", -1, "@_@", "`_`", CompareOptions
.OrdinalIgnoreCase
);
1185 public void OrdinalIgnoreCaseIndexOfChar ()
1187 AssertIndexOf ("#2-1", 0, "ABC", 'a', CompareOptions
.OrdinalIgnoreCase
);
1188 AssertIndexOf ("#2-2", -1, "AEBECE", '\u00C0', CompareOptions
.OrdinalIgnoreCase
);
1189 AssertIndexOf ("#2-3", -1, "@_@", '`', CompareOptions
.OrdinalIgnoreCase
);
1193 public void OrdinalIgnoreCaseLastIndexOf ()
1195 AssertLastIndexOf ("#1-1", 0, "ABC", "abc", CompareOptions
.OrdinalIgnoreCase
);
1196 AssertLastIndexOf ("#1-2", -1, "AEBECE", "\u00E6", CompareOptions
.OrdinalIgnoreCase
);
1197 AssertLastIndexOf ("#1-3", -1, "@_@", "`_`", CompareOptions
.OrdinalIgnoreCase
);
1198 AssertLastIndexOf ("#1-4", 1, "ABCDE", "bc", CompareOptions
.OrdinalIgnoreCase
);
1199 AssertLastIndexOf ("#1-5", -1, "BBBBB", "ab", CompareOptions
.OrdinalIgnoreCase
);
1203 public void OrdinalIgnoreCaseLastIndexOfChar ()
1205 AssertLastIndexOf ("#2-1", 0, "ABC", 'a', CompareOptions
.OrdinalIgnoreCase
);
1206 AssertLastIndexOf ("#2-2", -1, "AEBECE", '\u00C0', CompareOptions
.OrdinalIgnoreCase
);
1207 AssertLastIndexOf ("#2-3", -1, "@_@", '`', CompareOptions
.OrdinalIgnoreCase
);
1210 [Test
] // bug #80865
1211 public void IsPrefixOrdinalIgnoreCase ()
1213 Assert
.IsTrue ("aaaa".StartsWith ("A", StringComparison
.OrdinalIgnoreCase
));
1218 [ExpectedException (typeof (ArgumentNullException
))]
1219 public void IsPrefix_SourceNull ()
1221 invariant
.IsPrefix (null, "b");
1225 [ExpectedException (typeof (ArgumentNullException
))]
1226 public void IsPrefix_PrefixNull ()
1228 invariant
.IsPrefix ("a", null, CompareOptions
.None
);
1232 public void IsPrefix_PrefixEmpty ()
1234 Assert
.IsTrue (invariant
.IsPrefix ("a", String
.Empty
));
1238 [ExpectedException (typeof (ArgumentException
))]
1239 public void IsPrefix_CompareOptions_Invalid ()
1241 invariant
.IsPrefix ("a", "b", (CompareOptions
) Int32
.MinValue
);
1245 [ExpectedException (typeof (ArgumentException
))]
1246 public void IsPrefix_CompareOptions_StringSort ()
1248 invariant
.IsPrefix ("a", "b", CompareOptions
.StringSort
);
1252 [ExpectedException (typeof (ArgumentNullException
))]
1253 public void IsSuffix_SourceNull ()
1255 invariant
.IsSuffix (null, "b");
1259 [ExpectedException (typeof (ArgumentNullException
))]
1260 public void IsSuffix_SuffixNull ()
1262 invariant
.IsSuffix ("a", null, CompareOptions
.None
);
1266 public void IsSuffix_PrefixEmpty ()
1268 Assert
.IsTrue (invariant
.IsSuffix ("a", String
.Empty
));
1272 [ExpectedException (typeof (ArgumentException
))]
1273 public void IsSuffix_CompareOptions_Invalid ()
1275 invariant
.IsSuffix ("a", "b", (CompareOptions
) Int32
.MinValue
);
1279 [ExpectedException (typeof (ArgumentException
))]
1280 public void IsSuffix_CompareOptions_StringSort ()
1282 invariant
.IsSuffix ("a", "b", CompareOptions
.StringSort
);
1286 [ExpectedException (typeof (ArgumentException
))]
1287 public void Compare_String_String_CompareOptions_Invalid ()
1289 // validation of CompareOptions is made before null checks
1290 invariant
.Compare (null, null, (CompareOptions
) Int32
.MinValue
);
1294 public void Compare_String_String_CompareOptions_StringSort ()
1296 // StringSort is valid for Compare only
1297 Assert
.AreEqual (-1, invariant
.Compare ("a", "b", CompareOptions
.StringSort
));
1301 [ExpectedException (typeof (ArgumentException
))]
1302 public void Compare_String_Int_String_Int_CompareOptions_Invalid ()
1304 invariant
.Compare (null, 0, null, 0, (CompareOptions
) Int32
.MinValue
);
1308 [ExpectedException (typeof (ArgumentException
))]
1309 public void Compare_String_Int_Int_String_Int_Int_CompareOptions_Invalid ()
1311 invariant
.Compare (null, 0, 0, null, 0, 0, (CompareOptions
) Int32
.MinValue
);
1315 [ExpectedException (typeof (ArgumentException
))]
1316 public void IndexOf_String_Char_Int_Int_CompareOptions_Invalid ()
1318 invariant
.IndexOf ("a", 'a', 0, 1, (CompareOptions
) Int32
.MinValue
);
1322 [ExpectedException (typeof (ArgumentException
))]
1323 public void IndexOf_String_Char_Int_Int_CompareOptions_StringSort ()
1325 invariant
.IndexOf ("a", 'a', 0, 1, CompareOptions
.StringSort
);
1329 [ExpectedException (typeof (ArgumentException
))]
1330 public void IndexOf_String_String_Int_Int_CompareOptions_Invalid ()
1332 invariant
.IndexOf ("a", "a", 0, 1, (CompareOptions
) Int32
.MinValue
);
1336 [ExpectedException (typeof (ArgumentException
))]
1337 public void IndexOf_String_String_Int_Int_CompareOptions_StringSort ()
1339 invariant
.IndexOf ("a", "a", 0, 1, CompareOptions
.StringSort
);
1343 [ExpectedException (typeof (ArgumentException
))]
1344 public void LastIndexOf_String_Char_Int_Int_CompareOptions_Invalid ()
1346 invariant
.LastIndexOf ("a", 'a', 0, 1, (CompareOptions
) Int32
.MinValue
);
1350 [ExpectedException (typeof (ArgumentException
))]
1351 public void LastIndexOf_String_Char_Int_Int_CompareOptions_StringSort ()
1353 invariant
.LastIndexOf ("a", 'a', 0, 1, CompareOptions
.StringSort
);
1357 [ExpectedException (typeof (ArgumentException
))]
1358 public void LastIndexOf_String_String_Int_Int_CompareOptions_Invalid ()
1360 invariant
.LastIndexOf ("a", "a", 0, 1, (CompareOptions
) Int32
.MinValue
);
1364 [ExpectedException (typeof (ArgumentException
))]
1365 public void LastIndexOf_String_String_Int_Int_CompareOptions_StringSort ()
1367 invariant
.LastIndexOf ("a", "a", 0, 1, CompareOptions
.StringSort
);