Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -135,11 +135,10 @@ 4BF33AFC133807A20059CEF7 /* OFArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF66E1235358D0076B512 /* OFArrayTests.m */; }; 4BF33AFD133807A20059CEF7 /* OFBlockTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE5F0E412DF4259005C7A0C /* OFBlockTests.m */; }; 4BF33AFE133807A20059CEF7 /* OFDataArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF66F1235358D0076B512 /* OFDataArrayTests.m */; }; 4BF33AFF133807A20059CEF7 /* OFDateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE5F0E512DF4259005C7A0C /* OFDateTests.m */; }; 4BF33B00133807A20059CEF7 /* OFDictionaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF6701235358D0076B512 /* OFDictionaryTests.m */; }; - 4BF33B01133807A20059CEF7 /* OFFileTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF6711235358D0076B512 /* OFFileTests.m */; }; 4BF33B02133807A20059CEF7 /* OFHTTPRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3D23701337FB7500DD29B8 /* OFHTTPRequestTests.m */; }; 4BF33B03133807A20059CEF7 /* OFListTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF6721235358D0076B512 /* OFListTests.m */; }; 4BF33B04133807A20059CEF7 /* OFMD5HashTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF6731235358D0076B512 /* OFMD5HashTests.m */; }; 4BF33B05133807A20059CEF7 /* OFNumberTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF6741235358D0076B512 /* OFNumberTests.m */; }; 4BF33B06133807A20059CEF7 /* OFObjectTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF6751235358D0076B512 /* OFObjectTests.m */; }; @@ -228,10 +227,12 @@ 4B0108CA10EB8C9300631877 /* OFEnumerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFEnumerator.m; path = src/OFEnumerator.m; sourceTree = ""; }; 4B0D249411DFAA3D00ED6FFC /* OFXMLElementBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLElementBuilder.h; path = src/OFXMLElementBuilder.h; sourceTree = ""; }; 4B0D249511DFAA3D00ED6FFC /* OFXMLElementBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLElementBuilder.m; path = src/OFXMLElementBuilder.m; sourceTree = ""; }; 4B175C1D116D130B003C99CB /* OFApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFApplication.h; path = src/OFApplication.h; sourceTree = ""; }; 4B175C1E116D130B003C99CB /* OFApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFApplication.m; path = src/OFApplication.m; sourceTree = ""; }; + 4B19023A1338D6A2000374C9 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = Makefile; path = src/Makefile; sourceTree = SOURCE_ROOT; }; + 4B19023D1338D6D5000374C9 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = Makefile; path = tests/Makefile; sourceTree = ""; }; 4B23CA8A133811610047A1D9 /* TestPlugin.impl */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = TestPlugin.impl; sourceTree = BUILT_PRODUCTS_DIR; }; 4B3D236D1337FB5800DD29B8 /* base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = base64.h; path = src/base64.h; sourceTree = ""; }; 4B3D236E1337FB5800DD29B8 /* base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = base64.m; path = src/base64.m; sourceTree = ""; }; 4B3D23701337FB7500DD29B8 /* OFHTTPRequestTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFHTTPRequestTests.m; path = tests/OFHTTPRequestTests.m; sourceTree = ""; }; 4B3D23761337FBC800DD29B8 /* ObjFW.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ObjFW.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -287,11 +288,10 @@ 4B6AF97210A8D42E0003FB0A /* windows_1252.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = windows_1252.m; path = src/windows_1252.m; sourceTree = ""; }; 4B6AF97310A8D4450003FB0A /* ObjFW.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjFW.h; path = src/ObjFW.h; sourceTree = ""; }; 4B6EF66E1235358D0076B512 /* OFArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFArrayTests.m; path = tests/OFArrayTests.m; sourceTree = SOURCE_ROOT; }; 4B6EF66F1235358D0076B512 /* OFDataArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFDataArrayTests.m; path = tests/OFDataArrayTests.m; sourceTree = SOURCE_ROOT; }; 4B6EF6701235358D0076B512 /* OFDictionaryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFDictionaryTests.m; path = tests/OFDictionaryTests.m; sourceTree = SOURCE_ROOT; }; - 4B6EF6711235358D0076B512 /* OFFileTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFFileTests.m; path = tests/OFFileTests.m; sourceTree = SOURCE_ROOT; }; 4B6EF6721235358D0076B512 /* OFListTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFListTests.m; path = tests/OFListTests.m; sourceTree = SOURCE_ROOT; }; 4B6EF6731235358D0076B512 /* OFMD5HashTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMD5HashTests.m; path = tests/OFMD5HashTests.m; sourceTree = SOURCE_ROOT; }; 4B6EF6741235358D0076B512 /* OFNumberTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFNumberTests.m; path = tests/OFNumberTests.m; sourceTree = SOURCE_ROOT; }; 4B6EF6751235358D0076B512 /* OFObjectTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFObjectTests.m; path = tests/OFObjectTests.m; sourceTree = SOURCE_ROOT; }; 4B6EF6761235358D0076B512 /* OFPluginTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFPluginTests.m; path = tests/OFPluginTests.m; sourceTree = SOURCE_ROOT; }; @@ -407,10 +407,11 @@ }; 4B3D23801337FBC800DD29B8 /* Supporting Files */ = { isa = PBXGroup; children = ( 4B3D23BB1337FC5800DD29B8 /* Info.plist */, + 4B19023A1338D6A2000374C9 /* Makefile */, 4BDF37B41338055600F9A81A /* config.h */, 4B3D23EF1338008000DD29B8 /* mach_alias_list */, 4BD98C011338140B0048DD5B /* objfw-defs.h */, ); name = "Supporting Files"; @@ -531,11 +532,10 @@ 4B6EF66E1235358D0076B512 /* OFArrayTests.m */, 4BE5F0E412DF4259005C7A0C /* OFBlockTests.m */, 4B6EF66F1235358D0076B512 /* OFDataArrayTests.m */, 4BE5F0E512DF4259005C7A0C /* OFDateTests.m */, 4B6EF6701235358D0076B512 /* OFDictionaryTests.m */, - 4B6EF6711235358D0076B512 /* OFFileTests.m */, 4B3D23701337FB7500DD29B8 /* OFHTTPRequestTests.m */, 4B6EF6721235358D0076B512 /* OFListTests.m */, 4B6EF6731235358D0076B512 /* OFMD5HashTests.m */, 4B6EF6741235358D0076B512 /* OFNumberTests.m */, 4B6EF6751235358D0076B512 /* OFObjectTests.m */, @@ -581,10 +581,11 @@ sourceTree = ""; }; 4BF33B4113380CB60059CEF7 /* Supporting Files */ = { isa = PBXGroup; children = ( + 4B19023D1338D6D5000374C9 /* Makefile */, 4BF33B4213380CD40059CEF7 /* testfile.bin */, 4BF33B4313380CD40059CEF7 /* testfile.txt */, ); name = "Supporting Files"; sourceTree = ""; @@ -857,11 +858,10 @@ 4BF33AFC133807A20059CEF7 /* OFArrayTests.m in Sources */, 4BF33AFD133807A20059CEF7 /* OFBlockTests.m in Sources */, 4BF33AFE133807A20059CEF7 /* OFDataArrayTests.m in Sources */, 4BF33AFF133807A20059CEF7 /* OFDateTests.m in Sources */, 4BF33B00133807A20059CEF7 /* OFDictionaryTests.m in Sources */, - 4BF33B01133807A20059CEF7 /* OFFileTests.m in Sources */, 4BF33B02133807A20059CEF7 /* OFHTTPRequestTests.m in Sources */, 4BF33B03133807A20059CEF7 /* OFListTests.m in Sources */, 4BF33B04133807A20059CEF7 /* OFMD5HashTests.m in Sources */, 4BF33B05133807A20059CEF7 /* OFNumberTests.m in Sources */, 4BF33B06133807A20059CEF7 /* OFObjectTests.m in Sources */, Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -52,28 +52,10 @@ * It is not closed when the OFFile object is deallocated! * \return A new autoreleased OFFile */ + fileWithFileDescriptor: (int)fd; -/** - * \param path The path for which the components should be returned - * \return The components of the path - */ -+ (OFArray*)componentsOfPath: (OFString*)path; - -/** - * \param path The path for which the last component should be returned - * \return The last component of the path - */ -+ (OFString*)lastComponentOfPath: (OFString*)path; - -/** - * \param path The path for which the directory name should be returned - * \return The directory name of the path - */ -+ (OFString*)directoryNameOfPath: (OFString*)path; - /** * \param path The path to check * \return A boolean whether there is a file at the specified path */ + (BOOL)fileExistsAtPath: (OFString*)path; Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -113,11 +113,11 @@ OFString *date_str, *me, *msg; va_list args; date = [OFDate date]; date_str = [date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; - me = [OFFile lastComponentOfPath: [OFApplication programName]]; + me = [[OFApplication programName] lastPathComponent]; va_start(args, fmt); msg = [[[OFString alloc] initWithFormat: fmt arguments: args] autorelease]; va_end(args); @@ -132,13 +132,10 @@ @end @implementation OFFile + (void)load { - if (self != [OFFile class]) - return; - of_stdin = [[OFFileSingleton alloc] initWithFileDescriptor: 0]; of_stdout = [[OFFileSingleton alloc] initWithFileDescriptor: 1]; of_stderr = [[OFFileSingleton alloc] initWithFileDescriptor: 2]; } @@ -160,137 +157,10 @@ + fileWithFileDescriptor: (int)fd_ { return [[[self alloc] initWithFileDescriptor: fd_] autorelease]; } -+ (OFArray*)componentsOfPath: (OFString*)path -{ - OFMutableArray *ret; - OFAutoreleasePool *pool; - const char *path_c = [path cString]; - size_t path_len = [path cStringLength]; - size_t i, last = 0; - - ret = [OFMutableArray array]; - - if (path_len == 0) - return ret; - - pool = [[OFAutoreleasePool alloc] init]; - -#ifndef _WIN32 - if (path_c[path_len - 1] == OF_PATH_DELIM) -#else - if (path_c[path_len - 1] == '/' || path_c[path_len - 1] == '\\') -#endif - path_len--; - - for (i = 0; i < path_len; i++) { -#ifndef _WIN32 - if (path_c[i] == OF_PATH_DELIM) { -#else - if (path_c[i] == '/' || path_c[i] == '\\') { -#endif - [ret addObject: - [OFString stringWithCString: path_c + last - length: i - last]]; - last = i + 1; - } - } - - [ret addObject: [OFString stringWithCString: path_c + last - length: i - last]]; - - [pool release]; - - /* - * Class swizzle the array to be immutable. We declared the return type - * to be OFArray*, so it can't be modified anyway. But not swizzling it - * would create a real copy each time -[copy] is called. - */ - ret->isa = [OFArray class]; - return ret; -} - -+ (OFString*)lastComponentOfPath: (OFString*)path -{ - const char *path_c = [path cString]; - size_t path_len = [path cStringLength]; - ssize_t i; - - if (path_len == 0) - return @""; - -#ifndef _WIN32 - if (path_c[path_len - 1] == OF_PATH_DELIM) -#else - if (path_c[path_len - 1] == '/' || path_c[path_len - 1] == '\\') -#endif - path_len--; - - for (i = path_len - 1; i >= 0; i--) { -#ifndef _WIN32 - if (path_c[i] == OF_PATH_DELIM) { -#else - if (path_c[i] == '/' || path_c[i] == '\\') { -#endif - i++; - break; - } - } - - /* - * Only one component, but the trailing delimiter might have been - * removed, so return a new string anyway. - */ - if (i < 0) - i = 0; - - return [OFString stringWithCString: path_c + i - length: path_len - i]; -} - -+ (OFString*)directoryNameOfPath: (OFString*)path -{ - const char *path_c = [path cString]; - size_t path_len = [path cStringLength]; - size_t i; - - if (path_len == 0) - return @""; - -#ifndef _WIN32 - if (path_c[path_len - 1] == OF_PATH_DELIM) -#else - if (path_c[path_len - 1] == '/' || path_c[path_len - 1] == '\\') -#endif - path_len--; - - if (path_len == 0) - return [OFString stringWithCString: path_c - length: 1]; - - for (i = path_len - 1; i >= 1; i--) -#ifndef _WIN32 - if (path_c[i] == OF_PATH_DELIM) -#else - if (path_c[i] == '/' || path_c[i] == '\\') -#endif - return [OFString stringWithCString: path_c - length: i]; - -#ifndef _WIN32 - if (path_c[0] == OF_PATH_DELIM) -#else - if (path_c[i] == '/' || path_c[i] == '\\') -#endif - return [OFString stringWithCString: path_c - length: 1]; - - return @"."; -} - + (BOOL)fileExistsAtPath: (OFString*)path { struct stat s; if (stat([path cString], &s) == -1) @@ -518,11 +388,11 @@ OFFile *src; OFFile *dest; char buf[4096]; if ([self directoryExistsAtPath: to]) { - OFString *filename = [self lastComponentOfPath: from]; + OFString *filename = [from lastPathComponent]; to = [OFString stringWithPath: to, filename, nil]; } override = [self fileExistsAtPath: to]; @@ -560,11 +430,11 @@ + (void)renameFileAtPath: (OFString*)from toPath: (OFString*)to { if ([self directoryExistsAtPath: to]) { - OFString *filename = [self lastComponentOfPath: from]; + OFString *filename = [from lastPathComponent]; to = [OFString stringWithPath: to, filename, nil]; } #ifndef _WIN32 if (rename([from cString], [to cString])) @@ -597,11 +467,11 @@ #ifndef _WIN32 + (void)linkFileAtPath: (OFString*)src toPath: (OFString*)dest { if ([self directoryExistsAtPath: dest]) { - OFString *filename = [self lastComponentOfPath: src]; + OFString *filename = [src lastPathComponent]; dest = [OFString stringWithPath: dest, filename, nil]; } if (link([src cString], [dest cString]) != 0) @throw [OFLinkFailedException newWithClass: self @@ -613,11 +483,11 @@ #if !defined(_WIN32) && !defined(_PSP) + (void)symlinkFileAtPath: (OFString*)src toPath: (OFString*)dest { if ([self directoryExistsAtPath: dest]) { - OFString *filename = [self lastComponentOfPath: src]; + OFString *filename = [src lastPathComponent]; dest = [OFString stringWithPath: dest, filename, nil]; } if (symlink([src cString], [dest cString]) != 0) @throw [OFSymlinkFailedException newWithClass: self Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -397,10 +397,25 @@ * \param delimiter The delimiter for splitting * \return An autoreleased OFArray with the splitted string */ - (OFArray*)componentsSeparatedByString: (OFString*)delimiter; +/** + * \return The components of the path + */ +- (OFArray*)pathComponents; + +/** + * \return The last component of the path + */ +- (OFString*)lastPathComponent; + +/** + * \return The directory name of the path + */ +- (OFString*)stringByDeletingLastPathComponent; + /** * Returns the decimal value of the string as an intmax_t or throws an * OFInvalidEncoding exception if the string contains any non-number characters. * * \return An intmax_t with the value of the string Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1068,10 +1068,132 @@ * would create a real copy each time -[copy] is called. */ array->isa = [OFArray class]; return array; } + +- (OFArray*)pathComponents +{ + OFMutableArray *ret; + OFAutoreleasePool *pool; + size_t i, last = 0, path_len = length; + + ret = [OFMutableArray array]; + + if (path_len == 0) + return ret; + + pool = [[OFAutoreleasePool alloc] init]; + +#ifndef _WIN32 + if (string[path_len - 1] == OF_PATH_DELIM) +#else + if (string[path_len - 1] == '/' || string[path_len - 1] == '\\') +#endif + path_len--; + + for (i = 0; i < path_len; i++) { +#ifndef _WIN32 + if (string[i] == OF_PATH_DELIM) { +#else + if (string[i] == '/' || string[i] == '\\') { +#endif + [ret addObject: + [OFString stringWithCString: string + last + length: i - last]]; + last = i + 1; + } + } + + [ret addObject: [OFString stringWithCString: string + last + length: i - last]]; + + [pool release]; + + /* + * Class swizzle the array to be immutable. We declared the return type + * to be OFArray*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFArray class]; + return ret; +} + +- (OFString*)lastPathComponent +{ + size_t path_len = length; + ssize_t i; + + if (path_len == 0) + return @""; + +#ifndef _WIN32 + if (string[path_len - 1] == OF_PATH_DELIM) +#else + if (string[path_len - 1] == '/' || string[path_len - 1] == '\\') +#endif + path_len--; + + for (i = path_len - 1; i >= 0; i--) { +#ifndef _WIN32 + if (string[i] == OF_PATH_DELIM) { +#else + if (string[i] == '/' || string[i] == '\\') { +#endif + i++; + break; + } + } + + /* + * Only one component, but the trailing delimiter might have been + * removed, so return a new string anyway. + */ + if (i < 0) + i = 0; + + return [OFString stringWithCString: string + i + length: path_len - i]; +} + +- (OFString*)stringByDeletingLastPathComponent; +{ + size_t i, path_len = length; + + if (path_len == 0) + return @""; + +#ifndef _WIN32 + if (string[path_len - 1] == OF_PATH_DELIM) +#else + if (string[path_len - 1] == '/' || string[path_len - 1] == '\\') +#endif + path_len--; + + if (path_len == 0) + return [OFString stringWithCString: string + length: 1]; + + for (i = path_len - 1; i >= 1; i--) +#ifndef _WIN32 + if (string[i] == OF_PATH_DELIM) +#else + if (string[i] == '/' || string[i] == '\\') +#endif + return [OFString stringWithCString: string + length: i]; + +#ifndef _WIN32 + if (string[0] == OF_PATH_DELIM) +#else + if (path_c[i] == '/' || path_c[i] == '\\') +#endif + return [OFString stringWithCString: string + length: 1]; + + return @"."; +} - (intmax_t)decimalValue { int i = 0; intmax_t num = 0; Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -6,11 +6,10 @@ SRCS = OFArrayTests.m \ ${OFBLOCKTESTS_M} \ OFDataArrayTests.m \ OFDateTests.m \ OFDictionaryTests.m \ - OFFileTests.m \ ${OFHTTPREQUESTTESTS_M} \ OFListTests.m \ OFMD5HashTests.m \ OFNumberTests.m \ OFObjectTests.m \ Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -170,20 +170,10 @@ TEST(@"-[appendFormat:]", R(([s[0] appendFormat: @"%02X", 15])) && [s[0] isEqual: @"test:1230F"]) - TEST(@"+[stringWithPath:]", - (s[0] = [OFString stringWithPath: @"foo", @"bar", @"baz", nil]) && -#ifndef _WIN32 - [s[0] isEqual: @"foo/bar/baz"] && -#else - [s[0] isEqual: @"foo\\bar\\baz"] && -#endif - (s[0] = [OFString stringWithPath: @"foo", nil]) && - [s[0] isEqual: @"foo"]) - TEST(@"-[indexOfFirstOccurrenceOfString:]", [@"π„žΓΆΓΆ" indexOfFirstOccurrenceOfString: @"ΓΆΓΆ"] == 1 && [@"π„žΓΆΓΆ" indexOfFirstOccurrenceOfString: @"ΓΆ"] == 1 && [@"π„žΓΆΓΆ" indexOfFirstOccurrenceOfString: @"π„ž"] == 0 && [@"π„žΓΆΓΆ" indexOfFirstOccurrenceOfString: @"x"] == SIZE_MAX) @@ -231,10 +221,64 @@ [[a objectAtIndex: i++] isEqual: @""] && [[a objectAtIndex: i++] isEqual: @"baz"] && [[a objectAtIndex: i++] isEqual: @""] && [[a objectAtIndex: i++] isEqual: @""]) + TEST(@"+[stringWithPath:]", + (s[0] = [OFString stringWithPath: @"foo", @"bar", @"baz", nil]) && +#ifndef _WIN32 + [s[0] isEqual: @"foo/bar/baz"] && +#else + [s[0] isEqual: @"foo\\bar\\baz"] && +#endif + (s[0] = [OFString stringWithPath: @"foo", nil]) && + [s[0] isEqual: @"foo"]) + + TEST(@"-[pathComponents]", + /* /tmp */ + (a = [@"/tmp" pathComponents]) && [a count] == 2 && + [[a objectAtIndex: 0] isEqual: @""] && + [[a objectAtIndex: 1] isEqual: @"tmp"] && + /* /tmp/ */ + (a = [@"/tmp/" pathComponents]) && [a count] == 2 && + [[a objectAtIndex: 0] isEqual: @""] && + [[a objectAtIndex: 1] isEqual: @"tmp"] && + /* / */ + (a = [@"/" pathComponents]) && [a count] == 1 && + [[a objectAtIndex: 0] isEqual: @""] && + /* foo/bar */ + (a = [@"foo/bar" pathComponents]) && [a count] == 2 && + [[a objectAtIndex: 0] isEqual: @"foo"] && + [[a objectAtIndex: 1] isEqual: @"bar"] && + /* foo/bar/baz/ */ + (a = [@"foo/bar/baz" pathComponents]) && [a count] == 3 && + [[a objectAtIndex: 0] isEqual: @"foo"] && + [[a objectAtIndex: 1] isEqual: @"bar"] && + [[a objectAtIndex: 2] isEqual: @"baz"] && + /* foo// */ + (a = [@"foo//" pathComponents]) && [a count] == 2 && + [[a objectAtIndex: 0] isEqual: @"foo"] && + [[a objectAtIndex: 1] isEqual: @""] && + [[@"" pathComponents] count] == 0) + + TEST(@"-[lastPathComponent]", + [[@"/tmp" lastPathComponent] isEqual: @"tmp"] && + [[@"/tmp/" lastPathComponent] isEqual: @"tmp"] && + [[@"/" lastPathComponent] isEqual: @""] && + [[@"foo" lastPathComponent] isEqual: @"foo"] && + [[@"foo/bar" lastPathComponent] isEqual: @"bar"] && + [[@"foo/bar/baz/" lastPathComponent] isEqual: @"baz"]) + + TEST(@"-[stringByDeletingLastPathComponent]", + [[@"/tmp" stringByDeletingLastPathComponent] isEqual: @"/"] && + [[@"/tmp/" stringByDeletingLastPathComponent] isEqual: @"/"] && + [[@"/tmp/foo/" stringByDeletingLastPathComponent] + isEqual: @"/tmp"] && + [[@"foo/bar" stringByDeletingLastPathComponent] isEqual: @"foo"] && + [[@"/" stringByDeletingLastPathComponent] isEqual: @"/"] && + [[@"foo" stringByDeletingLastPathComponent] isEqual: @"."]) + TEST(@"-[decimalValue]", [@"1234" decimalValue] == 1234 && [@"+123" decimalValue] == 123 && [@"-500" decimalValue] == -500 && [@"" decimalValue] == 0) Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -91,14 +91,10 @@ @interface TestsAppDelegate (OFDictionaryTests) - (void)dictionaryTests; @end -@interface TestsAppDelegate (OFFileTests) -- (void)fileTests; -@end - @interface TestsAppDelegate (OFHTTPRequestTests) - (void)HTTPRequestTests; @end @interface TestsAppDelegate (OFListTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -119,11 +119,10 @@ [self objectTests]; #ifdef OF_HAVE_BLOCKS [self blockTests]; #endif [self stringTests]; - [self fileTests]; [self MD5HashTests]; [self SHA1HashTests]; [self dataArrayTests]; [self arrayTests]; [self dictionaryTests];