@@ -200,6 +200,15 @@ public struct Path: Equatable, Hashable, Comparable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Splits the string representation on the directory separator.
|
||||
- Important: The first element is always "/" to be consistent with `NSString.pathComponents`.
|
||||
*/
|
||||
@inlinable
|
||||
public var components: [String] {
|
||||
return ["/"] + string.split(separator: "/").map(String.init)
|
||||
}
|
||||
|
||||
//MARK: Pathing
|
||||
|
||||
/**
|
||||
|
||||
@@ -588,4 +588,9 @@ class PathTests: XCTestCase {
|
||||
XCTAssertNil(Path("../foo"))
|
||||
XCTAssertNil(Path("./foo"))
|
||||
}
|
||||
|
||||
func testPathComponents() throws {
|
||||
XCTAssertEqual(Path.root.foo.bar.components, ["/", "foo", "bar"])
|
||||
XCTAssertEqual(Path.root.components, ["/"])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ extension PathTests {
|
||||
("testMoveInto", testMoveInto),
|
||||
("testMoveTo", testMoveTo),
|
||||
("testNoUndesiredSymlinkResolution", testNoUndesiredSymlinkResolution),
|
||||
("testPathComponents", testPathComponents),
|
||||
("testReadlinkOnFileReturnsSelf", testReadlinkOnFileReturnsSelf),
|
||||
("testReadlinkOnNonExistantFileThrows", testReadlinkOnNonExistantFileThrows),
|
||||
("testReadlinkOnRelativeSymlink", testReadlinkOnRelativeSymlink),
|
||||
|
||||
Reference in New Issue
Block a user