aboutsummaryrefslogtreecommitdiff
path: root/Tests/NorgKitTests/Models/NorgDocumentTests.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <jj@r.bdr.sh>2026-06-16 12:08:21 +0200
committerRuben Beltran del Rio <jj@r.bdr.sh>2026-06-16 12:22:47 +0200
commit501fdce29e4d2c46c4708ad7f44056878e0db3fa (patch)
treedb923b77037db9f5b37600a6e34c3bb2e8a971be /Tests/NorgKitTests/Models/NorgDocumentTests.swift
Initial extraction from Norganize1.0.0
Diffstat (limited to 'Tests/NorgKitTests/Models/NorgDocumentTests.swift')
-rw-r--r--Tests/NorgKitTests/Models/NorgDocumentTests.swift32
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)
+ }
+}