@@ -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
|
//MARK: Pathing
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -588,4 +588,9 @@ class PathTests: XCTestCase {
|
|||||||
XCTAssertNil(Path("../foo"))
|
XCTAssertNil(Path("../foo"))
|
||||||
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),
|
("testMoveInto", testMoveInto),
|
||||||
("testMoveTo", testMoveTo),
|
("testMoveTo", testMoveTo),
|
||||||
("testNoUndesiredSymlinkResolution", testNoUndesiredSymlinkResolution),
|
("testNoUndesiredSymlinkResolution", testNoUndesiredSymlinkResolution),
|
||||||
|
("testPathComponents", testPathComponents),
|
||||||
("testReadlinkOnFileReturnsSelf", testReadlinkOnFileReturnsSelf),
|
("testReadlinkOnFileReturnsSelf", testReadlinkOnFileReturnsSelf),
|
||||||
("testReadlinkOnNonExistantFileThrows", testReadlinkOnNonExistantFileThrows),
|
("testReadlinkOnNonExistantFileThrows", testReadlinkOnNonExistantFileThrows),
|
||||||
("testReadlinkOnRelativeSymlink", testReadlinkOnRelativeSymlink),
|
("testReadlinkOnRelativeSymlink", testReadlinkOnRelativeSymlink),
|
||||||
|
|||||||
Reference in New Issue
Block a user