mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-14 22:51:28 +00:00
Fixed CPString pathComponents and lastPathComponent to match Cocoa. Added tests.
This commit is contained in:
@@ -584,7 +584,12 @@ var CPStringHashes = new objj_dictionary();
|
||||
*/
|
||||
- (CPArray)pathComponents
|
||||
{
|
||||
return split('/');
|
||||
var result = split('/');
|
||||
if (result[0] === "")
|
||||
result[0] = "/";
|
||||
if (result[result.length - 1] === "")
|
||||
result.pop();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -80,4 +80,31 @@ import <Foundation/CPString.j>
|
||||
[self assert:[testStrings[i][0] stringByDeletingLastPathComponent] equals:testStrings[i][1]];
|
||||
}
|
||||
|
||||
- (void)testPathComponents
|
||||
{
|
||||
var testStrings = [
|
||||
["tmp/scratch", ["tmp", "scratch"]],
|
||||
["/tmp/scratch", ["/", "tmp", "scratch"]]
|
||||
]
|
||||
|
||||
for (var i = 0; i < testStrings.length; i++) {
|
||||
var result = [testStrings[i][0] pathComponents];
|
||||
[self assertTrue:[result isEqualToArray:testStrings[i][1]] message:"Expected [" + testStrings[i][1] + "] was [" + result + "]"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testLastPathComponent
|
||||
{
|
||||
var testStrings = [
|
||||
["/tmp/scratch.tiff", "scratch.tiff"],
|
||||
["/tmp/scratch", "scratch"],
|
||||
["/tmp/", "tmp"],
|
||||
["scratch", "scratch"],
|
||||
["/", "/"]
|
||||
];
|
||||
|
||||
for (var i = 0; i < testStrings.length; i++)
|
||||
[self assert:testStrings[i][1] equals:[testStrings[i][0] lastPathComponent]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user