1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-18 11:11:34 +03:00
vimr/Commons/Tests/CommonsTests/UrlCommonsTest.swift

78 lines
2.6 KiB
Swift
Raw Normal View History

2017-05-03 23:10:19 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Nimble
2020-09-18 17:01:55 +03:00
import XCTest
2017-05-03 23:10:19 +03:00
class UrlCommonsTest: XCTestCase {
func testIsDirectParent() {
let parent = URL(fileURLWithPath: "/some/path")
let child = URL(fileURLWithPath: "/some/path/text.txt")
let noChild1 = URL(fileURLWithPath: "/some/where/else/text.txt")
let noChild2 = URL(fileURLWithPath: "/some/text.txt")
2021-07-16 18:24:10 +03:00
expect(parent.isParent(of: child)).to(beTrue())
expect(parent.isParent(of: noChild1)).to(beFalse())
expect(parent.isParent(of: noChild2)).to(beFalse())
2017-05-03 23:10:19 +03:00
}
func testIsParent() {
let parent = URL(fileURLWithPath: "/some/path")
let child1 = URL(fileURLWithPath: "/some/path/text.txt")
let child2 = URL(fileURLWithPath: "/some/path/deep/text.txt")
let noChild1 = URL(fileURLWithPath: "/some/where/else/text.txt")
let noChild2 = URL(fileURLWithPath: "/some/text.txt")
2021-07-16 18:24:10 +03:00
expect(parent.isAncestor(of: child1)).to(beTrue())
expect(parent.isAncestor(of: child2)).to(beTrue())
expect(parent.isAncestor(of: noChild1)).to(beFalse())
expect(parent.isAncestor(of: noChild2)).to(beFalse())
2017-05-03 23:10:19 +03:00
}
func testIsContained() {
let parent = URL(fileURLWithPath: "/some/path")
let child1 = URL(fileURLWithPath: "/some/path/text.txt")
let child2 = URL(fileURLWithPath: "/some/path/deep/text.txt")
let noChild1 = URL(fileURLWithPath: "/some/where/else/text.txt")
let noChild2 = URL(fileURLWithPath: "/some/text.txt")
expect(child1.isContained(in: parent)).to(beTrue())
expect(child2.isContained(in: parent)).to(beTrue())
expect(noChild1.isContained(in: parent)).to(beFalse())
expect(noChild2.isContained(in: parent)).to(beFalse())
}
func testParent() {
expect(URL(fileURLWithPath: "/some/path/").parent).to(equal(URL(fileURLWithPath: "/some/")))
2020-09-18 17:01:55 +03:00
expect(URL(fileURLWithPath: "/some/path/text.txt").parent)
.to(equal(URL(fileURLWithPath: "/some/path/")))
2017-05-03 23:10:19 +03:00
expect(URL(fileURLWithPath: "/").parent).to(equal(URL(fileURLWithPath: "/")))
}
func testIsHidden() {
2020-09-18 17:01:55 +03:00
let resourceUrl = Bundle.module.url(
forResource: "UrlCommonsTest",
withExtension: "",
subdirectory: "Resources"
)!
2017-05-03 23:10:19 +03:00
let hidden = resourceUrl.appendingPathComponent(".dot-hidden-file")
expect(hidden.isHidden).to(beTrue())
expect(resourceUrl.isHidden).to(beFalse())
}
func testIsPackage() {
2020-09-18 17:01:55 +03:00
let resourceUrl = Bundle.module.url(
forResource: "UrlCommonsTest",
withExtension: "",
subdirectory: "Resources"
)!
2017-05-03 23:10:19 +03:00
let package = resourceUrl.appendingPathComponent("dummy.rtfd")
expect(package.isPackage).to(beTrue())
expect(resourceUrl.isPackage).to(beFalse())
}
}