1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 16:56:40 +03:00
vimr/VimRTests/FileUtilsTest.swift

107 lines
3.1 KiB
Swift
Raw Normal View History

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