ObjFW  Diff

Differences From Artifact [0e68977055]:

To Artifact [979ff3e546]:

  • File tests/OFStringTests.m — part of check-in [7a488c3062] at 2018-03-11 00:37:56 on branch trunk — OFString: Move path handling into a category

    This is the first step to have different versions of those for different
    operating systems, rather than #ifdefs everywhere.

    This also has the nice side-effect of not having one implementation in
    OFString and another one in OFString_UTF8 anymore. The one in OFString
    was a generic version, while the one in OFString_UTF8 was one optimized
    for UTF-8 strings. Now only the version optimized for UTF-8 strings
    exists, as this is by far the most common string implementation used,
    and the overhead of converting from something else to UTF-8 is not more
    than converting to UTF-32. (user: js, size: 36099) [annotate] [blame] [check-ins using]


547
548
549
550
551
552
553

554
555
556
557
558
559
560
561
562
563

564
565
566
567
568
569
570

	TEST(@"-[stringByAppendingString:]",
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])


	s[0] = [mutableStringClass stringWithString: @"foo"];
	[s[0] appendString: OF_PATH_DELIMITER_STRING];
	[s[0] appendString: @"bar"];
	s[1] = [mutableStringClass stringWithString: s[0]];
	[s[1] appendString: OF_PATH_DELIMITER_STRING];
	is = [stringClass stringWithString: s[1]];
	[s[1] appendString: @"baz"];
	TEST(@"-[stringByAppendingPathComponent:]",
	    [[s[0] stringByAppendingPathComponent: @"baz"] isEqual: s[1]] &&
	    [[is stringByAppendingPathComponent: @"baz"] isEqual: s[1]])


	s[0] = [mutableStringClass stringWithString: @"foo"];
	[s[0] appendString: @"/"];
	[s[0] appendString: @"bar"];
	s[1] = [mutableStringClass stringWithString: s[0]];
	[s[1] appendString: @"/"];
	is = [stringClass stringWithString: s[1]];







>










>







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

	TEST(@"-[stringByAppendingString:]",
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])

#ifdef OF_HAVE_FILES
	s[0] = [mutableStringClass stringWithString: @"foo"];
	[s[0] appendString: OF_PATH_DELIMITER_STRING];
	[s[0] appendString: @"bar"];
	s[1] = [mutableStringClass stringWithString: s[0]];
	[s[1] appendString: OF_PATH_DELIMITER_STRING];
	is = [stringClass stringWithString: s[1]];
	[s[1] appendString: @"baz"];
	TEST(@"-[stringByAppendingPathComponent:]",
	    [[s[0] stringByAppendingPathComponent: @"baz"] isEqual: s[1]] &&
	    [[is stringByAppendingPathComponent: @"baz"] isEqual: s[1]])
#endif

	s[0] = [mutableStringClass stringWithString: @"foo"];
	[s[0] appendString: @"/"];
	[s[0] appendString: @"bar"];
	s[1] = [mutableStringClass stringWithString: s[0]];
	[s[1] appendString: @"/"];
	is = [stringClass stringWithString: s[1]];
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
	    componentsSeparatedByString: @"XX"
				options: OF_STRING_SKIP_EMPTY]) &&
	    [a count] == 3 &&
	    [[a objectAtIndex: i++] isEqual: @"foo"] &&
	    [[a objectAtIndex: i++] isEqual: @"bar"] &&
	    [[a objectAtIndex: i++] isEqual: @"baz"])


