1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
|
// CompareInfoTest.cs - NUnit Test Cases for the
// System.Globalization.CompareInfo class
//
// Dick Porter <dick@ximian.com>
// Atsushi Enomoto <atsushi@ximian.com>
//
// (C) 2003-2005 Novell, Inc. http://www.novell.com
//
using NUnit.Framework;
using System;
using System.Globalization;
namespace MonoTests.System.Globalization
{
[TestFixture]
public class CompareInfoTest : Assertion
{
static bool doTest = Environment.GetEnvironmentVariable ("MONO_DISABLE_MANAGED_COLLATION") != "yes";
public CompareInfoTest() {}
[Test]
public void Compare()
{
string s1 = "foo";
AssertEquals ("Compare two empty strings", 0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", ""));
AssertEquals ("Compare string with empty string", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, ""));
AssertEquals ("Compare empty string with string", -1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", s1));
AssertEquals ("Compare two empty strings, with 0 offsets", 0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "", 0));
AssertEquals ("Compare string with empty string, with 0 offsets", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, "", 0));
AssertEquals ("Compare empty string with string, with 0 offsets", -1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, s1, 0));
AssertEquals ("Compare two empty strings, with 0 offsets and specified lengths", 0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "".Length, "", 0, "".Length));
AssertEquals ("Compare string with empty string, with 0 offsets and specified lengths", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1.Length, "", 0, "".Length));
AssertEquals ("Compare empty string with string, with 0 offsets and specified lengths", -1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "".Length, s1, 0, s1.Length));
AssertEquals ("Compare two strings, with offsets == string lengths", 0, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s1.Length, s1, s1.Length));
AssertEquals ("Compare two strings, with first offset == string length", -1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s1.Length, s1, 0));
AssertEquals ("Compare two strings, with second offset == string length", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1, s1.Length));
AssertEquals ("Compare two strings, with zero lengths", 0, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, 0, s1, 0, 0));
AssertEquals ("Compare two strings, with first length zero", -1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, 0, s1, 0, s1.Length));
AssertEquals ("Compare strings, with second length zero", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1.Length, s1, 0, 0));
}
// Culture-sensitive collation tests
CompareInfo invariant = CultureInfo.InvariantCulture.CompareInfo;
CompareInfo french = new CultureInfo ("fr").CompareInfo;
CompareInfo japanese = new CultureInfo ("ja").CompareInfo;
CompareInfo czech = new CultureInfo ("cs").CompareInfo;
CompareInfo hungarian = new CultureInfo ("hu").CompareInfo;
CompareOptions ignoreCW =
CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase;
CompareOptions ignoreCN =
CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase;
void AssertSortKey (string message, byte [] expected, string test)
{
AssertSortKey (message, expected, test, CompareOptions.None);
}
void AssertSortKey (string message, byte [] expected, string test, CompareOptions opt)
{
AssertSortKey (message, expected, test, opt, invariant);
}
void AssertSortKey (string message, byte [] expected, string test, CompareOptions opt, CompareInfo ci)
{
byte [] actual = ci.GetSortKey (test, opt).KeyData;
AssertEquals (message, expected, actual);
}
void AssertSortKeyLevel5 (string message, byte [] expected, string test)
{
byte [] tmp = invariant.GetSortKey (test).KeyData;
int idx = 0;
for (int i = 0; i < 4; i++, idx++)
for (; tmp [idx] != 1; idx++)
;
byte [] actual = new byte [tmp.Length - idx];
Array.Copy (tmp, idx, actual, 0, actual.Length);
AssertEquals (message, expected, actual);
}
void AssertCompare (string message, int result, string s1, string s2)
{
AssertCompare (message, result, s1, s2, CompareOptions.None);
}
void AssertCompare (string message, int result, string s1, string s2,
CompareOptions opt)
{
AssertCompare (message, result, s1, s2, opt, invariant);
}
void AssertCompare (string message, int result, string s1, string s2,
CompareOptions opt, CompareInfo ci)
{
int ret = ci.Compare (s1, s2, opt);
if (result == 0)
AssertEquals (message, 0, ret);
else if (result < 0)
Assert (message + String.Format ("(neg: {0})", ret), ret < 0);
else
Assert (message + String.Format ("(pos: {0})", ret), ret > 0);
}
void AssertCompare (string message, int result,
string s1, int idx1, int len1, string s2, int idx2, int len2)
{
int ret = invariant.Compare (s1, idx1, len1, s2, idx2, len2);
if (result == 0)
AssertEquals (message, 0, ret);
else if (result < 0)
Assert (message, ret < 0);
else
Assert (message, ret > 0);
}
void AssertCompare (string message, int result,
string s1, int idx1, int len1, string s2, int idx2, int len2,
CompareOptions opt, CompareInfo ci)
{
int ret = ci.Compare (s1, idx1, len1, s2, idx2, len2, opt);
if (result == 0)
AssertEquals (message, 0, ret);
else if (result < 0)
Assert (message, ret < 0);
else
Assert (message, ret > 0);
}
void AssertIndexOf (string message, int expected,
string source, char target)
{
AssertEquals (message, expected,
invariant.IndexOf (source, target));
}
void AssertIndexOf (string message, int expected, string source,
char target, CompareOptions opt)
{
AssertEquals (message, expected,
invariant.IndexOf (source, target, opt));
}
void AssertIndexOf (string message, int expected, string source,
char target, int idx, int len, CompareOptions opt, CompareInfo ci)
{
AssertEquals (message, expected,
ci.IndexOf (source, target, idx, len, opt));
}
void AssertIndexOf (string message, int expected,
string source, string target)
{
AssertEquals (message, expected,
invariant.IndexOf (source, target));
}
void AssertIndexOf (string message, int expected, string source,
string target, CompareOptions opt)
{
AssertEquals (message, expected,
invariant.IndexOf (source, target, opt));
}
void AssertIndexOf (string message, int expected, string source,
string target, int idx, int len, CompareOptions opt, CompareInfo ci)
{
AssertEquals (message, expected,
ci.IndexOf (source, target, idx, len, opt));
}
void AssertLastIndexOf (string message, int expected,
string source, char target)
{
AssertEquals (message, expected,
invariant.LastIndexOf (source, target));
}
void AssertLastIndexOf (string message, int expected, string source,
char target, CompareOptions opt)
{
AssertEquals (message, expected,
invariant.LastIndexOf (source, target, opt));
}
void AssertLastIndexOf (string message, int expected, string source,
char target, int idx, int len)
{
AssertEquals (message, expected,
invariant.LastIndexOf (source, target, idx, len));
}
void AssertLastIndexOf (string message, int expected, string source,
char target, int idx, int len, CompareOptions opt, CompareInfo ci)
{
AssertEquals (message, expected,
ci.LastIndexOf (source, target, idx, len, opt));
}
void AssertLastIndexOf (string message, int expected,
string source, string target)
{
AssertEquals (message, expected,
invariant.LastIndexOf (source, target));
}
void AssertLastIndexOf (string message, int expected, string source,
string target, CompareOptions opt)
{
AssertEquals (message, expected,
invariant.LastIndexOf (source, target, opt));
}
void AssertLastIndexOf (string message, int expected, string source,
string target, int idx, int len)
{
AssertEquals (message, expected,
invariant.LastIndexOf (source, target, idx, len));
}
void AssertLastIndexOf (string message, int expected, string source,
string target, int idx, int len, CompareOptions opt, CompareInfo ci)
{
AssertEquals (message, expected,
ci.LastIndexOf (source, target, idx, len, opt));
}
void AssertIsPrefix (string message, bool expected, string source,
string target)
{
Assert (message, expected == invariant.IsPrefix (
source, target));
}
void AssertIsPrefix (string message, bool expected, string source,
string target, CompareOptions opt)
{
Assert (message, expected == invariant.IsPrefix (
source, target, opt));
}
void AssertIsSuffix (string message, bool expected, string source,
string target)
{
Assert (message, expected == invariant.IsSuffix (
source, target));
}
void AssertIsSuffix (string message, bool expected, string source,
string target, CompareOptions opt)
{
Assert (message, expected == invariant.IsSuffix (
source, target, opt));
}
[Test]
public void GetSortKey ()
{
if (!doTest)
return;
// AE == \u00C6
AssertSortKey ("#1", new byte [] {0xE, 2, 0xE, 0x21, 1, 1,
0x12, 0x12, 1, 1, 0}, "AE");
AssertSortKey ("#2", new byte [] {0xE, 2, 0xE, 0x21, 1, 1,
0x12, 0x12, 1, 1, 0}, "\u00C6");
AssertSortKey ("#3", new byte [] {1, 1, 1, 1,
0x80, 7, 6, 0x82, 0}, "-");
AssertSortKey ("#4", new byte [] {1, 1, 1, 1,
0x80, 7, 6, 0x82, 0x80, 7, 6, 0x82, 0}, "--");
AssertSortKey ("#4", new byte [] {0xE, 2, 0xE, 9,
0xE, 0xA, 1, 1, 0x12, 0x12, 0x12, 1, 1, 0x80, 0xB,
6, 0x82, 0x80, 0xF, 6, 0x82, 0}, "A-B-C");
AssertSortKey ("#6", new byte [] {0xE, 2, 1,
0x17, 1, 0x12, 1, 1, 0}, "A\u0304");
AssertSortKey ("#7", new byte [] {0xE, 2, 1,
0x17, 1, 0x12, 1, 1, 0}, "\u0100");
// StringSort
AssertSortKey ("#8", new byte [] {
0xE, 2, 6, 0x82, 1, 1, 1, 1, 0},
"a-", CompareOptions.StringSort);
// FIXME: not working (table fix is required)
// AssertSortKey ("#9", new byte [] {
// 0xE, 2, 6, 0x82, 1, 1, 2, 0x3, 1, 1, 0},
// "a\uFF0D", CompareOptions.StringSort);
AssertSortKey ("#10", new byte [] {1, 1, 1, 1, 0}, "\u3007");
}
[Test]
public void GetSortKeyIgnoreWidth ()
{
if (!doTest)
return;
AssertSortKey ("#i1", new byte [] {
0xE, 2, 1, 1, 0x13, 1, 1, 0}, "\uFF21");
AssertSortKey ("#i2", new byte [] {
0xE, 2, 1, 1, 0x12, 1, 1, 0}, "\uFF21", CompareOptions.IgnoreWidth);
AssertSortKey ("#i3", new byte [] {
0xE, 2, 1, 1, 0x3, 1, 1, 0}, "\uFF41");
AssertSortKey ("#i4", new byte [] {
0xE, 2, 1, 1, 1, 1, 0}, "\uFF41", CompareOptions.IgnoreWidth);
}
[Test]
public void GetSortKeyDiacritical ()
{
if (!doTest)
return;
AssertSortKey ("#i1", new byte [] {
0xE, 0x21, 1, 0xE, 1, 1, 1, 0}, "e\u0301");
AssertSortKey ("#i2", new byte [] {
0xE, 0x21, 1, 0x12, 1, 1, 1, 0}, "e\u0302");
AssertSortKey ("#i3", new byte [] {
0xE, 0x21, 1, 0x13, 1, 1, 1, 0}, "e\u0308");
AssertSortKey ("#i4", new byte [] {
0xE, 0x21, 1, 0x1F, 1, 1, 1, 0}, "e\u0308\u0301");
// FIXME: not working (table fix is required)
// AssertSortKey ("#i5", new byte [] {
// 0xE, 0x21, 1, 0x16, 1, 1, 1, 0}, "e\u0344");
AssertSortKey ("#i6", new byte [] {
0x22, 2, 1, 0xE, 1, 1, 0xC4, 0xFF, 2, 0xFF, 0xFF, 1, 0}, "\u3041\u0301");
AssertSortKey ("#i7", new byte [] {
0xC, 0x21, 1, 0xE, 1, 1, 1, 0}, "1\u0301");
AssertSortKey ("#i8", new byte [] {
0x22, 0xA, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0}, "\u304B\u309B");
AssertSortKey ("#i9", new byte [] {
0x22, 0xA, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0}, "\u304C");
AssertSortKey ("#i10", new byte [] {
0xE, 0x2, 1, 0x12, 1, 0x12, 1, 1, 0},
"A\u0302");
AssertSortKey ("#i11", new byte [] {
0xE, 0x2, 1, 0x65, 1, 0x12, 1, 1, 0},
"A\u0302\u0320");
AssertSortKey ("#i12", new byte [] {
0xE, 0x2, 1, 0xB8, 1, 0x12, 1, 1, 0},
"A\u0302\u0320\u0320");
// LAMESPEC: Windows just appends diacritical weight without
// AssertSortKey ("#i13", new byte [] {
// 0xE, 0x2, 1, 0xB, 1, 12, 1, 1, 0},
// "A\u0302\u0320\u0320\u0320");
// FIXME: not working (table fix is required)
// AssertSortKey ("#i14", new byte [] {
// 0xE, 0x2, 1, 0xF2, 1, 0x12, 1, 1, 0},
// "A\u20E1");
// LAMESPEC: It should not be equivalent to \u1EA6
AssertSortKey ("#i15", new byte [] {
0xE, 0x2, 1, 0x1F, 1, 0x12, 1, 1, 0},
"A\u0308\u0301");
AssertSortKey ("#i16", new byte [] {
0xE, 0x2, 1, 0x1F, 1, 0x12, 1, 1, 0},
"\u1EA6");
}
[Test]
public void GetSortKeyIgnoreNonSpaceKana ()
{
if (!doTest)
return;
AssertSortKey ("#i1", new byte [] {
0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
"\u305F");
AssertSortKey ("#i2", new byte [] {
0x22, 0x1A, 1, 3, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
"\u3060");
AssertSortKey ("#i3", new byte [] {
0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
"\u305F", CompareOptions.IgnoreNonSpace);
AssertSortKey ("#i4", new byte [] {
0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
"\u3060", CompareOptions.IgnoreNonSpace);
}
[Test]
public void GetSortKeySpecialWeight ()
{
if (!doTest)
return;
AssertSortKey ("#i1", new byte [] {
0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
"\u304B\u3042");
AssertSortKey ("#i2", new byte [] {
0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 5, 2, 0xFF, 0xFF, 1, 0},
"\u304B\u30FC");
AssertSortKey ("#i3", new byte [] {
0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
"\u304B\u30FC", CompareOptions.IgnoreNonSpace);
AssertSortKey ("#i4", new byte [] {
0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 2, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
"\u30AB\u30AC");
AssertSortKey ("#i5", new byte [] {
0x22, 0xA, 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
"\u30AB\u30AB\u30FC");
AssertSortKey ("#i6", new byte [] {
0x22, 0xA, 0x22, 2, 0x22, 2, 1, 1, 1, 0xFF, 3, 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
"\u30AB\u30A2\u30FC");
AssertSortKey ("#i7", new byte [] {
0x22, 0xA, 0x22, 2, 0x22, 2, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 3, 5, 2, 0xC4, 0xC4, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
"\u30AB\u30A2\u30FC\u30AB");
AssertSortKey ("#i8", new byte [] {
0x22, 0xA, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
"\u304B\u309D");
AssertSortKey ("#i9", new byte [] {
0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
"\u304B\u309E");
AssertSortKey ("#i10", new byte [] {
0x22, 0x2, 0x22, 0x2, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
"\u3042\u309E");//not possible
AssertSortKey ("#i11", new byte [] {
0x22, 0xA, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
"\u304B\u30FD");//not possible
AssertSortKey ("#i12", new byte [] {
0x22, 0xA, 0x22, 0xA, 1, 2, 3, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
"\u304B\u30FE");//not possible
AssertSortKey ("#i13", new byte [] {
0x22, 0xA, 0x22, 0xA, 1, 1, 1, 0xFF, 3, 4, 2, 0xC4, 0xC4, 0xFF, 0xFF, 1, 0},
"\u30AB\u30FD");
AssertSortKey ("#i14", new byte [] {
0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 3, 5, 2, 0xC4, 0xC4, 0xFF, 0xC4, 0xC4, 0xFF, 1, 0},
"\uFF76\uFF70");
AssertSortKey ("#i15", new byte [] {
0x22, 0xA, 0x22, 0xA, 1, 2, 5, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
"\u304B\u3005");
AssertSortKey ("#i16", new byte [] {
0xAF, 9, 0xAF, 9, 1, 2, 5, 1, 1, 1, 0},
"\u5EA6\u3005");
AssertSortKey ("#i17", new byte [] {
0xE, 2, 0xE, 2, 1, 2, 5, 1, 1, 1, 0},
"a\u3005"); // huh
// Not working, but I wonder if it is really FIXME.
// AssertSortKey ("#i18", new byte [] {
// 0xFF, 0xFF, 1, 1, 1, 1, 0},
// "\u3005");
// LAMESPEC. No one can handle \u3031 correctly.
// AssertSortKey ("#i19", new byte [] {
// 0x22, 0x22, 0x22, 0xC, 0x22, 0xC, 1, 1, 1, 0xFF, 3, 4, 2, 0xFF, 0xFF, 1, 0},
// "\u306A\u304F\u3031");
// IgnoreWidth -> all Kana becomes half-width
AssertSortKey ("#i20", new byte [] {
34, 26, 34, 3, 34, 44, 1, 3, 2, 3, 1, 1, 255, 2, 196, 196, 196, 255, 196, 196, 196, 255, 1, 0},
"\uFF80\uFF9E\uFF72\uFF8C\uFF9E", CompareOptions.IgnoreWidth);
AssertSortKey ("#i21", new byte [] {
34, 26, 34, 3, 34, 44, 1, 3, 2, 3, 1, 1, 255, 2, 196, 196, 196, 255, 196, 196, 196, 255, 1, 0},
"\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
AssertSortKey ("#i22", new byte [] {
0x22, 0x2A, 0x22, 2, 0x22, 0x44, 1, 3, 1, 1, 0xFF,
3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xC4, 0xC4, 0xC4,
0xFF, 1, 0},
"\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
AssertSortKey ("#i23", new byte [] {
0x22, 0x2A, 0x22, 2, 0x22, 0x44, 1, 3, 1, 1, 0xFF,
3, 5, 2, 0xC4, 0xC4, 0xC4, 0xFF, 0xC4, 0xC4, 0xC4,
0xFF, 1, 0},
"\uFF8A\uFF9E\uFF70\uFF99", CompareOptions.IgnoreWidth);
// extender + IgnoreNonSpace
AssertSortKey ("#i24", new byte [] {
0x22, 2, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0},
"\u3042\u309D", CompareOptions.IgnoreNonSpace);
}
[Test]
public void GetSortKeyLevel5 ()
{
if (!doTest)
return;
// shift weight
AssertSortKeyLevel5 ("#8", new byte [] {
0x80, 7, 6, 0x82, 0x80, 0x2F, 6, 0x82, 0},
'-' + new string ('A', 10) + '-');
AssertSortKeyLevel5 ("#9", new byte [] {
0x80, 7, 6, 0x82, 0x80, 0xFF, 6, 0x82, 0},
'-' + new string ('A', 62) + '-');
AssertSortKeyLevel5 ("#10", new byte [] {
0x80, 7, 6, 0x82, 0x81, 3, 6, 0x82, 0},
'-' + new string ('A', 63) + '-');
AssertSortKeyLevel5 ("#11", new byte [] {
0x80, 7, 6, 0x82, 0x81, 0x97, 6, 0x82, 0},
'-' + new string ('A', 100) + '-');
AssertSortKeyLevel5 ("#12", new byte [] {
0x80, 7, 6, 0x82, 0x8F, 0xA7, 6, 0x82, 0},
'-' + new string ('A', 1000) + '-');
AssertSortKeyLevel5 ("#13", new byte [] {
0x80, 7, 6, 0x82, 0x9A, 0x87, 6, 0x82, 0},
'-' + new string ('A', 100000) + '-');
// This shows how Windows is broken.
// AssertSortKeyLevel5 ("#14",
// 0x80, 7, 6, 0x82, 0x89, 0x07, 6, 0x82, 0},
// '-' + new string ('A', 1000000) + '-');
}
[Test]
#if NET_2_0
[Category ("NotDotNet")]
#endif
public void FrenchSort ()
{
if (!doTest)
return;
// invariant
AssertSortKey ("#inv-1", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "c\u00F4te");
AssertSortKey ("#inv-1-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "co\u0302te");
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");
AssertSortKey ("#inv-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 2, 2, 0xE, 1, 1, 1, 0}, "cot\u00E9");
AssertSortKey ("#inv-2-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x14, 1, 1, 1, 0}, "co\u030Cte");
// They are all bugs in 2.0:
// #inv-3: should not be 0 since those sortkey values differ.
// #inv-4: should not be -1 since co\u0302te sortkey is bigger than cote\u0306.
AssertCompare ("#inv-3", 1, "c\u00F4te", "cot\u00E9");
AssertCompare ("#inv-4", 1, "co\u0302te", "cote\u0306");
AssertCompare ("#inv-5", 1, "co\u030Cte", "cote\u0306");
// french
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);
AssertSortKey ("#fr-2", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 0xE, 1, 1, 1, 0}, "cot\u00E9", CompareOptions.None, french);
AssertCompare ("#fr-3", -1, "c\u00F4te", "cot\u00E9", CompareOptions.None, french);
// FIXME: why does .NET return 1 ?
// AssertCompare ("#fr-4", -1, "co\u0302te", "cote\u0306", CompareOptions.None, french);
// AssertCompare ("#fr-4", -1, "co\u030Cte", "cote\u0306", CompareOptions.None, french);
}
[Test]
public void GetSortKeyThai ()
{
if (!doTest)
return;
AssertSortKey ("#i1", new byte [] {
0x1E, 7, 0x1F, 0x28, 1, 3, 3, 1, 1, 1, 0},
"\u0E01\u0E3A");
AssertSortKey ("#i2", new byte [] {
0x1E, 7, 1, 3, 1, 1, 1, 0},
"\u0E01\u0E3B");
// FIXME: not working (table fix required)
// AssertSortKey ("#i6", new byte [] {
// 0x1E, 7, 0xA, 0xF9, 1, 3, 1, 1, 1, 0},
// "\u0E01\u0E3F");
AssertSortKey ("#i7", new byte [] {
0x1E, 7, 0x1E, 2, 1, 3, 3, 1, 1, 1, 0},
"\u0E01\u0E40");
AssertSortKey ("#i8", new byte [] {
0x1E, 7, 0x1E, 3, 1, 3, 3, 1, 1, 1, 0},
"\u0E01\u0E41");
AssertSortKey ("#i9", new byte [] {
0x1E, 7, 0x1E, 4, 1, 3, 3, 1, 1, 1, 0},
"\u0E01\u0E42");
AssertSortKey ("#i10", new byte [] {
0x1E, 7, 0x1E, 5, 1, 3, 3, 1, 1, 1, 0},
"\u0E01\u0E43");
AssertSortKey ("#i11", new byte [] {
0x1E, 7, 0x1E, 6, 1, 3, 3, 1, 1, 1, 0},
"\u0E01\u0E44");
AssertSortKey ("#i12", new byte [] {
0x1E, 7, 0x1F, 0x29, 1, 3, 3, 1, 1, 1, 0},
"\u0E01\u0E45");
AssertSortKey ("#i13", new byte [] {
0x1E, 7, 0x1F, 0x2A, 1, 3, 3, 1, 1, 1, 0},
"\u0E01\u0E46");
// FIXME: not working (U+E47 table fix required)
// AssertSortKey ("#i14", new byte [] {
// 0x1E, 7, 1, 5, 1, 1, 1, 0},
// "\u0E01\u0E47");
AssertSortKey ("#i15", new byte [] {
0x1E, 7, 1, 6, 1, 1, 1, 0},
"\u0E01\u0E48");
AssertSortKey ("#i16", new byte [] {
0x1E, 7, 1, 7, 1, 1, 1, 0},
"\u0E01\u0E49");
AssertSortKey ("#i17", new byte [] {
0x1E, 7, 1, 8, 1, 1, 1, 0},
"\u0E01\u0E4A");
AssertSortKey ("#i18", new byte [] {
0x1E, 7, 1, 9, 1, 1, 1, 0},
"\u0E01\u0E4B");
// FIXME: not working (U+E47 table fix required)
// AssertSortKey ("#i19", new byte [] {
// 0x1E, 7, 1, 8, 1, 1, 1, 0},
// "\u0E01\u0E48\u0E47");
AssertSortKey ("#i20", new byte [] {
0x1E, 7, 0x1E, 4, 0x1E, 0xD, 1, 3, 3, 3, 1, 1, 1, 0},
"\u0E01\u0E42\u0E02");
AssertSortKey ("#i21", new byte [] {
0x1E, 7, 0x1E, 0xD, 1, 3, 3, 1, 1, 1, 0},
"\u0E01\u0E02");
}
[Test]
public void GetSortKeyCzechTailoring ()
{
if (!doTest)
return;
AssertSortKey ("#i1", new byte [] {
0xE, 0xA, 0xE, 0x2C, 1, 1, 1, 1, 0},
"ch");
AssertSortKey ("#cs1", new byte [] {
0xE, 0x2E, 1, 1, 1, 1, 0},
"ch", CompareOptions.None, czech);
AssertSortKey ("#i2", new byte [] {
0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
"r\u030C");
AssertSortKey ("#cs2", new byte [] {
0xE, 0x8A, 1, 0x14, 1, 1, 1, 0},
"r\u030C", CompareOptions.None, czech);
}
[Test]
public void GetSortKeyHungarianTailoring ()
{
if (!doTest)
return;
AssertSortKey ("#1", new byte [] {
0xE, 0xE, 1, 1, 0x1A, 1, 1, 0},
"CS", CompareOptions.None, hungarian);
AssertSortKey ("#2", new byte [] {
0xE, 0xE, 1, 1, 0x12, 1, 1, 0},
"Cs", CompareOptions.None, hungarian);
AssertSortKey ("#3", new byte [] {
0xE, 0xE, 1, 1, 1, 1, 0},
"cs", CompareOptions.None, hungarian);
AssertSortKey ("#4", new byte [] {
0xE, 0x1C, 1, 1, 0x1A, 1, 1, 0},
"DZ", CompareOptions.None, hungarian);
AssertSortKey ("#5", new byte [] {
0xE, 0x1C, 1, 1, 0x12, 1, 1, 0},
"Dz", CompareOptions.None, hungarian);
AssertSortKey ("#6", new byte [] {
0xE, 0x1C, 1, 1, 1, 1, 0},
"dz", CompareOptions.None, hungarian);
AssertSortKey ("#7", new byte [] {
0xE, 0x75, 1, 1, 0x1A, 1, 1, 0},
"NY", CompareOptions.None, hungarian);
AssertSortKey ("#8", new byte [] {
0xE, 0x75, 1, 1, 0x12, 1, 1, 0},
"Ny", CompareOptions.None, hungarian);
AssertSortKey ("#9", new byte [] {
0xE, 0x75, 1, 1, 1, 1, 0},
"ny", CompareOptions.None, hungarian);
AssertSortKey ("#10", new byte [] {
0xE, 0xB1, 1, 1, 0x1A, 1, 1, 0},
"ZS", CompareOptions.None, hungarian);
AssertSortKey ("#11", new byte [] {
0xE, 0xB1, 1, 1, 0x12, 1, 1, 0},
"Zs", CompareOptions.None, hungarian);
AssertSortKey ("#12", new byte [] {
0xE, 0xB1, 1, 1, 1, 1, 0},
"zs", CompareOptions.None, hungarian);
// Windows seems to have bugs around repetitive characters
// that is tailored.
// AssertSortKey ("#x", new byte [] {
// 0xE, 0x2E, 1, 1, 1, 1, 0},
// "CCS", CompareOptions.None, hungarian);
// FIXME: we need to handle case insensitivity
}
[Test]
public void CustomCJKTable ()
{
if (!doTest)
return;
AssertSortKey ("#1", new byte [] {
0x9E, 9, 0x9E, 0x11, 1, 1, 1, 1, 0},
"\u4E03\u4E09");
AssertSortKey ("#2", new byte [] {
0x84, 0xD3, 0x84, 0x61, 1, 1, 1, 1, 0},
"\u4E03\u4E09", CompareOptions.None, japanese);
}
[Test]
#if NET_2_0
[Category ("NotDotNet")]
#endif
public void CultureSensitiveCompare ()
{
if (!doTest)
return;
AssertCompare ("#1", -1, "1", "2");
AssertCompare ("#2", 1, "A", "a");
AssertCompare ("#3", 0, "A", "a", CompareOptions.IgnoreCase);
AssertCompare ("#4", 0, "\uFF10", "0", CompareOptions.IgnoreWidth);
AssertCompare ("#5", 0, "\uFF21", "a", ignoreCW);
AssertCompare ("#6", 1, "12", "1");
// BUG in .NET 2.0: See GetSortKey() test that assures sortkeys for "AE" and
// "\u00C6" are equivalent.
AssertCompare ("#7", 0, "AE", "\u00C6");
AssertCompare ("#8", 0, "AB\u01c0C", "A\u01c0B\u01c0C", CompareOptions.IgnoreSymbols);
// BUG in .NET 2.0: ditto.
AssertCompare ("#9", 0, "A\u0304", "\u0100");
AssertCompare ("#10", 1, "ABCABC", 5, 1, "1", 0, 1, CompareOptions.IgnoreCase, invariant);
AssertCompare ("#11", 0, "-d:NET_2_0", 0, 1, "-", 0, 1);
// BUG in .NET 2.0: ditto.
AssertCompare ("#12", 0, "ae", "\u00E6");
AssertCompare ("#13", 0, "\u00E6", "ae");
AssertCompare ("#14", 0, "\u00E6s", 0, 1, "ae", 0, 2);
// target is "empty" (in culture-sensitive context).
// BUG in .NET 2.0: \u3007 is totally-ignored character as a GetSortKey()
// result, while it is not in Compare().
AssertCompare ("#17", 0, String.Empty, "\u3007");
AssertCompare ("#18", 1, "A", "\u3007");
AssertCompare ("#19", 1, "ABC", "\u3007");
// shift weight comparison
AssertCompare ("#20", 1, "--start", "--");
// expansion
// BUG in .NET 2.0: the same 00C6/00E6 issue.
AssertCompare ("#21", -1, "\u00E6", "aes");
}
[Test]
#if NET_2_0
[Category ("NotDotNet")]
#endif
public void CompareSpecialWeight ()
{
if (!doTest)
return;
// Japanese (in invariant)
// BUG in .NET 2.0 : half-width kana should be bigger.
AssertCompare ("#1", 1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
AssertCompare ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
AssertCompare ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
"\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
AssertCompare ("#4", 1, "\u3042\u309D", "\u3042\u3042");
AssertCompare ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
AssertCompare ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
"\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
// extender in target
// BUG in .NET 2.0 : an extender should result in bigger sortkey
AssertCompare ("#7", -1, "\u30D1\u30A2", "\u30D1\u30FC");
AssertCompare ("#8", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
// extender in source
// BUG in .NET 2.0 : vice versa
AssertCompare ("#9", 1, "\u30D1\u30FC", "\u30D1\u30A2");
AssertCompare ("#10", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
}
[Test]
public void IndexOfChar ()
{
if (!doTest)
return;
AssertIndexOf ("#1", -1, "ABC", '1');
AssertIndexOf ("#2", 2, "ABCABC", 'c', CompareOptions.IgnoreCase);
AssertIndexOf ("#3", 1, "ABCABC", '\uFF22', ignoreCW);
AssertIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN);
AssertIndexOf ("#5", 1, "ABCABC", 'B', 1, 5, CompareOptions.IgnoreCase, invariant);
AssertIndexOf ("#6", 4, "ABCABC", 'B', 2, 4, CompareOptions.IgnoreCase, invariant);
AssertIndexOf ("#7", 1, "\u30D1\u30FC", '\u30A2', CompareOptions.IgnoreNonSpace);
AssertIndexOf ("#8", 1, "UAE", '\u00C6');
AssertIndexOf ("#8-2", 1, "AAE", '\u00C6');
AssertIndexOf ("#9", -1, "UA", '\u00C6');
AssertIndexOf ("#10", -1, "UE", '\u00C6');
}
[Test]
[Category ("NotDotNet")]
public void IndexOfCharMSBug ()
{
if (!doTest)
return;
AssertIndexOf ("#1", 0, "\u00E6", 'a');
}
[Test]
public void LastIndexOfChar ()
{
if (!doTest)
return;
AssertLastIndexOf ("#1", -1, "ABC", '1');
AssertLastIndexOf ("#2", 5, "ABCABC", 'c', CompareOptions.IgnoreCase);
AssertLastIndexOf ("#3", 4, "ABCABC", '\uFF22', ignoreCW);
AssertLastIndexOf ("#4", 4, "ABCDE", '\u0117', ignoreCN);
AssertLastIndexOf ("#5", 1, "ABCABC", 'B', 3, 3);
AssertLastIndexOf ("#6", 4, "ABCABC", 'B', 4, 4);
AssertLastIndexOf ("#7", -1, "ABCABC", 'B', 5, 1);
AssertLastIndexOf ("#8", 1, "UAE", '\u00C6');
AssertLastIndexOf ("#8-2", 1, "UAEE", '\u00C6');
AssertLastIndexOf ("#9", -1, "UA", '\u00C6');
AssertLastIndexOf ("#10", -1, "UE", '\u00C6');
AssertLastIndexOf ("#11", 0, "\\", '\\');
AssertEquals ("#11en", 0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\", '\\'));
AssertEquals ("#11ja", 0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\", '\\'));
}
[Test]
[Category ("NotDotNet")]
public void LastIndexOfCharMSBug ()
{
if (!doTest)
return;
AssertIndexOf ("#1", 0, "\u00E6", 'a');
}
[Test]
#if NET_2_0
[Category ("NotDotNet")]
#endif
public void IsPrefix ()
{
if (!doTest)
return;
AssertIsPrefix ("#1", false, "ABC", "c", CompareOptions.IgnoreCase);
AssertIsPrefix ("#2", false, "BC", "c", CompareOptions.IgnoreCase);
AssertIsPrefix ("#3", true, "C", "c", CompareOptions.IgnoreCase);
AssertIsPrefix ("#4", true, "EDCBA", "\u0117", ignoreCN);
AssertIsPrefix ("#5", true, "ABC", "AB", CompareOptions.IgnoreCase);
// BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
AssertIsPrefix ("#6", true, "ae", "\u00E6", CompareOptions.None);
AssertIsPrefix ("#7", true, "\u00E6", "ae", CompareOptions.None);
// BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
AssertIsPrefix ("#8", true, "\u00E6", "a", CompareOptions.None);
AssertIsPrefix ("#9", true, "\u00E6s", "ae", CompareOptions.None);
AssertIsPrefix ("#10", false, "\u00E6", "aes", CompareOptions.None);
AssertIsPrefix ("#11", true, "--start", "--", CompareOptions.None);
AssertIsPrefix ("#12", true, "-d:NET_1_1", "-", CompareOptions.None);
AssertIsPrefix ("#13", false, "-d:NET_1_1", "@", CompareOptions.None);
// U+3007 is completely ignored character.
AssertIsPrefix ("#14", true, "\uff21\uff21", "\uff21", CompareOptions.None);
// BUG in .NET 2.0 : see \u3007 issue (mentioned above).
AssertIsPrefix ("#15", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
AssertIsPrefix ("#16", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
AssertIsPrefix ("#17", true, "\\b\\a a", "\\b\\a a");
Assert ("#17en", new CultureInfo ("en").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"));
Assert ("#17ja", new CultureInfo ("ja").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"));
}
[Test]
public void IsPrefixSpecialWeight ()
{
if (!doTest)
return;
// Japanese (in invariant)
AssertIsPrefix ("#1", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
AssertIsPrefix ("#2", true, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
AssertIsPrefix ("#2-2", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
AssertIsPrefix ("#3", true, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
"\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
AssertIsPrefix ("#3-2", false, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
"\u30C0\u30A4\u30D6");
AssertIsPrefix ("#4", false, "\u3042\u309D", "\u3042\u3042");
AssertIsPrefix ("#5", true, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
AssertIsPrefix ("#6", true, "\uFF8A\uFF9E\uFF70\uFF99",
"\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
// extender in target
AssertIsPrefix ("#7", false, "\u30D1\u30A2", "\u30D1\u30FC");
AssertIsPrefix ("#8", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
// extender in source
AssertIsPrefix ("#9", false, "\u30D1\u30FC", "\u30D1\u30A2");
AssertIsPrefix ("#10", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
// empty suffix always matches the source.
AssertIsPrefix ("#11", true, "", "");
AssertIsPrefix ("#12", true, "/test.css", "");
// bug #76243
AssertIsPrefix ("#13", false, "\u00e4_", "a");
}
[Test]
#if NET_2_0
[Category ("NotDotNet")]
#endif
public void IsSuffix ()
{
if (!doTest)
return;
AssertIsSuffix ("#1", true, "ABC", "c", CompareOptions.IgnoreCase);
AssertIsSuffix ("#2", true, "BC", "c", CompareOptions.IgnoreCase);
AssertIsSuffix ("#3", false, "CBA", "c", CompareOptions.IgnoreCase);
AssertIsSuffix ("#4", true, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
AssertIsSuffix ("#5", false, "\u00E6", "a", CompareOptions.None);
// BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
AssertIsSuffix ("#6", true, "\u00E6", "ae", CompareOptions.None);
AssertIsSuffix ("#7", true, "ae", "\u00E6", CompareOptions.None);
AssertIsSuffix ("#8", false, "e", "\u00E6", CompareOptions.None);
// U+3007 is completely ignored character.
AssertIsSuffix ("#9", true, "\uff21\uff21", "\uff21", CompareOptions.None);
// BUG in .NET 2.0 : see \u3007 issue (mentioned above).
AssertIsSuffix ("#10", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
AssertIsSuffix ("#11", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
// extender in target
AssertIsSuffix ("#12", false, "\u30D1\u30A2", "\u30D1\u30FC");
AssertIsSuffix ("#13", true, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
// extender in source
AssertIsSuffix ("#14", false, "\u30D1\u30FC", "\u30D1\u30A2");
AssertIsSuffix ("#15", true, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
// optimization sanity check
AssertIsSuffix ("#16", true,
"/configuration/system.runtime.remoting",
"system.runtime.remoting");
// empty suffix always matches the source.
AssertIsSuffix ("#17", true, "", "");
AssertIsSuffix ("#18", true, "/test.css", "");
AssertIsSuffix ("#19", true, "/test.css", "/test.css");
AssertIsSuffix ("#20", true, "\\b\\a a", "\\b\\a a");
Assert ("#20en", new CultureInfo ("en").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"));
Assert ("#20ja", new CultureInfo ("ja").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"));
}
[Test]
[Category ("NotDotNet")]
[Category ("NotWorking")]
public void IsSuffixMSBug ()
{
if (!doTest)
return;
AssertIsSuffix ("#1", true, "\u00E6", "e", CompareOptions.None);
}
[Test]
#if NET_2_0
[Category ("NotDotNet")]
#endif
public void IndexOfString ()
{
if (!doTest)
return;
AssertIndexOf ("#1", -1, "ABC", "1", CompareOptions.None);
AssertIndexOf ("#2", 2, "ABCABC", "c", CompareOptions.IgnoreCase);
AssertIndexOf ("#3", 1, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
AssertIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
AssertIndexOf ("#5", 1, "ABCABC", "BC", CompareOptions.IgnoreCase);
AssertIndexOf ("#6", 1, "BBCBBC", "BC", CompareOptions.IgnoreCase);
AssertIndexOf ("#7", -1, "ABCDEF", "BCD", 0, 3, CompareOptions.IgnoreCase, invariant);
AssertIndexOf ("#8", 0, "-ABC", "-", CompareOptions.None);
AssertIndexOf ("#9", 0, "--ABC", "--", CompareOptions.None);
AssertIndexOf ("#10", -1, "--ABC", "--", 1, 2, CompareOptions.None, invariant);
// BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
AssertIndexOf ("#11", 0, "AE", "\u00C6", CompareOptions.None);
// U+3007 is completely ignored character.
AssertIndexOf ("#12", 0, "\uff21\uff21", "\uff21", CompareOptions.None);
// BUG in .NET 2.0 : see \u3007 issue (mentioned above).
AssertIndexOf ("#13", 0, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
AssertIndexOf ("#14", 0, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
AssertIndexOf ("#15", 0, "\uff21\uff21", "\u3007", CompareOptions.None);
AssertIndexOf ("#15-2", 1, "\u3007\uff21", "\uff21", CompareOptions.None);
// target is "empty" (in culture-sensitive context).
AssertIndexOf ("#16", -1, String.Empty, "\u3007");
// BUG in .NET 2.0 : see \u3007 issue (mentioned above).
AssertIndexOf ("#17", 0, "A", "\u3007");
AssertIndexOf ("#18", 0, "ABC", "\u3007");
AssertIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
AssertEquals ("#19en", 0, new CultureInfo ("en").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"));
AssertEquals ("#19ja", 0, new CultureInfo ("ja").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"));
}
[Test]
public void IndexOfSpecialWeight ()
{
if (!doTest)
return;
// Japanese (in invariant)
AssertIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
// extender in target
AssertIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
AssertIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
// extender in source
AssertIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
AssertIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
AssertIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
AssertIndexOf ("#2-2", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
AssertIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
"\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
AssertIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
AssertIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
AssertIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
"\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
}
[Test]
#if NET_2_0
[Category ("NotDotNet")]
#endif
public void LastIndexOfString ()
{
if (!doTest)
return;
AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions.None);
AssertLastIndexOf ("#2", 5, "ABCABC", "c", CompareOptions.IgnoreCase);
AssertLastIndexOf ("#3", 4, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
AssertLastIndexOf ("#4", 4, "ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
AssertLastIndexOf ("#5", 4, "ABCABC", "BC", CompareOptions.IgnoreCase);
AssertLastIndexOf ("#6", 4, "BBCBBC", "BC", CompareOptions.IgnoreCase);
AssertLastIndexOf ("#7", 1, "original", "rig", CompareOptions.None);
// BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
AssertLastIndexOf ("#8", 0, "\u00E6", "ae", CompareOptions.None);
AssertLastIndexOf ("#9", 0, "-ABC", "-", CompareOptions.None);
AssertLastIndexOf ("#10", 0, "--ABC", "--", CompareOptions.None);
AssertLastIndexOf ("#11", -1, "--ABC", "--", 2, 2, CompareOptions.None, invariant);
AssertLastIndexOf ("#12", -1, "--ABC", "--", 4, 2, CompareOptions.None, invariant);
// BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
AssertLastIndexOf ("#13", 0, "AE", "\u00C6", CompareOptions.None);
// U+3007 is completely ignored character.
AssertLastIndexOf ("#14", 1, "\uff21\uff21", "\uff21", CompareOptions.None);
// BUG in .NET 2.0 : see \u3007 issue (mentioned above).
AssertLastIndexOf ("#15", 1, "\uff21\uff21", "\u3007\uff21", CompareOptions.None);
AssertLastIndexOf ("#16", 1, "\uff21\uff21", "\uff21\u3007", CompareOptions.None);
AssertLastIndexOf ("#17", 1, "\uff21\uff21", "\u3007", CompareOptions.None);
AssertLastIndexOf ("#18", 1, "\u3007\uff21", "\uff21", CompareOptions.None);
AssertLastIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a");
AssertEquals ("#19en", 0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"));
AssertEquals ("#19ja", 0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"));
}
[Test]
public void LastIndexOfSpecialWeight ()
{
if (!doTest)
return;
// Japanese (in invariant)
AssertLastIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D");
// extender in target
AssertLastIndexOf ("#1-2", -1, "\u30D1\u30A2", "\u30D1\u30FC");
AssertLastIndexOf ("#1-3", 0, "\u30D1\u30A2", "\u30D1\u30FC", CompareOptions.IgnoreNonSpace);
// extender in source
AssertLastIndexOf ("#1-4", 0, "\u30D1\u30FC", "\u30D1\u30A2", CompareOptions.IgnoreNonSpace);
// FIXME: not working (extender support is not complete.
// Currently private IsPrefix() cannot handle heading
// extenders to consume previous primary char.)
// AssertLastIndexOf ("#1-5", 1, "\u30D1\u30FC", "\u30A2", CompareOptions.IgnoreNonSpace);
// this shows that Windows accesses beyond the length and
// acquires the corresponding character to expand.
// AssertLastIndexOf ("#1-6", 1, "\u30D1\u30FC", "\u30A2", 1, 1, CompareOptions.IgnoreNonSpace, invariant);
AssertLastIndexOf ("#2", 0, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D", CompareOptions.IgnoreWidth);
AssertLastIndexOf ("#3", 0, "\uFF80\uFF9E\uFF72\uFF8C\uFF9E",
"\u30C0\u30A4\u30D6", CompareOptions.IgnoreWidth);
AssertLastIndexOf ("#4", -1, "\u3042\u309D", "\u3042\u3042");
AssertLastIndexOf ("#5", 0, "\u3042\u309D", "\u3042\u3042", CompareOptions.IgnoreNonSpace);
AssertLastIndexOf ("#6", 0, "\uFF8A\uFF9E\uFF70\uFF99",
"\u30D0\u30FC\u30EB", CompareOptions.IgnoreWidth);
}
[Test]
// for bug #76702
public void NullCharacter ()
{
AssertEquals ("#1", -1, "MONO".IndexOf ("\0\0\0"));
AssertEquals ("#2", -1, "MONO".LastIndexOf ("\0\0\0"));
AssertEquals ("#3", 1, "MONO".CompareTo ("\0\0\0"));
}
[Test]
[Category ("NotDotNet")]
// MS.NET treats it as equivalent, while in IndexOf() it does not match.
public void NullCharacterWeird ()
{
AssertEquals ("#4", -1, "MONO".CompareTo ("MONO\0\0\0"));
}
#if NET_2_0
[Test]
[Category ("NotDotNet")]
public void OrdinalIgnoreCaseCompare ()
{
if (!doTest)
return;
// matches
// BUG in .NET 2.0 : see GetSortKey() test (mentioned above).
AssertCompare ("#1", 0, "AE", "\u00C6", CompareOptions.None);
// BUG in .NET 2.0 : It raises inappropriate ArgumentException.
// should not match since it is Ordinal
AssertCompare ("#2", -133, "AE", "\u00C6", CompareOptions.OrdinalIgnoreCase);
AssertCompare ("#3", 1, "AE", "\u00E6", CompareOptions.None);
// matches
AssertCompare ("#4", 0, "AE", "\u00E6", CompareOptions.IgnoreCase);
// should not match since it is Ordinal
AssertCompare ("#5", -133, "AE", "\u00E6", CompareOptions.OrdinalIgnoreCase);
AssertCompare ("#6", 0, "AE", "ae", CompareOptions.OrdinalIgnoreCase);
AssertCompare ("#7", 0, "aE", "ae", CompareOptions.OrdinalIgnoreCase);
AssertCompare ("#8", 0, "aE", "ae", CompareOptions.OrdinalIgnoreCase);
AssertCompare ("#9", 0, "ae", "ae", CompareOptions.OrdinalIgnoreCase);
AssertCompare ("#10", 0, "AE", "AE", CompareOptions.OrdinalIgnoreCase);
AssertCompare ("#11", 0, "aE", "AE", CompareOptions.OrdinalIgnoreCase);
AssertCompare ("#12", 0, "aE", "AE", CompareOptions.OrdinalIgnoreCase);
AssertCompare ("#13", 0, "ae", "AE", CompareOptions.OrdinalIgnoreCase);
AssertCompare ("#14", 0, "ola", "OLA", CompareOptions.OrdinalIgnoreCase);
}
#endif
}
}
|