diff options
Diffstat (limited to 'Tests/NorgKitTests/Models/NorgDocumentTests.swift')
| -rw-r--r-- | Tests/NorgKitTests/Models/NorgDocumentTests.swift | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Tests/NorgKitTests/Models/NorgDocumentTests.swift b/Tests/NorgKitTests/Models/NorgDocumentTests.swift new file mode 100644 index 0000000..13bad67 --- /dev/null +++ b/Tests/NorgKitTests/Models/NorgDocumentTests.swift @@ -0,0 +1,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) + } +} |