krz/orgstar

A native macOS editor for org-mode files. editor org-mode swift

Tests/OrgCoreTests/CtrlCCtrlCTests.swift

ab6ccec56eca03d0dadf2c9332aab10c4490eb62
orgstar/Tests/OrgCoreTests/CtrlCCtrlCTests.swift history · blame · raw

55 lines · 2211 bytes

 1import Foundation
 2import Testing
 3@testable import OrgCore
 4
 5struct CtrlCCtrlCTests {
 6    static let text = """
 7        #+TITLE: Test
 8        * TODO Task [1/3] :old:
 9        SCHEDULED: <2026-10-05 Tue>
10        :LOGBOOK:
11        CLOCK: [2026-10-01 Fri 09:00]--[2026-10-01 Fri 11:30] =>  1:00
12        CLOCK: [2026-10-01 Thu 12:00]--[2026-10-01 Thu 12:45]
13        :END:
14        - [X] one
15        - [ ] two
16        - three
17        1. first
18        3. second
19        Text with <2026-10-07 Mon> stamp.
20
21        ** DONE Child [50%]
22        - [ ] a
23        - [X] b
24        | a | b |
25        |-+-|
26
27        """
28
29    @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
30    func actsLikeOrgCtrlCCtrlC() throws {
31        let ns = Self.text as NSString
32        var offsets: [Int] = []
33        var at = 0
34        while at < ns.length {
35            let line = ns.lineRange(for: NSRange(location: at, length: 0))
36            offsets += [line.location, min(line.location + 8, NSMaxRange(line) - 1)]
37            at = NSMaxRange(line)
38        }
39        offsets = Array(Set(offsets)).sorted()
40        // Cookies and timestamps under the caret.
41        offsets += [ns.range(of: "[1/3]").location + 1, ns.range(of: "[50%]").location + 2, ns.range(of: "<2026-10-07").location + 3, ns.range(of: "Fri 09").location]
42        var cases: [EmacsOracle.Case] = []
43        var ours: [String] = []
44        for offset in offsets {
45            cases.append(EmacsOracle.Case(text: Self.text, point: EmacsOracle.point(offset, in: Self.text), form: frozenClock(1_789_000_000, """
46                (cl-letf (((symbol-function 'completing-read-multiple) (lambda (&rest _) '("x"))))
47                  (org-ctrl-c-ctrl-c))
48                """)))
49            ours.append(runCommand(CtrlCCtrlC(), Self.text, caret: offset, answers: ["tags": "x"]).text)
50        }
51        for (i, (mine, theirs)) in zip(ours, try EmacsOracle.run(cases)).enumerated() {
52            #expect(mine == theirs.text, "at \(offsets[i]) (\(ns.substring(with: ns.lineRange(for: NSRange(location: offsets[i], length: 0)))).debugDescription))\nours:  \(mine.debugDescription)\nemacs: \(theirs.text.debugDescription) \(theirs.error)")
53        }
54    }
55}