Tests/OrgCoreTests/LinesTests.swift
66 lines · 2317 bytes
5 symbols in this file
1import Testing
2@testable import OrgCore
3
4struct LinesTests {
5 @Test func splitKeepsEveryEnding() {
6 let lines = splitRawLines("a\r\nb\n\nc")
7 #expect(lines.map { String($0.content) } == ["a", "b", "", "c"])
8 #expect(lines.map { String($0.ending) } == ["\r\n", "\n", "\n", ""])
9 #expect(splitRawLines("").isEmpty)
10 #expect(splitRawLines("x\n").count == 1)
11 }
12
13 @Test func splitIsLossless() {
14 let text = "\r\n\n a\r b\r\n😀\n"
15 #expect(splitRawLines(text).map { String($0.content) + String($0.ending) }.joined() == text)
16 }
17
18 @Test(arguments: [
19 ("", LineClass.blank),
20 (" \t", .blank),
21 ("* a", .heading(level: 1)),
22 ("*** ", .heading(level: 3)),
23 ("*", .plain),
24 ("*\ttab", .plain),
25 ("* ", .heading(level: 1)),
26 ("*bold* text", .plain),
27 (" * a", .listItem),
28 ("#+BEGIN_SRC sh :results output", .blockBegin(name: "src")),
29 ("#+end_src", .blockEnd(name: "src")),
30 ("#+BEGIN: clocktable :scope file", .dynamicBegin),
31 ("#+END:", .dynamicEnd),
32 ("#+TITLE: x", .keyword(key: "TITLE")),
33 ("#+tblfm: $2=$1", .keyword(key: "TBLFM")),
34 ("# comment", .comment),
35 ("#", .comment),
36 ("#hashtag", .plain),
37 (": fixed", .fixedWidth),
38 (":", .fixedWidth),
39 (":PROPERTIES:", .drawerBegin(name: "PROPERTIES")),
40 (" :LOGBOOK:", .drawerBegin(name: "LOGBOOK")),
41 (":END:", .drawerEnd),
42 ("| a | b |", .tableRow),
43 ("-----", .horizontalRule),
44 ("----", .plain),
45 ("[fn:1] note", .footnoteDefinition),
46 ("CLOCK: [2026-10-04 Sun 10:00]", .clock),
47 ("SCHEDULED: <2026-10-04 Sun>", .planning),
48 ("- item", .listItem),
49 ("+ item", .listItem),
50 ("1. item", .listItem),
51 ("2) item", .listItem),
52 ("-", .listItem),
53 ("-x", .plain),
54 ("1.5 apples", .plain),
55 ("plain text", .plain),
56 ])
57 func classify(line: String, expected: LineClass) {
58 #expect(classifyLine(line[...]).cls == expected)
59 }
60
61 @Test func indentCountsTabsToEight() {
62 #expect(classifyLine("\t- a").indent == 8)
63 #expect(classifyLine(" \t- a").indent == 8)
64 #expect(classifyLine(" - a").indent == 3)
65 }
66}