Tests/OrgEditorAppKitTests/PlainModeTests.swift
36 lines · 1273 bytes
4 symbols in this file
1import AppKit
2import OrgCore
3import OrgDocument
4import Testing
5@testable import OrgEditorAppKit
6
7/// Files that aren't org: plain text, without org styling, folding or commands.
8@MainActor
9struct PlainModeTests {
10 func plain(_ text: String) -> Harness {
11 let h = Harness(DocumentState(bytes: Array(text.utf8)), mode: .plain(language: nil))
12 h.drainStyling()
13 h.layout()
14 return h
15 }
16
17 @Test func orgCommandsDoNothing() {
18 let h = plain("* TODO Not a heading\n")
19 var messages: [String] = []
20 h.editor.onMessage = { messages.append($0) }
21 h.caret(at: 2)
22 h.editor.run("org.todo.cycle")
23 #expect(h.editor.document.text == "* TODO Not a heading\n")
24 #expect(messages == ["Not an org file"])
25 KeyTests().send(h, characters: "\t", ignoring: "\t", code: 48)
26 #expect(h.editor.document.text == "* \tTODO Not a heading\n")
27 }
28
29 @Test func noOrgStyling() {
30 let h = plain("* Heading *bold*\n")
31 let org = Harness("* Heading *bold*\n")
32 let font = { (h: Harness) in h.textView.textStorage!.attribute(.font, at: 2, effectiveRange: nil) as? NSFont }
33 #expect(font(h) == h.editor.theme.font)
34 #expect(font(org) != org.editor.theme.font)
35 }
36}