Tests/OrgWorkspaceTests/DiscoveryTests.swift
62 lines · 2782 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(.text)),
17 ("a.markdown", .file(.text)),
18 ("a.txt", .file(.text)),
19 ("a.sync-conflict-20261004-120000-ABCDEFG.md", .file(.conflict)),
20 (".a.md.icloud", .placeholder("a.md")),
21 ("photo.jpg", .file(.other)),
22 (".hidden.org", .file(.org)),
23 (".zshrc", .file(.other)),
24 (".#a.org", .ignored),
25 (".DS_Store", .ignored),
26 (".a.org.orgstar-backup-1", .ignored),
27 ])
28 func classify(name: String, expected: FileClassification) {
29 #expect(WorkspaceScanner.classify(name) == expected)
30 }
31
32 @Test func agendaScope() {
33 #expect(AgendaScope().contains(relativePath: "a.org", kind: .org))
34 #expect(!AgendaScope().contains(relativePath: "a.org_archive", kind: .archive))
35 #expect(!AgendaScope().contains(relativePath: "a.org", kind: .conflict))
36 #expect(!AgendaScope().contains(relativePath: "sub/.draft.org", kind: .org))
37 let work = AgendaScope(globs: ["work/*"])
38 #expect(work.contains(relativePath: "work/deep/a.org", kind: .org))
39 #expect(!work.contains(relativePath: "home/a.org", kind: .org))
40 }
41}
42
43struct ScanTests {
44 @Test func skipsHiddenFoldersAndFindsPlaceholders() throws {
45 let folder = try Folder()
46 try folder.write("a.org", "* a\n")
47 try folder.write("sub/b.org_archive", "* b\n")
48 try folder.write(".git/c.org", "* c\n")
49 try folder.write(".stversions/d.org", "* d\n")
50 try folder.write("sub/.e.org.icloud", "")
51 try folder.write("notes.txt", "")
52 try folder.write(".config/app.toml", "")
53 try folder.write(".notes.org", "* n\n")
54 try folder.write("node_modules/x/index.js", "")
55 let discovery = try WorkspaceScanner.scan(folder.url)
56 #expect(discovery.files.map(\.url.lastPathComponent) == ["app.toml", ".notes.org", "a.org", "notes.txt", "b.org_archive"])
57 #expect(discovery.files.map(\.kind) == [.other, .org, .org, .text, .archive])
58 let visible = try WorkspaceScanner.scan(folder.url, rules: ScanRules(hiddenFiles: false))
59 #expect(visible.files.map(\.url.lastPathComponent) == ["a.org", "notes.txt", "b.org_archive"])
60 #expect(discovery.placeholders.map(\.lastPathComponent) == ["e.org"])
61 }
62}