Differences From Artifact [40fec06275]:
- File tests/OFStringTests.m — part of check-in [e73c65a849] at 2021-04-18 22:56:46 on branch new-naming-convention — Rename all symbols marked extern (user: js, size: 54528) [annotate] [blame] [check-ins using] [more...]
To Artifact [ebff40f9d8]:
- File
tests/OFStringTests.m
— part of check-in
[14f1e22d79]
at
2021-05-08 23:22:59
on branch trunk
— tests: Align more with ObjFW style
ObjFW's style changed over the years, but the tests were never adjusted
to it. (user: js, size: 57247) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
26 27 28 29 30 31 32 | #import "OFUTF8String.h" #ifndef INFINITY # define INFINITY __builtin_inf() #endif static OFString *module = nil; | | | | | | | 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 | #import "OFUTF8String.h" #ifndef INFINITY # define INFINITY __builtin_inf() #endif static OFString *module = nil; static OFString *const whitespace[] = { @" \r \t\n\t \tasd \t \t\t\r\n", @" \t\t \t\t \t \t" }; static const OFUnichar unicharString[] = { 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0x1F03A, 0 }; static const OFUnichar swappedUnicharString[] = { 0xFFFE0000, 0x66000000, 0xF6000000, 0xF6000000, 0x62000000, 0xE4000000, 0x72000000, 0x3AF00100, 0 }; static const uint16_t UTF16String[] = { 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0xD83C, 0xDC3A, 0 }; static const uint16_t swappedUTF16String[] = { 0xFFFE, 0x6600, 0xF600, 0xF600, 0x6200, 0xE400, 0x7200, 0x3CD8, 0x3ADC, 0 }; @interface SimpleString: OFString { OFMutableString *_string; |
︙ | ︙ | |||
209 210 211 212 213 214 215 | @end @implementation TestsAppDelegate (OFStringTests) - (void)stringTestsWithClass: (Class)stringClass mutableClass: (Class)mutableStringClass { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | | | | | | > | | 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 | @end @implementation TestsAppDelegate (OFStringTests) - (void)stringTestsWithClass: (Class)stringClass mutableClass: (Class)mutableStringClass { void *pool = objc_autoreleasePoolPush(); OFMutableString *mutableString1, *mutableString2, *mutableString3; OFString *string; OFArray *array; size_t i; const OFUnichar *characters; const uint16_t *UTF16Characters; OFCharacterSet *characterSet; EntityHandler *entityHandler; #ifdef OF_HAVE_BLOCKS __block int j; __block bool ok; #endif #define C(s) ((OFString *)[stringClass stringWithString: s]) mutableString1 = [mutableStringClass stringWithString: @"täs€"]; mutableString2 = [mutableStringClass string]; mutableString3 = [[mutableString1 copy] autorelease]; TEST(@"-[isEqual:]", [mutableString1 isEqual: mutableString3] && ![mutableString1 isEqual: [[[OFObject alloc] init] autorelease]]) TEST(@"-[compare:]", [mutableString1 compare: mutableString3] == OFOrderedSame && [mutableString1 compare: @""] != OFOrderedSame && [C(@"") compare: @"a"] == OFOrderedAscending && [C(@"a") compare: @"b"] == OFOrderedAscending && [C(@"cd") compare: @"bc"] == OFOrderedDescending && [C(@"ä") compare: @"ö"] == OFOrderedAscending && [C(@"€") compare: @"ß"] == OFOrderedDescending && [C(@"aa") compare: @"z"] == OFOrderedAscending) |
︙ | ︙ | |||
261 262 263 264 265 266 267 | [C(@"AA") caseInsensitiveCompare: @"z"] == OFOrderedAscending && [[stringClass stringWithUTF8String: "ABC"] caseInsensitiveCompare: [stringClass stringWithUTF8String: "AbD"]] == [C(@"abc") compare: @"abd"]) #endif TEST(@"-[hash] is the same if -[isEqual:] is true", | | | > | > > | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | > | > | | | | | | | | | | | | | | | | | | > | | 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 | [C(@"AA") caseInsensitiveCompare: @"z"] == OFOrderedAscending && [[stringClass stringWithUTF8String: "ABC"] caseInsensitiveCompare: [stringClass stringWithUTF8String: "AbD"]] == [C(@"abc") compare: @"abd"]) #endif TEST(@"-[hash] is the same if -[isEqual:] is true", mutableString1.hash == mutableString3.hash) TEST(@"-[description]", [mutableString1.description isEqual: mutableString1]) TEST(@"-[appendString:] and -[appendUTF8String:]", R([mutableString2 appendUTF8String: "1𝄞"]) && R([mutableString2 appendString: @"3"]) && R([mutableString1 appendString: mutableString2]) && [mutableString1 isEqual: @"täs€1𝄞3"]) TEST(@"-[appendCharacters:length:]", R([mutableString2 appendCharacters: unicharString + 6 length: 2]) && [mutableString2 isEqual: @"1𝄞3r🀺"]) TEST(@"-[length]", mutableString1.length == 7) TEST(@"-[UTF8StringLength]", mutableString1.UTF8StringLength == 13) TEST(@"-[hash]", mutableString1.hash == 0x705583C0) TEST(@"-[characterAtIndex:]", [mutableString1 characterAtIndex: 0] == 't' && [mutableString1 characterAtIndex: 1] == 0xE4 && [mutableString1 characterAtIndex: 3] == 0x20AC && [mutableString1 characterAtIndex: 5] == 0x1D11E) EXPECT_EXCEPTION(@"Detect out of range in -[characterAtIndex:]", OFOutOfRangeException, [mutableString1 characterAtIndex: 7]) TEST(@"-[reverse]", R([mutableString1 reverse]) && [mutableString1 isEqual: @"3𝄞1€sät"]) mutableString2 = [mutableStringClass stringWithString: @"abc"]; #ifdef OF_HAVE_UNICODE_TABLES TEST(@"-[uppercase]", R([mutableString1 uppercase]) && [mutableString1 isEqual: @"3𝄞1€SÄT"] && R([mutableString2 uppercase]) && [mutableString2 isEqual: @"ABC"]) TEST(@"-[lowercase]", R([mutableString1 lowercase]) && [mutableString1 isEqual: @"3𝄞1€sät"] && R([mutableString2 lowercase]) && [mutableString2 isEqual: @"abc"]) TEST(@"-[uppercaseString]", [[mutableString1 uppercaseString] isEqual: @"3𝄞1€SÄT"]) TEST(@"-[lowercaseString]", R([mutableString1 uppercase]) && [[mutableString1 lowercaseString] isEqual: @"3𝄞1€sät"]) TEST(@"-[capitalizedString]", [C(@"džbla tdžst TDŽST").capitalizedString isEqual: @"Džbla Tdžst Tdžst"]) #else TEST(@"-[uppercase]", R([mutableString1 uppercase]) && [mutableString1 isEqual: @"3𝄞1€SäT"] && R([mutableString2 uppercase]) && [mutableString2 isEqual: @"ABC"]) TEST(@"-[lowercase]", R([mutableString1 lowercase]) && [mutableString1 isEqual: @"3𝄞1€sät"] && R([mutableString2 lowercase]) && [mutableString2 isEqual: @"abc"]) TEST(@"-[uppercaseString]", [mutableString1.uppercaseString isEqual: @"3𝄞1€SäT"]) TEST(@"-[lowercaseString]", R([mutableString1 uppercase]) && [mutableString1.lowercaseString isEqual: @"3𝄞1€sät"]) TEST(@"-[capitalizedString]", [C(@"džbla tdžst TDŽST").capitalizedString isEqual: @"džbla Tdžst TDŽst"]) #endif TEST(@"+[stringWithUTF8String:length:]", (mutableString1 = [mutableStringClass stringWithUTF8String: "\xEF\xBB\xBF" "foobar" length: 6]) && [mutableString1 isEqual: @"foo"]) TEST(@"+[stringWithUTF16String:]", (string = [stringClass stringWithUTF16String: UTF16String]) && [string isEqual: @"fööbär🀺"] && (string = [stringClass stringWithUTF16String: swappedUTF16String]) && [string isEqual: @"fööbär🀺"]) TEST(@"+[stringWithUTF32String:]", (string = [stringClass stringWithUTF32String: unicharString]) && [string isEqual: @"fööbär🀺"] && (string = [stringClass stringWithUTF32String: swappedUnicharString]) && [string isEqual: @"fööbär🀺"]) #ifdef OF_HAVE_FILES TEST(@"+[stringWithContentsOfFile:encoding]", (string = [stringClass stringWithContentsOfFile: @"testfile.txt" encoding: OFStringEncodingISO8859_1]) && [string isEqual: @"testäöü"]) TEST(@"+[stringWithContentsOfURL:encoding]", (string = [stringClass stringWithContentsOfURL: [OFURL fileURLWithPath: @"testfile.txt"] encoding: OFStringEncodingISO8859_1]) && [string isEqual: @"testäöü"]) #endif TEST(@"-[appendUTFString:length:]", R([mutableString1 appendUTF8String: "\xEF\xBB\xBF" "barqux" length: 6]) && [mutableString1 isEqual: @"foobar"]) EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #1", OFInvalidEncodingException, [stringClass stringWithUTF8String: "\xE0\x80"]) EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #2", OFInvalidEncodingException, [stringClass stringWithUTF8String: "\xF0\x80\x80\xC0"]) |
︙ | ︙ | |||
471 472 473 474 475 476 477 | #ifdef HAVE_CODEPAGE_437 TEST(@"Lossy conversion of Unicode to Codepage 437", !strcmp([C(@"T€st strîng ░▒▓") lossyCStringWithEncoding: OFStringEncodingCodepage437], "T?st str\x8Cng \xB0\xB1\xB2")) #endif TEST(@"+[stringWithFormat:]", | | > | | | > | | | | | | < | | | | | | | | 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 | #ifdef HAVE_CODEPAGE_437 TEST(@"Lossy conversion of Unicode to Codepage 437", !strcmp([C(@"T€st strîng ░▒▓") lossyCStringWithEncoding: OFStringEncodingCodepage437], "T?st str\x8Cng \xB0\xB1\xB2")) #endif TEST(@"+[stringWithFormat:]", [(mutableString1 = [mutableStringClass stringWithFormat: @"%@:%d", @"test", 123]) isEqual: @"test:123"]) TEST(@"-[appendFormat:]", R(([mutableString1 appendFormat: @"%02X", 15])) && [mutableString1 isEqual: @"test:1230F"]) TEST(@"-[rangeOfString:]", [C(@"𝄞öö") rangeOfString: @"öö"].location == 1 && [C(@"𝄞öö") rangeOfString: @"ö"].location == 1 && [C(@"𝄞öö") rangeOfString: @"𝄞"].location == 0 && [C(@"𝄞öö") rangeOfString: @"x"].location == OFNotFound && [C(@"𝄞öö") rangeOfString: @"öö" options: OFStringSearchBackwards].location == 1 && [C(@"𝄞öö") rangeOfString: @"ö" options: OFStringSearchBackwards].location == 2 && [C(@"𝄞öö") rangeOfString: @"𝄞" options: OFStringSearchBackwards].location == 0 && [C(@"𝄞öö") rangeOfString: @"x" options: OFStringSearchBackwards].location == OFNotFound) EXPECT_EXCEPTION( @"Detect out of range in -[rangeOfString:options:range:]", OFOutOfRangeException, [C(@"𝄞öö") rangeOfString: @"ö" options: 0 range: OFRangeMake(3, 1)]) characterSet = [OFCharacterSet characterSetWithCharactersInString: @"cđ"]; TEST(@"-[indexOfCharacterFromSet:]", [C(@"abcđabcđe") indexOfCharacterFromSet: characterSet] == 2 && [C(@"abcđabcđë") indexOfCharacterFromSet: characterSet options: OFStringSearchBackwards] == 7 && [C(@"abcđabcđë") indexOfCharacterFromSet: characterSet options: 0 range: OFRangeMake(4, 4)] == 6 && [C(@"abcđabcđëf") indexOfCharacterFromSet: characterSet options: 0 range: OFRangeMake(8, 2)] == OFNotFound) EXPECT_EXCEPTION( @"Detect out of range in -[indexOfCharacterFromSet:options:range:]", OFOutOfRangeException, [C(@"𝄞öö") indexOfCharacterFromSet: characterSet options: 0 range: OFRangeMake(3, 1)]) TEST(@"-[substringWithRange:]", [[C(@"𝄞öö") substringWithRange: OFRangeMake(1, 1)] isEqual: @"ö"] && [[C(@"𝄞öö") substringWithRange: OFRangeMake(3, 0)] isEqual: @""]) |
︙ | ︙ | |||
561 562 563 564 565 566 567 | !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath) # else TEST(@"-[isAbsolutePath]", C(@"/foo").absolutePath && C(@"/foo/bar").absolutePath && !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath) # endif | | | | | | | | | | | > | > | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | 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 | !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath) # else TEST(@"-[isAbsolutePath]", C(@"/foo").absolutePath && C(@"/foo/bar").absolutePath && !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath) # endif mutableString1 = [mutableStringClass stringWithString: @"foo"]; # if defined(OF_WINDOWS) || defined(OF_MSDOS) [mutableString1 appendString: @"\\"]; # else [mutableString1 appendString: @"/"]; # endif [mutableString1 appendString: @"bar"]; mutableString2 = [mutableStringClass stringWithString: mutableString1]; # if defined(OF_WINDOWS) || defined(OF_MSDOS) [mutableString2 appendString: @"\\"]; # else [mutableString2 appendString: @"/"]; # endif string = [stringClass stringWithString: mutableString2]; [mutableString2 appendString: @"baz"]; TEST(@"-[stringByAppendingPathComponent:]", [[mutableString1 stringByAppendingPathComponent: @"baz"] isEqual: mutableString2] && [[string stringByAppendingPathComponent: @"baz"] isEqual: mutableString2]) #endif TEST(@"-[hasPrefix:]", [C(@"foobar") hasPrefix: @"foo"] && ![C(@"foobar") hasPrefix: @"foobar0"]) TEST(@"-[hasSuffix:]", [C(@"foobar") hasSuffix: @"bar"] && ![C(@"foobar") hasSuffix: @"foobar0"]) i = 0; TEST(@"-[componentsSeparatedByString:]", (array = [C(@"fooXXbarXXXXbazXXXX") componentsSeparatedByString: @"XX"]) && [[array objectAtIndex: i++] isEqual: @"foo"] && [[array objectAtIndex: i++] isEqual: @"bar"] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @"baz"] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @""] && array.count == i && (array = [C(@"foo") componentsSeparatedByString: @""]) && [[array objectAtIndex: 0] isEqual: @"foo"] && array.count == 1) i = 0; TEST(@"-[componentsSeparatedByString:options:]", (array = [C(@"fooXXbarXXXXbazXXXX") componentsSeparatedByString: @"XX" options: OFStringSkipEmptyComponents]) && [[array objectAtIndex: i++] isEqual: @"foo"] && [[array objectAtIndex: i++] isEqual: @"bar"] && [[array objectAtIndex: i++] isEqual: @"baz"] && array.count == i) characterSet = [OFCharacterSet characterSetWithCharactersInString: @"XYZ"]; i = 0; TEST(@"-[componentsSeparatedByCharactersInSet:]", (array = [C(@"fooXYbarXYZXbazXYXZx") componentsSeparatedByCharactersInSet: characterSet]) && [[array objectAtIndex: i++] isEqual: @"foo"] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @"bar"] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @"baz"] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @"x"] && array.count == i) i = 0; TEST(@"-[componentsSeparatedByCharactersInSet:options:]", (array = [C(@"fooXYbarXYZXbazXYXZ") componentsSeparatedByCharactersInSet: characterSet options: OFStringSkipEmptyComponents]) && [[array objectAtIndex: i++] isEqual: @"foo"] && [[array objectAtIndex: i++] isEqual: @"bar"] && [[array objectAtIndex: i++] isEqual: @"baz"] && array.count == i) #ifdef OF_HAVE_FILES # if defined(OF_WINDOWS) TEST(@"+[pathWithComponents:]", [[stringClass pathWithComponents: [OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil]] isEqual: @"foo\\bar\\baz"] && [[stringClass pathWithComponents: [OFArray arrayWithObjects: |
︙ | ︙ | |||
744 745 746 747 748 749 750 | [[stringClass pathWithComponents: [OFArray arrayWithObjects: @"foo", nil]] isEqual: @"foo"]) # endif # if defined(OF_WINDOWS) TEST(@"-[pathComponents]", /* c:/tmp */ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 | [[stringClass pathWithComponents: [OFArray arrayWithObjects: @"foo", nil]] isEqual: @"foo"]) # endif # if defined(OF_WINDOWS) TEST(@"-[pathComponents]", /* c:/tmp */ (array = C(@"c:/tmp").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"c:/"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* c:\tmp\ */ (array = C(@"c:\\tmp\\").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"c:\\"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* c:\ */ (array = C(@"c:\\").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:\\"] && /* c:/ */ (array = C(@"c:/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:/"] && /* c: */ (array = C(@"c:").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:"] && /* foo\bar */ (array = C(@"foo\\bar").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && /* foo\bar/baz/ */ (array = C(@"foo\\bar/baz/").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && [[array objectAtIndex: 2] isEqual: @"baz"] && /* foo\/ */ (array = C(@"foo\\/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"foo"] && /* \\foo\bar */ (array = C(@"\\\\foo\\bar").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"\\\\"] && [[array objectAtIndex: 1] isEqual: @"foo"] && [[array objectAtIndex: 2] isEqual: @"bar"] && C(@"").pathComponents.count == 0) # elif defined(OF_MSDOS) TEST(@"-[pathComponents]", /* c:/tmp */ (array = C(@"c:/tmp").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"c:/"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* c:\tmp\ */ (array = C(@"c:\\tmp\\").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"c:\\"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* c:\ */ (array = C(@"c:\\").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:\\"] && /* c:/ */ (array = C(@"c:/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:/"] && /* c: */ (array = C(@"c:").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:"] && /* foo\bar */ (array = C(@"foo\\bar").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && /* foo\bar/baz/ */ (array = C(@"foo\\bar/baz/").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && [[array objectAtIndex: 2] isEqual: @"baz"] && /* foo\/ */ (array = C(@"foo\\/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"foo"] && C(@"").pathComponents.count == 0) # elif defined(OF_AMIGAOS) TEST(@"-[pathComponents]", /* dh0:tmp */ (array = C(@"dh0:tmp").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"dh0:"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* dh0:tmp/ */ (array = C(@"dh0:tmp/").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"dh0:"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* dh0: */ (array = C(@"dh0:/").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"dh0:"] && [[array objectAtIndex: 1] isEqual: @"/"] && /* foo/bar */ (array = C(@"foo/bar").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && /* foo/bar/baz/ */ (array = C(@"foo/bar/baz/").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && [[array objectAtIndex: 2] isEqual: @"baz"] && /* foo// */ (array = C(@"foo//").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"/"] && C(@"").pathComponents.count == 0) # elif defined(OF_NINTENDO_3DS) || defined(OF_WII) TEST(@"-[pathComponents]", /* sdmc:/tmp */ (array = C(@"sdmc:/tmp").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"sdmc:"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* sdmc:/ */ (array = C(@"sdmc:/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"sdmc:"] && /* foo/bar */ (array = C(@"foo/bar").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && /* foo/bar/baz/ */ (array = C(@"foo/bar/baz/").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && [[array objectAtIndex: 2] isEqual: @"baz"] && /* foo// */ (array = C(@"foo//").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"foo"] && C(@"").pathComponents.count == 0) # else TEST(@"-[pathComponents]", /* /tmp */ (array = C(@"/tmp").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"/"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* /tmp/ */ (array = C(@"/tmp/").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"/"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* / */ (array = C(@"/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"/"] && /* foo/bar */ (array = C(@"foo/bar").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && /* foo/bar/baz/ */ (array = C(@"foo/bar/baz/").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && [[array objectAtIndex: 2] isEqual: @"baz"] && /* foo// */ (array = C(@"foo//").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"foo"] && C(@"").pathComponents.count == 0) # endif # if defined(OF_WINDOWS) TEST(@"-[lastPathComponent]", [C(@"c:/tmp").lastPathComponent isEqual: @"tmp"] && [C(@"c:\\tmp\\").lastPathComponent isEqual: @"tmp"] && |
︙ | ︙ | |||
1181 1182 1183 1184 1185 1186 1187 | EXPECT_EXCEPTION(@"Detect out of range in -[unsignedLongLongValue]", OFOutOfRangeException, [C(@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF") unsignedLongLongValueWithBase: 16]) | | | | > | | > | | > | | > | | 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 | EXPECT_EXCEPTION(@"Detect out of range in -[unsignedLongLongValue]", OFOutOfRangeException, [C(@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF") unsignedLongLongValueWithBase: 16]) TEST(@"-[characters]", (characters = C(@"fööbär🀺").characters) && !memcmp(characters, unicharString + 1, sizeof(unicharString) - 8)) #ifdef OF_BIG_ENDIAN # define SWAPPED_BYTE_ORDER OFByteOrderLittleEndian #else # define SWAPPED_BYTE_ORDER OFByteOrderBigEndian #endif TEST(@"-[UTF16String]", (UTF16Characters = C(@"fööbär🀺").UTF16String) && !memcmp(UTF16Characters, UTF16String + 1, OFUTF16StringLength(UTF16String) * 2) && (UTF16Characters = [C(@"fööbär🀺") UTF16StringWithByteOrder: SWAPPED_BYTE_ORDER]) && !memcmp(UTF16Characters, swappedUTF16String + 1, OFUTF16StringLength(swappedUTF16String) * 2)) TEST(@"-[UTF16StringLength]", C(@"fööbär🀺").UTF16StringLength == 8) TEST(@"-[UTF32String]", (characters = C(@"fööbär🀺").UTF32String) && !memcmp(characters, unicharString + 1, OFUTF32StringLength(unicharString) * 4) && (characters = [C(@"fööbär🀺") UTF32StringWithByteOrder: SWAPPED_BYTE_ORDER]) && !memcmp(characters, swappedUnicharString + 1, OFUTF32StringLength(swappedUnicharString) * 4)) #undef SWAPPED_BYTE_ORDER TEST(@"-[stringByMD5Hashing]", [C(@"asdfoobar").stringByMD5Hashing isEqual: @"184dce2ec49b5422c7cfd8728864db4c"]) TEST(@"-[stringByRIPEMD160Hashing]", [C(@"asdfoobar").stringByRIPEMD160Hashing |
︙ | ︙ | |||
1231 1232 1233 1234 1235 1236 1237 | @"279e5addf8be854044bca0cece073fce28eec7d9"]) TEST(@"-[stringBySHA512Hashing]", [C(@"asdfoobar").stringBySHA512Hashing isEqual: @"0464c427da158b02161bb44a3090bbfc594611ef6a53603640454b56" @"412a9247c3579a329e53a5dc74676b106755e3394f9454a2d4227324" @"2615d32f80437d61"]) | > | | > | | | > | | | | | | | | > > | | | | | > | | | | | | | | | | | | | | > | > | | > | | | > | | | | | | | | > | | | > | | > > | | | > | | > > | | > > | | > | | | | 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 | @"279e5addf8be854044bca0cece073fce28eec7d9"]) TEST(@"-[stringBySHA512Hashing]", [C(@"asdfoobar").stringBySHA512Hashing isEqual: @"0464c427da158b02161bb44a3090bbfc594611ef6a53603640454b56" @"412a9247c3579a329e53a5dc74676b106755e3394f9454a2d4227324" @"2615d32f80437d61"]) characterSet = [OFCharacterSet characterSetWithCharactersInString: @"abfo'_~$🍏"]; TEST(@"-[stringByURLEncodingWithAllowedCharacters:]", [[C(@"foo\"ba'_~$]🍏🍌") stringByURLEncodingWithAllowedCharacters: characterSet] isEqual: @"foo%22ba'_~$%5D🍏%F0%9F%8D%8C"]) TEST(@"-[stringByURLDecoding]", [C(@"foo%20bar%22+%24%F0%9F%8D%8C").stringByURLDecoding isEqual: @"foo bar\"+$🍌"]) TEST(@"-[insertString:atIndex:]", (mutableString1 = [mutableStringClass stringWithString: @"𝄞öööbä€"]) && R([mutableString1 insertString: @"äöü" atIndex: 3]) && [mutableString1 isEqual: @"𝄞ööäöüöbä€"]) EXPECT_EXCEPTION(@"Detect invalid format in -[stringByURLDecoding] " @"#1", OFInvalidFormatException, [C(@"foo%xbar") stringByURLDecoding]) EXPECT_EXCEPTION(@"Detect invalid encoding in -[stringByURLDecoding] " @"#2", OFInvalidEncodingException, [C(@"foo%FFbar") stringByURLDecoding]) TEST(@"-[setCharacter:atIndex:]", (mutableString1 = [mutableStringClass stringWithString: @"abäde"]) && R([mutableString1 setCharacter: 0xF6 atIndex: 2]) && [mutableString1 isEqual: @"aböde"] && R([mutableString1 setCharacter: 'c' atIndex: 2]) && [mutableString1 isEqual: @"abcde"] && R([mutableString1 setCharacter: 0x20AC atIndex: 3]) && [mutableString1 isEqual: @"abc€e"] && R([mutableString1 setCharacter: 'x' atIndex: 1]) && [mutableString1 isEqual: @"axc€e"]) TEST(@"-[deleteCharactersInRange:]", (mutableString1 = [mutableStringClass stringWithString: @"𝄞öööbä€"]) && R([mutableString1 deleteCharactersInRange: OFRangeMake(1, 3)]) && [mutableString1 isEqual: @"𝄞bä€"] && R([mutableString1 deleteCharactersInRange: OFRangeMake(0, 4)]) && [mutableString1 isEqual: @""]) TEST(@"-[replaceCharactersInRange:withString:]", (mutableString1 = [mutableStringClass stringWithString: @"𝄞öööbä€"]) && R([mutableString1 replaceCharactersInRange: OFRangeMake(1, 3) withString: @"äöüß"]) && [mutableString1 isEqual: @"𝄞äöüßbä€"] && R([mutableString1 replaceCharactersInRange: OFRangeMake(4, 2) withString: @"b"]) && [mutableString1 isEqual: @"𝄞äöübä€"] && R([mutableString1 replaceCharactersInRange: OFRangeMake(0, 7) withString: @""]) && [mutableString1 isEqual: @""]) EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #1", OFOutOfRangeException, { mutableString1 = [mutableStringClass stringWithString: @"𝄞öö"]; [mutableString1 deleteCharactersInRange: OFRangeMake(2, 2)]; }) EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #2", OFOutOfRangeException, [mutableString1 deleteCharactersInRange: OFRangeMake(4, 0)]) EXPECT_EXCEPTION(@"Detect OoR in " @"-[replaceCharactersInRange:withString:] #1", OFOutOfRangeException, [mutableString1 replaceCharactersInRange: OFRangeMake(2, 2) withString: @""]) EXPECT_EXCEPTION(@"Detect OoR in " @"-[replaceCharactersInRange:withString:] #2", OFOutOfRangeException, [mutableString1 replaceCharactersInRange: OFRangeMake(4, 0) withString: @""]) TEST(@"-[replaceOccurrencesOfString:withString:]", (mutableString1 = [mutableStringClass stringWithString: @"asd fo asd fofo asd"]) && R([mutableString1 replaceOccurrencesOfString: @"fo" withString: @"foo"]) && [mutableString1 isEqual: @"asd foo asd foofoo asd"] && (mutableString1 = [mutableStringClass stringWithString: @"XX"]) && R([mutableString1 replaceOccurrencesOfString: @"X" withString: @"XX"]) && [mutableString1 isEqual: @"XXXX"]) TEST(@"-[replaceOccurrencesOfString:withString:options:range:]", (mutableString1 = [mutableStringClass stringWithString: @"foofoobarfoobarfoo"]) && R([mutableString1 replaceOccurrencesOfString: @"oo" withString: @"óò" options: 0 range: OFRangeMake(2, 15)]) && [mutableString1 isEqual: @"foofóòbarfóòbarfoo"]) TEST(@"-[deleteLeadingWhitespaces]", (mutableString1 = [mutableStringClass stringWithString: whitespace[0]]) && R([mutableString1 deleteLeadingWhitespaces]) && [mutableString1 isEqual: @"asd \t \t\t\r\n"] && (mutableString1 = [mutableStringClass stringWithString: whitespace[1]]) && R([mutableString1 deleteLeadingWhitespaces]) && [mutableString1 isEqual: @""]) TEST(@"-[deleteTrailingWhitespaces]", (mutableString1 = [mutableStringClass stringWithString: whitespace[0]]) && R([mutableString1 deleteTrailingWhitespaces]) && [mutableString1 isEqual: @" \r \t\n\t \tasd"] && (mutableString1 = [mutableStringClass stringWithString: whitespace[1]]) && R([mutableString1 deleteTrailingWhitespaces]) && [mutableString1 isEqual: @""]) TEST(@"-[deleteEnclosingWhitespaces]", (mutableString1 = [mutableStringClass stringWithString: whitespace[0]]) && R([mutableString1 deleteEnclosingWhitespaces]) && [mutableString1 isEqual: @"asd"] && (mutableString1 = [mutableStringClass stringWithString: whitespace[1]]) && R([mutableString1 deleteEnclosingWhitespaces]) && [mutableString1 isEqual: @""]) #ifdef OF_HAVE_UNICODE_TABLES TEST(@"-[decomposedStringWithCanonicalMapping]", [C(@"H\xC3\xA4llj\xC3\xB6").decomposedStringWithCanonicalMapping isEqual: @"H\x61\xCC\x88llj\x6F\xCC\x88"]); TEST(@"-[decomposedStringWithCompatibilityMapping]", [C(@"H\xC3\xA4llj\xC3\xB6").decomposedStringWithCompatibilityMapping isEqual: @"H\x61\xCC\x88llj\x6F\xCC\x88"]); #endif TEST(@"-[stringByXMLEscaping]", (string = C(@"<hello> &world'\"!&").stringByXMLEscaping) && [string isEqual: @"<hello> &world'"!&"]) TEST(@"-[stringByXMLUnescaping]", [string.stringByXMLUnescaping isEqual: @"<hello> &world'\"!&"] && [C(@"y").stringByXMLUnescaping isEqual: @"y"] && [C(@"ä").stringByXMLUnescaping isEqual: @"ä"] && [C(@"€").stringByXMLUnescaping isEqual: @"€"] && [C(@"𝄞").stringByXMLUnescaping isEqual: @"𝄞"]) EXPECT_EXCEPTION(@"Detect unknown entities in -[stringByXMLUnescaping]", OFUnknownXMLEntityException, [C(@"&foo;") stringByXMLUnescaping]) |
︙ | ︙ | |||
1377 1378 1379 1380 1381 1382 1383 | EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] " @"#4", OFInvalidFormatException, [C(@"&#g;") stringByXMLUnescaping]) EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] " @"#5", OFInvalidFormatException, [C(@"&#xg;") stringByXMLUnescaping]) TEST(@"-[stringByXMLUnescapingWithDelegate:]", | | | | | 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 | EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] " @"#4", OFInvalidFormatException, [C(@"&#g;") stringByXMLUnescaping]) EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] " @"#5", OFInvalidFormatException, [C(@"&#xg;") stringByXMLUnescaping]) TEST(@"-[stringByXMLUnescapingWithDelegate:]", (entityHandler = [[[EntityHandler alloc] init] autorelease]) && [[C(@"x&foo;y") stringByXMLUnescapingWithDelegate: entityHandler] isEqual: @"xbary"]) #ifdef OF_HAVE_BLOCKS TEST(@"-[stringByXMLUnescapingWithBlock:]", [[C(@"x&foo;y") stringByXMLUnescapingWithBlock: ^ OFString *(OFString *str, OFString *entity) { if ([entity isEqual: @"foo"]) return @"bar"; return nil; }] isEqual: @"xbary"]) j = 0; |
︙ | ︙ |