Tests/OrgWorkspaceTests/DiscoveryTests.swift
58 lines · 2591 bytes
5 symbols in this file
1import Foundation
2import OrgIndex
3import Testing
4@testable import OrgWorkspace
5
6struct ClassificationTests {
7 @Test(arguments: [
8 ("a.org", FileClassification.file(.org)),
9 ("a.org_archive", .file(.archive)),
10 ("a.sync-conflict-20261004-120000-ABCDEFG.org", .file(.conflict)),
11 (".a.org.icloud", .placeholder("a.org")),
12 (".syncthing.a.org.tmp", .ignored),
13 (".a.org.orgstar-1234", .ignored),
14 ("a.org~", .ignored),
15 ("#a.org#", .ignored),
16 ("a.md", .file(.other)),
17 ("photo.jpg", .file(.other)),
18 (".hidden.org", .file(.org)),
19 (".zshrc", .file(.other)),
20 (".#a.org", .ignored),
21 (".DS_Store", .ignored),
22 (".a.org.orgstar-backup-1", .ignored),
23 ])
24 func classify(name: String, expected: FileClassification) {
25 #expect(WorkspaceScanner.classify(name) == expected)
26 }
27
28 @Test func agendaScope() {
29 #expect(AgendaScope().contains(relativePath: "a.org", kind: .org))
30 #expect(!AgendaScope().contains(relativePath: "a.org_archive", kind: .archive))
31 #expect(!AgendaScope().contains(relativePath: "a.org", kind: .conflict))
32 #expect(!AgendaScope().contains(relativePath: "sub/.draft.org", kind: .org))
33 let work = AgendaScope(globs: ["work/*"])
34 #expect(work.contains(relativePath: "work/deep/a.org", kind: .org))
35 #expect(!work.contains(relativePath: "home/a.org", kind: .org))
36 }
37}
38
39struct ScanTests {
40 @Test func skipsHiddenFoldersAndFindsPlaceholders() throws {
41 let folder = try Folder()
42 try folder.write("a.org", "* a\n")
43 try folder.write("sub/b.org_archive", "* b\n")
44 try folder.write(".git/c.org", "* c\n")
45 try folder.write(".stversions/d.org", "* d\n")
46 try folder.write("sub/.e.org.icloud", "")
47 try folder.write("notes.txt", "")
48 try folder.write(".config/app.toml", "")
49 try folder.write(".notes.org", "* n\n")
50 try folder.write("node_modules/x/index.js", "")
51 let discovery = try WorkspaceScanner.scan(folder.url)
52 #expect(discovery.files.map(\.url.lastPathComponent) == ["app.toml", ".notes.org", "a.org", "notes.txt", "b.org_archive"])
53 #expect(discovery.files.map(\.kind) == [.other, .org, .org, .other, .archive])
54 let visible = try WorkspaceScanner.scan(folder.url, rules: ScanRules(hiddenFiles: false))
55 #expect(visible.files.map(\.url.lastPathComponent) == ["a.org", "notes.txt", "b.org_archive"])
56 #expect(discovery.placeholders.map(\.lastPathComponent) == ["e.org"])
57 }
58}