Tests/OrgPresentationTests/SpellCheckTests.swift
39 lines · 1225 bytes
1import Foundation
2import Testing
3import OrgCore
4@testable import OrgPresentation
5
6struct SpellCheckTests {
7 /// The words left for the spell checker.
8 func checked(_ text: String) -> [String] {
9 let skipped = SpellCheck.skipped(OrgParser.parse(text))
10 let ns = text as NSString
11 var words: [String] = []
12 ns.enumerateSubstrings(in: NSRange(location: 0, length: ns.length), options: .byWords) { word, range, _, _ in
13 if !skipped.contains(where: { $0.contains(range.location) }) { words.append(word!) }
14 }
15 return words
16 }
17
18 @Test func skipsMarkupAndCode() {
19 let text = """
20 #+TITLE: Speling
21 * TODO [#A] Headng wurd :tagg:
22 SCHEDULED: <2026-10-06 Tue>
23 :PROPERTIES:
24 :ID: abcxyz
25 :END:
26 Prose ~codez~ =verbz= [[https://x.org][desc]] <2026-01-01> wurds.
27 - [ ] itemm
28 #+begin_src sh
29 ecko
30 #+end_src
31 #+begin_quote
32 quotd
33 #+end_quote
34 : fixd
35 $x^2$ \\alpha
36 """ + "\n"
37 #expect(checked(text) == ["Headng", "wurd", "Prose", "wurds", "itemm", "quotd"])
38 }
39}