#if !defined(OF_WINDOWS) && !defined(OF_MSDOS)
# define EXPECTED @"foo/bar/baz"
#else
# define EXPECTED @"foo\\bar\\baz"
#endif
	TEST(@"+[pathWithComponents:]",
	    (is = [stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", @"bar", @"baz", nil]]) &&
	    [is isEqual: EXPECTED] &&
	    (is = [stringClass pathWithComponents:
	    [OFArray arrayWithObjects: @"foo", nil]]) &&
	    [is isEqual: @"foo"])
#undef EXPECTED

	TEST(@"-[pathComponents]",
	    /* /tmp */
	    (a = [C(@"/tmp") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @""] &&
	    [[a objectAtIndex: 1] isEqual: @"tmp"] &&
	    /* /tmp/ */







>
|
|
|
|
|







|







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
	    componentsSeparatedByString: @"XX"
				options: OF_STRING_SKIP_EMPTY]) &&
	    [a count] == 3 &&
	    [[a objectAtIndex: i++] isEqual: @"foo"] &&
	    [[a objectAtIndex: i++] isEqual: @"bar"] &&
	    [[a objectAtIndex: i++] isEqual: @"baz"])

#ifdef OF_HAVE_FILES
# if !defined(OF_WINDOWS) && !defined(OF_MSDOS)
#  define EXPECTED @"foo/bar/baz"
# else
#  define EXPECTED @"foo\\bar\\baz"
# endif
	TEST(@"+[pathWithComponents:]",
	    (is = [stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", @"bar", @"baz", nil]]) &&
	    [is isEqual: EXPECTED] &&
	    (is = [stringClass pathWithComponents:
	    [OFArray arrayWithObjects: @"foo", nil]]) &&
	    [is isEqual: @"foo"])
# undef EXPECTED

	TEST(@"-[pathComponents]",
	    /* /tmp */
	    (a = [C(@"/tmp") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @""] &&
	    [[a objectAtIndex: 1] isEqual: @"tmp"] &&
	    /* /tmp/ */
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
	    [[C(@"/tmp/foo/") stringByDeletingLastPathComponent]
	    isEqual: @"/tmp"] &&
	    [[C(@"foo/bar") stringByDeletingLastPathComponent]
	    isEqual: @"foo"] &&
	    [[C(@"/") stringByDeletingLastPathComponent] isEqual: @"/"] &&
	    [[C(@"foo") stringByDeletingLastPathComponent] isEqual: @"."])

#if !defined(OF_WINDOWS) && !defined(OF_MSDOS)
# define EXPECTED @"/foo./bar"
#else
# define EXPECTED @"\\foo.\\bar"
#endif
	TEST(@"-[stringByDeletingPathExtension]",
	    [[C(@"foo.bar") stringByDeletingPathExtension] isEqual: @"foo"] &&
	    [[C(@"foo..bar") stringByDeletingPathExtension] isEqual: @"foo."] &&
	    [[C(@"/foo./bar") stringByDeletingPathExtension]
	    isEqual: @"/foo./bar"] &&
	    [[C(@"/foo./bar.baz") stringByDeletingPathExtension]
	    isEqual: EXPECTED] &&
	    [[C(@"foo.bar/") stringByDeletingPathExtension] isEqual: @"foo"] &&
	    [[C(@".foo") stringByDeletingPathExtension] isEqual: @".foo"] &&
	    [[C(@".foo.bar") stringByDeletingPathExtension] isEqual: @".foo"])
#undef EXPECTED


	TEST(@"-[decimalValue]",
	    [C(@"1234") decimalValue] == 1234 &&
	    [C(@"\r\n+123  ") decimalValue] == 123 &&
	    [C(@"-500\t") decimalValue] == -500 &&
	    [C(@"\t\t\r\n") decimalValue] == 0)








|
|
|
|
|










|
>







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
	    [[C(@"/tmp/foo/") stringByDeletingLastPathComponent]
	    isEqual: @"/tmp"] &&
	    [[C(@"foo/bar") stringByDeletingLastPathComponent]
	    isEqual: @"foo"] &&
	    [[C(@"/") stringByDeletingLastPathComponent] isEqual: @"/"] &&
	    [[C(@"foo") stringByDeletingLastPathComponent] isEqual: @"."])

# if !defined(OF_WINDOWS) && !defined(OF_MSDOS)
#  define EXPECTED @"/foo./bar"
# else
#  define EXPECTED @"\\foo.\\bar"
# endif
	TEST(@"-[stringByDeletingPathExtension]",
	    [[C(@"foo.bar") stringByDeletingPathExtension] isEqual: @"foo"] &&
	    [[C(@"foo..bar") stringByDeletingPathExtension] isEqual: @"foo."] &&
	    [[C(@"/foo./bar") stringByDeletingPathExtension]
	    isEqual: @"/foo./bar"] &&
	    [[C(@"/foo./bar.baz") stringByDeletingPathExtension]
	    isEqual: EXPECTED] &&
	    [[C(@"foo.bar/") stringByDeletingPathExtension] isEqual: @"foo"] &&
	    [[C(@".foo") stringByDeletingPathExtension] isEqual: @".foo"] &&
	    [[C(@".foo.bar") stringByDeletingPathExtension] isEqual: @".foo"])
# undef EXPECTED
#endif

	TEST(@"-[decimalValue]",
	    [C(@"1234") decimalValue] == 1234 &&
	    [C(@"\r\n+123  ") decimalValue] == 123 &&
	    [C(@"-500\t") decimalValue] == -500 &&
	    [C(@"\t\t\r\n") decimalValue] == 0)