blob: 13bad670d874abef9659273d3289ffbb80eb6a30 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import Foundation
import Testing
@testable import NorgKit
struct NorgDocumentTests {
@Test func defaultsToEmptyBlocks() {
#expect(NorgDocument().blocks.isEmpty)
}
@Test func treeFoldsBlocksIntoNodes() {
let doc = NorgDocument(blocks: [
.heading(level: 1, status: nil, content: [InlineSpan(text: "H")], line: 0),
.paragraph(content: [InlineSpan(text: "body")], line: 1),
])
let tree = doc.tree()
#expect(tree.count == 1)
#expect(tree.first?.children.count == 1)
}
@Test func treeMatchesTreeFolderOutput() {
let doc = NorgParser.parse("* H\n- a\n-- b")
#expect(doc.tree() == TreeFolder(doc.blocks).fold())
}
@Test func roundTripsThroughJSON() throws {
let doc = NorgParser.parse("* H\nbody\n- ( ) task")
let data = try JSONEncoder().encode(doc)
#expect(try JSONDecoder().decode(NorgDocument.self, from: data) == doc)
}
}
|