Skip to content

Commit

Permalink
Fix root subfolder parent (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeLM authored and JohnSundell committed Sep 27, 2019
1 parent 85d7895 commit 6568bfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/Files.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ fileprivate extension Storage {
guard path != "/" else { return nil }
let url = URL(fileURLWithPath: path)
let components = url.pathComponents.dropFirst().dropLast()
guard !components.isEmpty else { return "/" }
return "/" + components.joined(separator: "/") + "/"
}

Expand Down
9 changes: 9 additions & 0 deletions Tests/FilesTests/FilesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@ class FilesTests: XCTestCase {
}
}

func testRootSubfolderParentIsRoot() {
performTest {
let rootFolder = try Folder(path: "/")
let subfolder = rootFolder.subfolders.first
XCTAssertEqual(subfolder?.parent, rootFolder)
}
}

func testOpeningFileWithEmptyPathThrows() {
performTest {
try assert(File(path: ""), throwsErrorOfType: LocationError.self)
Expand Down Expand Up @@ -869,6 +877,7 @@ class FilesTests: XCTestCase {
("testModificationDate", testModificationDate),
("testParent", testParent),
("testRootFolderParentIsNil", testRootFolderParentIsNil),
("testRootSubfolderParentIsRoot", testRootSubfolderParentIsRoot),
("testOpeningFileWithEmptyPathThrows", testOpeningFileWithEmptyPathThrows),
("testDeletingNonExistingFileThrows", testDeletingNonExistingFileThrows),
("testWritingDataToFile", testWritingDataToFile),
Expand Down

0 comments on commit 6568bfe

Please sign in to comment.