2016-08-30 21:44:58 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Nimble
|
2020-09-18 17:01:55 +03:00
|
|
|
import XCTest
|
2016-08-30 21:44:58 +03:00
|
|
|
|
2020-08-19 01:42:34 +03:00
|
|
|
@testable import Commons
|
|
|
|
|
2016-08-30 21:44:58 +03:00
|
|
|
class FileUtilsTest: XCTestCase {
|
2016-09-25 19:59:31 +03:00
|
|
|
var fileUtilsRsrcUrl = URL(fileURLWithPath: "/")
|
|
|
|
var a1Dir = URL(fileURLWithPath: "/")
|
2016-08-30 21:44:58 +03:00
|
|
|
|
|
|
|
override func setUp() {
|
2020-09-18 17:01:55 +03:00
|
|
|
self.fileUtilsRsrcUrl = Bundle.module.url(
|
|
|
|
forResource: "FileUtilsTest",
|
|
|
|
withExtension: "",
|
|
|
|
subdirectory: "Resources"
|
|
|
|
)!
|
|
|
|
self.a1Dir = self.fileUtilsRsrcUrl.appendingPathComponent("a1")
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testCommonParentOneDirUrl() {
|
|
|
|
let urls = [
|
2016-09-25 18:50:33 +03:00
|
|
|
fileUtilsRsrcUrl.appendingPathComponent("a1"),
|
2016-08-30 21:44:58 +03:00
|
|
|
]
|
|
|
|
|
2020-09-18 17:01:55 +03:00
|
|
|
expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl))
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testCommonParentOneFileUrl() {
|
|
|
|
let urls = [
|
2016-09-25 18:50:33 +03:00
|
|
|
fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
2016-08-30 21:44:58 +03:00
|
|
|
]
|
|
|
|
|
2020-09-18 17:01:55 +03:00
|
|
|
expect(FileUtils.commonParent(of: urls)).to(equal(self.a1Dir))
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testCommonParentEmptyParams() {
|
2020-09-18 17:01:55 +03:00
|
|
|
expect(FileUtils.commonParent(of: []) as URL)
|
|
|
|
.to(equal(URL(fileURLWithPath: "/", isDirectory: true)))
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testCommonParent1() {
|
|
|
|
let urls = [
|
2016-09-25 18:50:33 +03:00
|
|
|
fileUtilsRsrcUrl.appendingPathComponent("a1"),
|
2020-09-18 17:01:55 +03:00
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
2016-08-30 21:44:58 +03:00
|
|
|
]
|
|
|
|
|
2020-09-18 17:01:55 +03:00
|
|
|
expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl))
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testCommonParent2() {
|
|
|
|
let urls = [
|
2016-09-25 18:50:33 +03:00
|
|
|
fileUtilsRsrcUrl.appendingPathComponent("a1"),
|
2020-09-18 17:01:55 +03:00
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
2016-08-30 21:44:58 +03:00
|
|
|
]
|
|
|
|
|
2020-09-18 17:01:55 +03:00
|
|
|
expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl))
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|
|
|
|
|
2016-10-07 01:24:15 +03:00
|
|
|
func testBug1() {
|
|
|
|
let paths = [
|
|
|
|
fileUtilsRsrcUrl.appendingPathComponent("Downloads/test2/some/nginx.config"),
|
2020-09-18 17:01:55 +03:00
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent(".Trash/nginx.config"),
|
2016-10-07 01:24:15 +03:00
|
|
|
]
|
2020-09-18 17:01:55 +03:00
|
|
|
expect(FileUtils.commonParent(of: paths)).to(equal(self.fileUtilsRsrcUrl))
|
2016-10-07 01:24:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testBug2() {
|
|
|
|
let paths = [
|
|
|
|
fileUtilsRsrcUrl.appendingPathComponent("Downloads/test2/some/nginx.config"),
|
2020-09-18 17:01:55 +03:00
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent(".Trash/nginx.config/de/nginx.config"),
|
2016-10-07 01:24:15 +03:00
|
|
|
]
|
2020-09-18 17:01:55 +03:00
|
|
|
expect(FileUtils.commonParent(of: paths)).to(equal(self.fileUtilsRsrcUrl))
|
2016-10-07 01:24:15 +03:00
|
|
|
}
|
|
|
|
|
2016-08-30 21:44:58 +03:00
|
|
|
func testCommonParent3() {
|
|
|
|
let urls = [
|
2016-09-25 18:50:33 +03:00
|
|
|
fileUtilsRsrcUrl.appendingPathComponent("a1"),
|
2020-09-18 17:01:55 +03:00
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("b1/b1-file1"),
|
2016-08-30 21:44:58 +03:00
|
|
|
]
|
|
|
|
|
2020-09-18 17:01:55 +03:00
|
|
|
expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl))
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testCommonParent4() {
|
|
|
|
let urls = [
|
2016-09-25 18:50:33 +03:00
|
|
|
fileUtilsRsrcUrl.appendingPathComponent("a1"),
|
2020-09-18 17:01:55 +03:00
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("b1"),
|
2016-08-30 21:44:58 +03:00
|
|
|
]
|
|
|
|
|
2020-09-18 17:01:55 +03:00
|
|
|
expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl))
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testCommonParent5() {
|
|
|
|
let urls = [
|
2016-09-25 18:50:33 +03:00
|
|
|
fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
2020-09-18 17:01:55 +03:00
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
|
|
|
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2"),
|
2016-08-30 21:44:58 +03:00
|
|
|
]
|
|
|
|
|
2020-09-18 17:01:55 +03:00
|
|
|
expect(FileUtils.commonParent(of: urls)).to(equal(self.a1Dir))
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|
|
|
|
}
|