|
| 1 | +import System_ |
| 2 | +import Testing |
| 3 | + |
| 4 | +@Suite |
| 5 | +enum Directories |
| 6 | +{ |
| 7 | + @Test |
| 8 | + static func ExistenceDoesNotExist() throws |
| 9 | + { |
| 10 | + let path:FilePath = "Sources/SystemTests/TheLimit" |
| 11 | + #expect(!path.directory.exists()) |
| 12 | + } |
| 13 | + @Test |
| 14 | + static func ExistenceDoesExist() throws |
| 15 | + { |
| 16 | + let path:FilePath = "Sources/SystemTests/directories/flat" |
| 17 | + #expect(path.directory.exists()) |
| 18 | + } |
| 19 | + @Test |
| 20 | + static func ExistenceIsSymlink() throws |
| 21 | + { |
| 22 | + let path:FilePath = "Sources/SystemTests/directories/flat-link/a.txt" |
| 23 | + #expect(!path.directory.exists()) |
| 24 | + } |
| 25 | + @Test |
| 26 | + static func ExistenceIsSymlinkToDirectory() throws |
| 27 | + { |
| 28 | + let path:FilePath = "Sources/SystemTests/directories/flat-link" |
| 29 | + #expect(path.directory.exists()) |
| 30 | + } |
| 31 | + @Test |
| 32 | + static func ExistenceIsNotDirectory() throws |
| 33 | + { |
| 34 | + let path:FilePath = "Sources/SystemTests/directories/flat/a.txt" |
| 35 | + #expect(!path.directory.exists()) |
| 36 | + } |
| 37 | + @Test |
| 38 | + static func Flat() throws |
| 39 | + { |
| 40 | + var files:[FilePath] = [] |
| 41 | + |
| 42 | + let path:FilePath = "Sources/SystemTests/directories/flat" |
| 43 | + try path.directory.walk |
| 44 | + { |
| 45 | + files.append($0) |
| 46 | + return true |
| 47 | + } |
| 48 | + let discovered:Set<FilePath.Component> = files.reduce(into: []) |
| 49 | + { |
| 50 | + if let file:FilePath.Component = $1.lastComponent |
| 51 | + { |
| 52 | + $0.insert(file) |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + #expect(discovered == ["a.txt", "b.txt", "c.txt"]) |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + static func Complex() throws |
| 61 | + { |
| 62 | + var files:[FilePath] = [] |
| 63 | + |
| 64 | + let path:FilePath = "Sources/SystemTests/directories/complex" |
| 65 | + try path.directory.walk |
| 66 | + { |
| 67 | + files.append($0) |
| 68 | + return true |
| 69 | + } |
| 70 | + |
| 71 | + let discovered:Set<FilePath.Component> = files.reduce(into: []) |
| 72 | + { |
| 73 | + if let file:FilePath.Component = $1.lastComponent |
| 74 | + { |
| 75 | + $0.insert(file) |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + #expect(discovered == [ |
| 80 | + "a.txt", |
| 81 | + "b.txt", |
| 82 | + "x", |
| 83 | + "c.txt", |
| 84 | + "y", |
| 85 | + "d.txt", |
| 86 | + "z", |
| 87 | + "e.txt" |
| 88 | + ]) |
| 89 | + } |
| 90 | +} |
0 commit comments