Tests/OrgCoreTests/PrioritySetTests.swift
44 lines · 2317 bytes
4 symbols in this file
1import Foundation
2import Testing
3@testable import OrgCore
4
5struct PrioritySetTests {
6 static let oracle = ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil
7
8 @Test(.enabled(if: oracle))
9 func setsPrioritiesLikeOrg() throws {
10 let texts = ["* TODO Task :tag:\nbody\n", "* [#B] Plain\n", "* DONE [#A] Done one :x:y:\n", "* Heading\n"]
11 // Org reads SPC and lower case only at its prompt.
12 let values: [(Character, String)] = [("A", "(org-priority ?A)"), ("C", "(org-priority ?C)"),
13 (" ", "(cl-letf (((symbol-function 'read-char-exclusive) (lambda (&rest _) ?\\s))) (org-priority))"),
14 ("b", "(cl-letf (((symbol-function 'read-char-exclusive) (lambda (&rest _) ?b))) (org-priority))")]
15 var cases: [EmacsOracle.Case] = []
16 var ours: [(String, String?)] = []
17 for text in texts {
18 for (value, form) in values {
19 cases.append(EmacsOracle.Case(text: text, point: 3, form: form))
20 let result = runCommand(SetPriority(), text, caret: 2, answers: ["priority": String(value)])
21 ours.append((result.text, result.failure))
22 }
23 cases.append(EmacsOracle.Case(text: text, point: 3, form: "(org-priority ?D)"))
24 let result = runCommand(SetPriority(), text, caret: 2, answers: ["priority": "D"])
25 ours.append((result.text, result.failure))
26 }
27 for (i, theirs) in try EmacsOracle.run(cases).enumerated() {
28 #expect(ours[i].0 == theirs.text, "\(cases[i].form) on \(cases[i].text.debugDescription)")
29 #expect((ours[i].1 != nil) == !theirs.error.isEmpty, "\(cases[i].form): \(ours[i].1 ?? "") vs \(theirs.error)")
30 }
31 }
32
33 @Test func speedKeysHoldAtHeadingStarts() {
34 let text = "* One\nbody\n** Two\n"
35 func holds(_ caret: Int, _ on: Bool) -> Bool {
36 KeyContext.holds("speed", in: EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [caret..<caret], options: EditingOptions(useSpeedCommands: on)))
37 }
38 #expect(holds(0, true))
39 #expect(holds(11, true))
40 #expect(!holds(1, true))
41 #expect(!holds(6, true))
42 #expect(!holds(0, false))
43 }
44}