add tests for abbreviation of home directory with tilde

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36429 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-03-25 14:14:04 +00:00
parent acf7b640fc
commit 15f378e72a

View file

@ -0,0 +1,53 @@
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSString.h>
int main()
{
START_SET("tilde")
NSString *home = NSHomeDirectory();
NSString *tmp;
PASS_EQUAL([home stringByAbbreviatingWithTildeInPath], @"~",
"home directory becomes tilde");
tmp = [home stringByAppendingPathComponent: @"Documents"];
PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents",
"the Documents subdirectory becomes ~/Documents");
tmp = [home stringByAppendingString: @"/Documents"];
PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents",
"trailing slash removed");
tmp = [home stringByAppendingString: @"//Documents///"];
PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents",
"multiple slashes removed");
tmp = [home stringByAppendingString: @"/Documents//.."];
PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents/..",
"upper directory reference retained");
tmp = [home stringByAppendingString: @"/Documents/./.."];
PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents/./..",
"dot directory reference retained");
tmp = NSHomeDirectoryForUser(@"root");
PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], tmp,
"tilde does nothing for root's home");
tmp = [NSString stringWithFormat: @"////%@//Documents///", home];
PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents",
"multiple slashes removed");
PASS_EQUAL([@"//////Documents///" stringByAbbreviatingWithTildeInPath],
@"/Documents",
"multiple slashes removed without tilde replacement");
PASS_EQUAL([@".//////Documents///" stringByAbbreviatingWithTildeInPath],
@"./Documents",
"multiple slashes removed without tilde replacement");
END_SET("tilde")
return 0;
}