Tests/OrgCoreTests/StuckProjectsTests.swift

design-themes-widgets
orgstar/Tests/OrgCoreTests/StuckProjectsTests.swift history · blame · raw

48 lines · 1981 bytes

 1import Foundation
 2import Testing
 3@testable import OrgCore
 4
 5/// `org-agenda-list-stuck-projects` against Emacs.
 6struct StuckProjectsTests {
 7    static let file = """
 8    * Projects
 9    ** Website
10    *** TODO Draft the copy
11    ** Garden :outdoor:
12    *** WAIT Seeds
13    *** Notes
14    ** TODO Taxes
15    ** Kitchen
16    *** Buy tiles :errand:
17    ** DONE Old project
18    ** Reading
19    Waiting for the library. NEXT week.
20    ** IDEA Novel
21    *** HOLD Outline :@home:
22    * Areas
23    ** Health
24    *** STRT Running
25
26    """
27
28    @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
29    func listsLikeOrg() throws {
30        let today = Days.absolute(year: 2026, month: 10, day: 5)
31        let cases: [(String, StuckProjects)] = [
32            ("'(\"+LEVEL=2/-DONE\" (\"TODO\" \"NEXT\" \"NEXTACTION\") nil \"\")", StuckProjects()),
33            ("'(\"+LEVEL=2/-DONE\" (\"*\") nil \"\")", StuckProjects(todo: ["*"])),
34            ("'(\"+LEVEL=2/-DONE\" nil (\"errand\" \"@home\") \"\")", StuckProjects(todo: [], tags: ["errand", "@home"])),
35            ("'(\"+LEVEL=2/-DONE\" nil (\"*\") \"\")", StuckProjects(todo: [], tags: ["*"])),
36            ("'(\"+LEVEL=2/-DONE\" (\"WAIT\") nil \"\\\\<NEXT\\\\>\")", StuckProjects(todo: ["WAIT"], regexp: "\\<NEXT\\>")),
37            ("'(\"LEVEL=2-outdoor\" (\"TODO\" \"STRT\") nil \"library\")", StuckProjects(match: "LEVEL=2-outdoor", todo: ["TODO", "STRT"], regexp: "library")),
38        ]
39        var utc = Calendar(identifier: .gregorian)
40        utc.timeZone = TimeZone(identifier: "UTC")!
41        let now = Date(timeIntervalSince1970: Double((today - 719163) * 86400 + 9 * 3600 + 30 * 60))
42        for (lisp, definition) in cases {
43            try AgendaOracle.compareList(files: [("p.org", Self.file)], form: "(let ((org-stuck-projects \(lisp))) (org-agenda-list-stuck-projects))", today: today) {
44                Agenda.stuckProjects($0, definition, now: now, calendar: utc)
45            }
46        }
47    }
48}