Tests/OrgCoreTests/VimTests.swift

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

450 lines · 21289 bytes

  1import Foundation
  2import Testing
  3@testable import OrgCore
  4
  5/// Plays keys through `Vim` the way the editor does: printable keys in insert state type,
  6/// actions apply to the text.
  7struct VimDriver {
  8    var vim = Vim()
  9    var text: String
 10    var caret: Int
 11    var clipboard: String?
 12    var commands: [String] = []
 13    var halfPage = 15
 14    var visible: Range<Int>?
 15    var org = false
 16    var marks: [Character: Int] = [:]
 17    var fileName: String?
 18    var lastEx: String?
 19    var actions: [Vim.Action] = []
 20
 21    init(_ text: String, caret: Int) {
 22        self.text = text
 23        self.caret = caret
 24    }
 25
 26    /// An edit as the editor makes it: the change list hears of it and the marks move.
 27    mutating func edit(_ edit: TextEdit) {
 28        text = edit.apply(to: text)
 29        vim.changed(edit)
 30        let delta = edit.replacement.utf16.count - edit.range.count
 31        for (name, mark) in marks where mark >= edit.range.lowerBound {
 32            marks[name] = mark >= edit.range.upperBound ? mark + delta : edit.range.lowerBound
 33        }
 34    }
 35
 36    mutating func type(_ keys: [KeyChord]) {
 37        for key in keys {
 38            if vim.mode == .insert, vim.passesThrough(key) {
 39                if key == KeyChord("DEL") {
 40                    if caret > 0 {
 41                        edit(TextEdit(range: (caret - 1)..<caret, replacement: ""))
 42                        caret -= 1
 43                        vim.deletedBackward()
 44                    }
 45                } else {
 46                    let s = key.key == "SPC" ? " " : key.key == "RET" ? "\n" : key.key == "TAB" ? "\t" : key.key
 47                    guard key.modifiers.isEmpty, s.count == 1 else { continue }
 48                    edit(TextEdit(range: caret..<caret, replacement: s))
 49                    caret += s.utf16.count
 50                    vim.inserted(s)
 51                }
 52                continue
 53            }
 54            let actions = vim.feed(key, Vim.Context(text: text, caret: caret, clipboard: clipboard, halfPage: halfPage, marks: marks, visible: visible, org: org,
 55                                                    fileName: fileName, lastEx: lastEx))
 56            self.actions += actions
 57            for action in actions {
 58                switch action {
 59                case .edit(let edits, let to):
 60                    for edit in edits.sorted(by: { $0.range.lowerBound > $1.range.lowerBound }) { self.edit(edit) }
 61                    caret = to
 62                case .setMark(let name, let offset): marks[name] = offset
 63                case .move(let to): caret = to
 64                case .setClipboard(let s): clipboard = s
 65                case .command(let id): commands.append(id)
 66                case .fill(let range, let keep):
 67                    let result = runCommand(FillRegion(range: range, keep: keep), text, caret: caret)
 68                    text = result.text
 69                    caret = result.caret
 70                default: break
 71                }
 72            }
 73        }
 74    }
 75}
 76
 77struct VimTests {
 78    static func keys(_ s: String) -> [KeyChord] { KeySequence.parse(s)! }
 79
 80    static let cases: [(String, Int, String)] = [
 81        ("hello world foo\nsecond line here\n", 0, "d w"),
 82        ("hello world foo\nsecond line here\n", 0, "j c i w X ESC"),
 83        ("hello world foo\nsecond line here\n", 6, "d i w"),
 84        ("hello world foo\nsecond line here\n", 6, "d a w"),
 85        ("hello world foo\nsecond line here\n", 0, "2 d w"),
 86        ("hello world foo\nsecond line here\n", 0, "d 2 w"),
 87        ("hello world foo\nsecond line here\n", 12, "d w"),
 88        ("hello world foo\nsecond line here\n", 4, "x"),
 89        ("hello world foo\nsecond line here\n", 4, "3 x"),
 90        ("hello world foo\nsecond line here\n", 4, "X"),
 91        ("hello world foo\nsecond line here\n", 4, "D"),
 92        ("hello world foo\nsecond line here\n", 4, "C n e w ESC"),
 93        ("hello world foo\nsecond line here\n", 4, "d d"),
 94        ("one\ntwo\nthree\nfour\n", 4, "2 d d"),
 95        ("one\ntwo\nthree\nfour\n", 14, "d d"),
 96        ("one\ntwo\nthree\nfour", 14, "d d"),
 97        ("one\ntwo\nthree\n", 0, "y y p"),
 98        ("one\ntwo\nthree\n", 0, "y y P"),
 99        ("one\ntwo\nthree\n", 4, "y w $ p"),
100        ("one\ntwo\nthree\n", 0, "d d p"),
101        ("one two three\n", 0, "d w w P"),
102        ("one two three\n", 4, "Y $ p"),
103        ("one\ntwo\nthree\n", 0, "J"),
104        ("one\n  two\nthree\n", 0, "3 J"),
105        ("one two\n", 0, "r X"),
106        ("one two\n", 0, "~ ~"),
107        ("Hello World\n", 0, "g U i w"),
108        ("Hello World\n", 0, "g u u"),
109        ("one two\n", 0, "o n e w ESC"),
110        ("one two\n", 4, "O n e w ESC"),
111        ("  one two\n", 6, "I x ESC"),
112        ("one two\n", 2, "A ! ESC"),
113        ("one two\n", 2, "a X ESC"),
114        ("one two three four\n", 0, "d w ."),
115        ("one two three four\n", 0, "c w X ESC w ."),
116        ("one\ntwo\nthree\nfour\n", 0, "d d j ."),
117        ("a(b, c) d\n", 3, "d i ("),
118        ("a(b, c) d\n", 3, "d a ("),
119        ("say \"hi there\" now\n", 7, "c i \" X ESC"),
120        ("say \"hi there\" now\n", 7, "d a \""),
121        ("x = [1, 2, 3]\n", 6, "d i ["),
122        ("f {\n  body\n}\n", 6, "d i {"),
123        ("one two three\n", 0, "v e d"),
124        ("one two three\n", 4, "v i w y $ p"),
125        ("one\ntwo\nthree\n", 4, "V d"),
126        ("one\ntwo\nthree\n", 0, "V j d"),
127        ("one\ntwo\nthree\n", 0, "V j y G p"),
128        ("one two three\n", 0, "f t x"),
129        ("one two three\n", 0, "t t x"),
130        ("one two three\n", 12, "F o x"),
131        ("one two three\n", 0, "f e ; x"),
132        ("one two three\n", 0, "d f t"),
133        ("one two three\n", 0, "d t t"),
134        ("one two three\n", 0, "$ x"),
135        ("one two three\n", 8, "0 x"),
136        ("   one two\n", 8, "^ x"),
137        ("one\ntwo\nthree\n", 0, "G x"),
138        ("one\ntwo\nthree\n", 10, "g g x"),
139        ("one\ntwo\nthree\n", 0, "2 G x"),
140        ("one two three\n", 0, "e x"),
141        ("one two three\n", 0, "w w b x"),
142        ("one.two three\n", 0, "w x"),
143        ("one.two three\n", 0, "W x"),
144        ("one.two three\n", 12, "B x"),
145        ("one two three\n", 0, "d e"),
146        ("one two three\n", 8, "d b"),
147        ("para one\nstill\n\npara two\n", 0, "} x"),
148        ("para one\nstill\n\npara two\n", 0, "d }"),
149        ("para one\nstill\n\npara two\n", 0, "d a p"),
150        ("para one\nstill\n\npara two\n", 0, "y i p G p"),
151        ("(a (b) c)\n", 0, "% x"),
152        ("one two\nthree four\n", 0, "j l l l k x"),
153        ("long line here\nab\nlonger line\n", 10, "j j x"),
154        ("one two three\n", 0, "s t h x"),
155        ("one two three\n", 12, "S t w x"),
156        ("ab ab ab ab\n", 0, "s a b ; ; x"),
157        ("ab ab ab ab\n", 0, "s a b ; ; , x"),
158        ("ab ab ab ab\n", 10, "S a b ; x"),
159        ("ab ab ab ab ab ab\n", 0, "2 s a b ; x"),
160        ("one tw tw tw\n", 0, "f w s t w ; x"),
161        ("one two three\n", 0, "\" a y w w \" a P"),
162        ("one two three\n", 0, "\" _ d w"),
163        ("  one\n", 2, "o x ESC"),
164        ("- item\n", 3, "o x ESC"),
165        ("- [ ] item\n", 3, "o x ESC"),
166        ("1. item\n", 3, "o x ESC"),
167        ("text\n- item\n", 8, "O x ESC"),
168        ("- item\n  more\n", 9, "o x ESC"),
169        ("* Heading\n", 3, "o x ESC"),
170        ("one two three\n", 0, "v e ~"),
171        ("one two three\n", 0, "v e U"),
172        ("one\ntwo\nthree\n", 0, "V j >"),
173        ("one\ntwo\nthree\n", 0, "v j J"),
174        ("one two three\n", 0, "y i w w v e p"),
175        ("a (b c) d\n", 0, "c i ( X ESC"),
176        ("one two\n", 4, "d a w"),
177        ("one   two\n", 4, "d i w"),
178        ("one two three four\n", 0, "d 2 a w"),
179        ("one two three\n", 4, "c $ X ESC"),
180        ("one two three\n", 8, "d 0"),
181        ("   one two\n", 8, "d ^"),
182        ("one\ntwo\nthree\n", 4, "d G"),
183        ("one\ntwo\nthree\n", 4, "d g g"),
184        ("one two three\n", 4, "y $ P"),
185        ("ab\n", 0, "x p"),
186        ("one\ntwo\n", 0, "d d p"),
187        ("abc\n", 1, "5 x"),
188        ("abcdef\n", 1, "3 r x"),
189        ("one two three four\n", 0, "x . ."),
190        ("one two three four five\n", 0, "d w 2 ."),
191        ("one   two\n", 3, "c w X ESC"),
192        ("aXbXcXd\n", 0, "2 f X x"),
193        ("one two three\n", 0, "w v $ d"),
194        ("one\ntwo\nthree\n", 0, "j V d p"),
195        ("x\n\n\ny\n", 0, "d }"),
196        ("one two\n", 0, "e a X ESC b ."),
197        ("one\n\nthree\n", 0, "j o x ESC"),
198        ("one two\n", 0, "g U U"),
199        ("a b\n", 0, "w i x ESC h ."),
200        ("one two three\n", 4, "c c X ESC"),
201        ("  one two\n", 4, "c c X ESC"),
202        ("one two\n", 0, "> >"),
203        ("    one two\n", 0, "< <"),
204        ("one two\n", 0, "i a b DEL c ESC"),
205        ("one two\n", 0, "i x C-w y ESC"),
206        ("one two\n", 3, "a X ESC . ."),
207        ("one\ntwo\n", 0, "A ; ESC j ."),
208        ("one two three\n", 0, "3 l v l d"),
209        ("one two three\n", 8, "v b d"),
210        ("one two three\n", 0, "v 2 e c X ESC"),
211        // evil-snipe-override-mode: f, F, t and T snipe one character, ; and , repeat over
212        // the visible text, and the snipe's own keys repeat it right after.
213        ("abc abc\nxbz abc\n", 0, "f c ; ; x"),
214        ("abc abc\nxbz abc\n", 0, "f c f f x"),
215        ("abc abc\nxbz abc\n", 0, "f c f F x"),
216        ("abc abc abc\n", 10, "F b f x"),
217        ("abc abc abc abc\n", 10, "F b F x"),
218        ("abc abc\nxbz abc\n", 14, "T a ; x"),
219        ("abc abc\nxbz abc\n", 0, "t c t x"),
220        ("abc abc\nxbz abc\n", 0, "f c l f c x"),
221        ("aAa\n", 0, "f a x"),
222        ("aAa\n", 0, "f A x"),
223        ("abab\n", 0, "t b x"),
224        ("ab ab\n", 4, "T a x"),
225        ("abc\nxbz\n", 2, "t z x"),
226        ("a  b c\n", 0, "f SPC x"),
227        ("a b\n", 0, "d f SPC"),
228        ("a b c\n", 0, "t SPC x"),
229        ("one two three\n", 0, "d t e"),
230        ("one two three\n", 0, "c f o X ESC"),
231        ("one two three\n", 12, "d F o"),
232        ("one two three\n", 12, "d T o"),
233        ("one two three\n", 0, "v f e d"),
234        ("one two three\n", 0, "v t e d"),
235        ("one two three\n", 0, "d f e ."),
236        ("a1a2a3a4a5a6\n", 0, "2 f a ; x"),
237        ("ab ab ab\n", 0, "s a b s S x"),
238        ("ab ab ab\n", 0, "s a b d ;"),
239        ("ab ab ab\n", 0, "v s a b d"),
240        ("ab x\ncd ab\nab\n", 5, "s a b ; , x"),
241        // A count after a snipe ends its repeat keys: the key snipes again with the count.
242        ("a1a2a3a4a5a6a7\n", 0, "f a 2 f a x"),
243        ("a1a2a3a4a5a6a7\n", 0, "f a f 2 f a x"),
244        ("a1a2a3a4a5a6a7\n", 0, "f a 2 ; x"),
245        ("a1a2a3a4a3\n", 0, "s a 2 2 s a 3 x"),
246        // evil-snipe-char-fold: a letter matches its variants, in either case unless typed
247        // as a capital.
248        ("x à b á c\n", 0, "f a ; x"),
249        ("x À b á c\n", 0, "f a x"),
250        ("x à b À c\n", 0, "f A x"),
251        ("x ü b ǜ c\n", 0, "f u ; x"),
252        ("x ⓐ a ª\n", 0, "f a ; ; x"),
253        ("x e\u{301}b\n", 0, "t b x"),
254        ("x e\u{301}b\n", 0, "t e x"),
255        ("x é b\n", 0, "s é SPC x"),
256        ("x é É\n", 0, "f É x"),
257        ("a\u{A0}b c\n", 0, "f SPC x"),
258        ("one fi fa\n", 0, "f f x"),
259    ]
260
261    /// Thirty lines of seven characters: line `i` starts at `7 * i`.
262    static let lines = (0..<30).map { String(format: "line%02d\n", $0) }.joined()
263
264    func driven(_ caret: Int, _ keys: String, halfPage: Int? = nil, visible: Range<Int>? = nil) -> Int {
265        var driver = VimDriver(Self.lines, caret: caret)
266        if let halfPage { driver.halfPage = halfPage }
267        driver.visible = visible
268        driver.type(Self.keys(keys))
269        return driver.caret
270    }
271
272    @Test func zzAndZqRunExCommands() {
273        var vim = Vim()
274        let context = Vim.Context(text: "a\n", caret: 0)
275        #expect(vim.feed(KeyChord("Z"), context) == [])
276        #expect(vim.feed(KeyChord("Z"), context) == [.ex("wq")])
277        _ = vim.feed(KeyChord("Z"), context)
278        #expect(vim.feed(KeyChord("Q"), context) == [.ex("q!")])
279    }
280
281    @Test func snipeRepeatsOverTheVisibleText() {
282        let text = "ab x\ncd ab\nab\n"
283        func caret(_ keys: String, visible: Range<Int>?) -> Int {
284            var driver = VimDriver(text, caret: 0)
285            driver.visible = visible
286            driver.type(Self.keys(keys))
287            return driver.caret
288        }
289        // The snipe itself keeps to the line; repeats search what the window shows.
290        #expect(caret("s a b ;", visible: nil) == 0)
291        #expect(caret("s a b ;", visible: 0..<14) == 8)
292        #expect(caret("s a b ; ;", visible: 0..<14) == 11)
293        #expect(caret("s a b ; ; ,", visible: 0..<14) == 8)
294        // After f, ; repeats the f.
295        #expect(caret("s a b f x ;", visible: 0..<14) == 3)
296    }
297
298    @Test func halfPageScrollsFollowTheWindow() {
299        #expect(driven(0, "C-d", halfPage: 5) == 35)
300        #expect(driven(70, "C-u", halfPage: 5) == 35)
301        #expect(driven(0, "C-d") == 105)
302        #expect(driven(0, "3 C-d", halfPage: 5) == 21)
303    }
304
305    @Test func windowLines() {
306        let shown = 70..<140
307        #expect(driven(0, "H", visible: shown) == 70)
308        #expect(driven(0, "3 H", visible: shown) == 84)
309        #expect(driven(0, "2 0 H", visible: shown) == 133)
310        #expect(driven(0, "L", visible: shown) == 133)
311        #expect(driven(0, "2 L", visible: shown) == 126)
312        #expect(driven(0, "M", visible: shown) == 98)
313        #expect(driven(3, "H") == 3)
314        // Linewise with an operator, and a jump.
315        var driver = VimDriver(Self.lines, caret: 70)
316        driver.visible = shown
317        driver.type(Self.keys("d L"))
318        #expect(driver.text == Self.lines.replacingOccurrences(of: (10..<20).map { String(format: "line%02d\n", $0) }.joined(), with: ""))
319        var vim = Vim()
320        let actions = vim.feed(KeyChord("L"), Vim.Context(text: Self.lines, caret: 70, visible: shown))
321        #expect(actions == [.jumped(from: 70), .move(caret: 133)])
322    }
323
324    /// Replace state, and evil-numbers on the keys Doom binds (`g=`, `g-`, visual `g=`, `g-`
325    /// and `g+`) and on `C-a`.
326    static let replaceAndNumbers: [(String, Int, String)] = [
327        ("hello world\n", 0, "R J E L ESC"),
328        ("hello\n", 3, "R a b c d ESC"),
329        ("hello world\n", 0, "R a b DEL DEL c ESC"),
330        ("hello world\n", 0, "3 R x y ESC"),
331        ("hello world\n", 2, "R a RET b ESC"),
332        ("aaaa bbbb\n", 0, "R x y ESC w ."),
333        ("item 7 and 12\n", 0, "g ="),
334        ("item 7 and 12\n", 6, "5 g ="),
335        ("item 7 and 12\n", 6, "g -"),
336        ("value -3 here\n", 0, "4 g ="),
337        ("count 009\n", 0, "g ="),
338        ("count 010\n", 0, "g -"),
339        ("addr 0xff\n", 0, "g ="),
340        ("addr 0xFE\n", 0, "g ="),
341        ("bits 0b0111\n", 0, "g ="),
342        ("no digits\n", 0, "g ="),
343        ("1\n1\n1\n", 0, "V j j g ="),
344        ("1\n1\n1\n", 0, "V j j g +"),
345        ("a 1 b 2\nc 3\n", 0, "V j 2 g -"),
346        ("x 1 y\n", 0, "C-a"),
347        ("x 1 y 2\n", 4, "3 C-a"),
348    ]
349
350    @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
351    func replaceAndNumbersMatchEvil() throws {
352        let repos = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".config/emacs/.local/straight/repos")
353        guard FileManager.default.fileExists(atPath: repos.appendingPathComponent("evil-numbers/evil-numbers.el").path) else { return }
354        var forms: [EmacsOracle.Case] = []
355        for (text, point, keys) in Self.replaceAndNumbers {
356            forms.append(EmacsOracle.Case(text: text, point: point + 1, form: """
357            (progn
358              (setq evil-want-Y-yank-to-eol t evil-undo-system 'undo-redo)
359              (dolist (p '("evil" "goto-chg" "evil-numbers" "emacs-shift-number")) (add-to-list 'load-path (concat "\(repos.path)/" p)))
360              (require 'evil)
361              (require 'evil-numbers)
362              (evil-define-key 'normal 'global (kbd "g=") #'evil-numbers/inc-at-pt (kbd "g-") #'evil-numbers/dec-at-pt (kbd "C-a") #'evil-numbers/inc-at-pt)
363              (evil-define-key 'visual 'global (kbd "g=") #'evil-numbers/inc-at-pt-incremental (kbd "g-") #'evil-numbers/dec-at-pt-incremental (kbd "g+") #'evil-numbers/inc-at-pt)
364              (switch-to-buffer (current-buffer))
365              (evil-local-mode 1)
366              (evil-normal-state)
367              (execute-kbd-macro (kbd "\(keys.replacingOccurrences(of: "ESC", with: "<escape>").replacingOccurrences(of: "DEL", with: "DEL"))"))
368              (let ((p (point)) (s evil-state))
369                (goto-char (point-max))
370                (insert (format "\\n@@STATE %s" s))
371                (goto-char p)))
372            """))
373        }
374        let results = try EmacsOracle.run(forms)
375        for ((text, point, keys), result) in zip(Self.replaceAndNumbers, results) {
376            var driver = VimDriver(text, caret: point)
377            driver.visible = 0..<text.utf16.count
378            driver.type(Self.keys(keys))
379            guard let marker = result.text.range(of: "\n@@STATE ") else {
380                Issue.record("\(keys): \(result.error)")
381                continue
382            }
383            let emacsText = String(result.text[..<marker.lowerBound])
384            let state = String(result.text[marker.upperBound...])
385            let ours = driver.vim.mode == .normal ? "normal" : driver.vim.mode.rawValue
386            let emacsCaret = EmacsOracle.offset(result.point, in: result.text)
387            #expect(driver.text == emacsText && driver.caret == emacsCaret && ours == state,
388                    "\(keys.debugDescription) on \(text.debugDescription) at \(point)\nours:  \(driver.text.debugDescription) @\(driver.caret) \(ours)\nevil:  \(emacsText.debugDescription) @\(emacsCaret) \(state) \(result.error)")
389        }
390    }
391
392    @Test func scrollsAndOpensTheCommandWindow() {
393        var vim = Vim()
394        let text = "one\n  two\nthree\n"
395        #expect(vim.feed(KeyChord("z"), Vim.Context(text: text, caret: 0)) == [])
396        #expect(vim.feed(KeyChord("z"), Vim.Context(text: text, caret: 0)) == [.scroll(.center)])
397        _ = vim.feed(KeyChord("2"), Vim.Context(text: text, caret: 0))
398        _ = vim.feed(KeyChord("z"), Vim.Context(text: text, caret: 0))
399        #expect(vim.feed(KeyChord("RET"), Vim.Context(text: text, caret: 0)) == [.move(caret: 6), .scroll(.top)])
400        _ = vim.feed(KeyChord("q"), Vim.Context(text: text, caret: 0))
401        #expect(vim.feed(KeyChord(":"), Vim.Context(text: text, caret: 0)) == [.commandWindow(":")])
402    }
403
404    @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
405    func matchesEvil() throws {
406        let evil = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".config/emacs/.local/straight/repos")
407        guard FileManager.default.fileExists(atPath: evil.appendingPathComponent("evil/evil.el").path) else { return }
408        var forms: [EmacsOracle.Case] = []
409        for (text, point, keys) in Self.cases {
410            forms.append(EmacsOracle.Case(text: text, point: point + 1, form: """
411            (progn
412              (setq evil-want-Y-yank-to-eol t evil-undo-system 'undo-redo evil-want-C-w-delete t evil-want-C-u-delete t evil-shift-width 8)
413              (add-to-list 'load-path "\(evil.path)/evil")
414              (add-to-list 'load-path "\(evil.path)/goto-chg")
415              (add-to-list 'load-path "\(evil.path)/evil-snipe")
416              (require 'evil)
417              (require 'evil-snipe)
418              (setq evil-snipe-smart-case t evil-snipe-scope 'line evil-snipe-repeat-scope 'visible evil-snipe-char-fold t)
419              (setq kill-ring nil)
420              (switch-to-buffer (current-buffer))
421              (evil-local-mode 1)
422              (evil-snipe-local-mode 1)
423              (evil-snipe-override-local-mode 1)
424              (evil-normal-state)
425              (execute-kbd-macro (kbd "\(keys.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\"").replacingOccurrences(of: "ESC", with: "<escape>").replacingOccurrences(of: "DEL", with: "DEL"))"))
426              (let ((p (point)) (s evil-state))
427                (goto-char (point-max))
428                (insert (format "\\n@@STATE %s" s))
429                (goto-char p)))
430            """))
431        }
432        let results = try EmacsOracle.run(forms)
433        for ((text, point, keys), result) in zip(Self.cases, results) {
434            var driver = VimDriver(text, caret: point)
435            // A batch Emacs window shows the whole buffer.
436            driver.visible = 0..<text.utf16.count
437            driver.type(Self.keys(keys))
438            guard let marker = result.text.range(of: "\n@@STATE ") else {
439                Issue.record("\(keys): \(result.error)")
440                continue
441            }
442            let emacsText = String(result.text[..<marker.lowerBound])
443            let state = String(result.text[marker.upperBound...])
444            let ours = driver.vim.mode == .insert ? "insert" : driver.vim.mode == .normal ? "normal" : "visual"
445            let emacsCaret = EmacsOracle.offset(result.point, in: result.text)
446            #expect(driver.text == emacsText && driver.caret == emacsCaret && ours == state,
447                    "\(keys.debugDescription) on \(text.debugDescription) at \(point)\nours:  \(driver.text.debugDescription) @\(driver.caret) \(ours)\nevil:  \(emacsText.debugDescription) @\(emacsCaret) \(state) \(result.error)")
448        }
449    }
450}