Finder is a iterable Sequence; .type -> .kind
This commit is contained in:
@@ -2,39 +2,50 @@ import XCTest
|
||||
import Path
|
||||
|
||||
extension PathTests {
|
||||
func testFindMaxDepth0() throws {
|
||||
#if !os(Linux) || swift(>=5)
|
||||
func testFindMaxDepth1() throws {
|
||||
try Path.mktemp { tmpdir in
|
||||
try tmpdir.a.touch()
|
||||
try tmpdir.b.touch()
|
||||
try tmpdir.c.mkdir().join("e").touch()
|
||||
|
||||
XCTAssertEqual(
|
||||
Set(tmpdir.find().maxDepth(0).execute()),
|
||||
Set([tmpdir.a, tmpdir.b, tmpdir.c].map(Path.init)))
|
||||
do {
|
||||
let finder = tmpdir.find().depth(max: 1)
|
||||
XCTAssertEqual(finder.depth, 1...1)
|
||||
#if !os(Linux) || swift(>=5)
|
||||
XCTAssertEqual(Set(finder), Set([tmpdir.a, tmpdir.b, tmpdir.c].map(Path.init)))
|
||||
#endif
|
||||
}
|
||||
do {
|
||||
let finder = tmpdir.find().depth(max: 0)
|
||||
XCTAssertEqual(finder.depth, 0...0)
|
||||
#if !os(Linux) || swift(>=5)
|
||||
XCTAssertEqual(Set(finder), Set())
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
func testFindMaxDepth1() throws {
|
||||
#if !os(Linux) || swift(>=5)
|
||||
func testFindMaxDepth2() throws {
|
||||
try Path.mktemp { tmpdir in
|
||||
try tmpdir.a.touch()
|
||||
try tmpdir.b.mkdir().join("c").touch()
|
||||
try tmpdir.b.d.mkdir().join("e").touch()
|
||||
|
||||
#if !os(Linux)
|
||||
XCTAssertEqual(
|
||||
Set(tmpdir.find().maxDepth(1).execute()),
|
||||
Set([tmpdir.a, tmpdir.b, tmpdir.b.c].map(Path.init)))
|
||||
#else
|
||||
// Linux behavior is different :-/
|
||||
XCTAssertEqual(
|
||||
Set(tmpdir.find().maxDepth(1).execute()),
|
||||
Set([tmpdir.a, tmpdir.b, tmpdir.b.d, tmpdir.b.c].map(Path.init)))
|
||||
#endif
|
||||
do {
|
||||
let finder = tmpdir.find().depth(max: 2)
|
||||
XCTAssertEqual(finder.depth, 1...2)
|
||||
XCTAssertEqual(
|
||||
Set(finder),
|
||||
Set([tmpdir.a, tmpdir.b, tmpdir.b.d, tmpdir.b.c].map(Path.init)))
|
||||
}
|
||||
do {
|
||||
let finder = tmpdir.find().depth(max: 3)
|
||||
XCTAssertEqual(finder.depth, 1...3)
|
||||
XCTAssertEqual(
|
||||
Set(finder),
|
||||
Set([tmpdir.a, tmpdir.b, tmpdir.b.d, tmpdir.b.c, tmpdir.b.d.e].map(Path.init)))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
func testFindExtension() throws {
|
||||
@@ -43,10 +54,10 @@ extension PathTests {
|
||||
try tmpdir.join("bar.txt").touch()
|
||||
|
||||
XCTAssertEqual(
|
||||
Set(tmpdir.find().extension("json").execute()),
|
||||
Set(tmpdir.find().extension("json")),
|
||||
[tmpdir.join("foo.json")])
|
||||
XCTAssertEqual(
|
||||
Set(tmpdir.find().extension("txt").extension("json").execute()),
|
||||
Set(tmpdir.find().extension("txt").extension("json")),
|
||||
[tmpdir.join("foo.json"), tmpdir.join("bar.txt")])
|
||||
}
|
||||
}
|
||||
@@ -57,13 +68,13 @@ extension PathTests {
|
||||
try tmpdir.bar.touch()
|
||||
|
||||
XCTAssertEqual(
|
||||
Set(tmpdir.find().kind(.file).execute()),
|
||||
Set(tmpdir.find().type(.file)),
|
||||
[tmpdir.join("bar")])
|
||||
XCTAssertEqual(
|
||||
Set(tmpdir.find().kind(.directory).execute()),
|
||||
Set(tmpdir.find().type(.directory)),
|
||||
[tmpdir.join("foo")])
|
||||
XCTAssertEqual(
|
||||
Set(tmpdir.find().kind(.file).kind(.directory).execute()),
|
||||
Set(tmpdir.find().type(.file).type(.directory)),
|
||||
Set(["foo", "bar"].map(tmpdir.join)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +76,10 @@ class PathTests: XCTestCase {
|
||||
try Path.mktemp { tmpdir in
|
||||
XCTAssertTrue(tmpdir.exists)
|
||||
XCTAssertFalse(try tmpdir.bar.symlink(as: tmpdir.foo).exists)
|
||||
XCTAssertTrue(tmpdir.foo.kind == .symlink)
|
||||
XCTAssertTrue(tmpdir.foo.type == .symlink)
|
||||
XCTAssertTrue(try tmpdir.bar.touch().symlink(as: tmpdir.baz).exists)
|
||||
XCTAssertTrue(tmpdir.bar.kind == .file)
|
||||
XCTAssertTrue(tmpdir.kind == .directory)
|
||||
XCTAssertTrue(tmpdir.bar.type == .file)
|
||||
XCTAssertTrue(tmpdir.type == .directory)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,18 +393,18 @@ class PathTests: XCTestCase {
|
||||
|
||||
// regression test: can delete a symlink that points to a non-existent file
|
||||
let bar5 = try tmpdir.bar4.symlink(as: tmpdir.bar5)
|
||||
XCTAssertEqual(bar5.kind, .symlink)
|
||||
XCTAssertEqual(bar5.type, .symlink)
|
||||
XCTAssertFalse(bar5.exists)
|
||||
XCTAssertNoThrow(try bar5.delete())
|
||||
XCTAssertEqual(bar5.kind, nil)
|
||||
XCTAssertEqual(bar5.type, nil)
|
||||
|
||||
// test that deleting a symlink *only* deletes the symlink
|
||||
let bar7 = try tmpdir.bar6.touch().symlink(as: tmpdir.bar7)
|
||||
XCTAssertEqual(bar7.kind, .symlink)
|
||||
XCTAssertEqual(bar7.type, .symlink)
|
||||
XCTAssertTrue(bar7.exists)
|
||||
XCTAssertNoThrow(try bar7.delete())
|
||||
XCTAssertEqual(bar7.kind, nil)
|
||||
XCTAssertEqual(tmpdir.bar6.kind, .file)
|
||||
XCTAssertEqual(bar7.type, nil)
|
||||
XCTAssertEqual(tmpdir.bar6.type, .file)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,8 +619,8 @@ class PathTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testPathComponents() throws {
|
||||
XCTAssertEqual(Path.root.foo.bar.components, ["/", "foo", "bar"])
|
||||
XCTAssertEqual(Path.root.components, ["/"])
|
||||
XCTAssertEqual(Path.root.foo.bar.components, ["foo", "bar"])
|
||||
XCTAssertEqual(Path.root.components, [])
|
||||
}
|
||||
|
||||
func testFlatMap() throws {
|
||||
@@ -637,9 +637,9 @@ class PathTests: XCTestCase {
|
||||
try Path.mktemp { tmpdir in
|
||||
let foo = try tmpdir.foo.touch()
|
||||
let bar = try foo.symlink(as: tmpdir.bar)
|
||||
XCTAssertEqual(tmpdir.kind, .directory)
|
||||
XCTAssertEqual(foo.kind, .file)
|
||||
XCTAssertEqual(bar.kind, .symlink)
|
||||
XCTAssertEqual(tmpdir.type, .directory)
|
||||
XCTAssertEqual(foo.type, .file)
|
||||
XCTAssertEqual(bar.type, .symlink)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user