Tests/OrgCoreTests/LispReaderTests.swift
40 lines · 2110 bytes
3 symbols in this file
1import Foundation
2import Testing
3@testable import OrgCore
4
5struct LispReaderTests {
6 @Test func readsForms() throws {
7 let text = #"""
8 ;; comment
9 (setq org-tags-column -77 ; inline
10 fill-column 80)
11 (after! org (setq org-agenda-start-day "-3d\n" x 1.5 c ?a d ?\C-x))
12 (map! :leader :desc "Save" "f s" #'save-buffer)
13 '(a . b) `(x ,y ,@z) [1 2] nil
14 """#
15 let forms = try LispReader.read(text)
16 #expect(forms.map(\.line) == [2, 4, 5, 6, 6, 6, 6])
17 #expect(forms[0].sexp == .list([.symbol("setq"), .symbol("org-tags-column"), .integer(-77), .symbol("fill-column"), .integer(80)]))
18 #expect(forms[1].sexp.description == "(after! org (setq org-agenda-start-day \"-3d\\n\" x 1.5 c ?a d ?x))")
19 #expect(forms[2].sexp.elements?.last == .list([.symbol("function"), .symbol("save-buffer")]))
20 #expect(forms[3].sexp == .list([.symbol("quote"), .dotted([.symbol("a")], .symbol("b"))]))
21 #expect(forms[4].sexp.description == "`(x ,y ,@z)")
22 #expect(forms[5].sexp == .vector([.integer(1), .integer(2)]))
23 #expect(throws: LispReader.ReadError.self) { try LispReader.read("(setq a") }
24 }
25
26 /// Every Lisp file of the installed Doom Emacs and the user's Doom config reads.
27 @Test(.enabled(if: FileManager.default.fileExists(atPath: NSHomeDirectory() + "/.config/emacs/lisp")))
28 func readsDoom() throws {
29 var failures: [String] = []
30 for folder in ["/.config/emacs/lisp", "/.config/emacs/modules/lang/org", "/.config/doom"] {
31 guard let files = FileManager.default.enumerator(atPath: NSHomeDirectory() + folder) else { continue }
32 for case let file as String in files where file.hasSuffix(".el") {
33 let path = NSHomeDirectory() + folder + "/" + file
34 guard let text = try? String(contentsOfFile: path, encoding: .utf8) else { continue }
35 do { _ = try LispReader.read(text) } catch { failures.append("\(path): \(error)") }
36 }
37 }
38 #expect(failures.isEmpty, "\(failures)")
39 }
40}