Tests/OrgAppTests/WorkspaceContainsTests.swift

27 lines · 1556 bytes

3 symbols in this file
 1import Foundation
 2import Testing
 3@testable import OrgApp
 4
 5struct WorkspaceContainsTests {
 6    @Test func insideByWholeComponents() {
 7        let root = URL(fileURLWithPath: "/tmp/notes")
 8        #expect(WorkspaceModel.isInside(URL(fileURLWithPath: "/tmp/notes"), roots: [root]))
 9        #expect(WorkspaceModel.isInside(URL(fileURLWithPath: "/tmp/notes/a/b.html"), roots: [root]))
10        #expect(WorkspaceModel.isInside(URL(fileURLWithPath: "/tmp/notes/../notes/b.html"), roots: [root]))
11        #expect(!WorkspaceModel.isInside(URL(fileURLWithPath: "/tmp/notes2/b.html"), roots: [root]))
12        #expect(!WorkspaceModel.isInside(URL(fileURLWithPath: "/tmp/b.html"), roots: [root]))
13        #expect(!WorkspaceModel.isInside(URL(fileURLWithPath: "/tmp/notes/b.html"), roots: []))
14    }
15
16    @Test func insideThroughSymbolicLinks() throws {
17        let base = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
18        defer { try? FileManager.default.removeItem(at: base) }
19        let real = base.appendingPathComponent("real")
20        try FileManager.default.createDirectory(at: real, withIntermediateDirectories: true)
21        let link = base.appendingPathComponent("link")
22        try FileManager.default.createSymbolicLink(at: link, withDestinationURL: real)
23        try Data().write(to: real.appendingPathComponent("a.org"))
24        #expect(WorkspaceModel.isInside(link.appendingPathComponent("a.org"), roots: [real]))
25        #expect(WorkspaceModel.isInside(real.appendingPathComponent("a.org"), roots: [link]))
26    }
27}