AtlatestRepositoryfolio
1
(import (sigil test)2
(sigil string)3
(folio frontmatter))5
;; ============================================================6
;; read-frontmatter7
;; ============================================================9
(test-group "read-frontmatter"10
(test "basic frontmatter"11
(let-values (((fm body) (read-frontmatter "---\nstatus: active\ngoal: Test\n---\n# Content\n\nBody text")))12
(assert-equal "active" (dict-ref fm status:))13
(assert-equal "Test" (dict-ref fm goal:))14
(assert-true (string-contains? body "# Content"))))16
(test "no frontmatter"17
(let-values (((fm body) (read-frontmatter "# Just a heading\n\nSome text")))18
(assert-equal (dict) fm)19
(assert-true (string-starts-with? body "# Just a heading"))))21
(test "empty frontmatter"22
(let-values (((fm body) (read-frontmatter "---\n---\nBody")))23
(assert-equal (dict) fm)24
(assert-equal "Body" body)))26
(test "frontmatter with list tags"27
(let-values (((fm body) (read-frontmatter "---\ntags: [sigil, folio]\n---\nBody")))28
(assert-true (list? (dict-ref fm tags:)))29
(assert-equal 2 (length (dict-ref fm tags:))))))31
;; ============================================================32
;; write-frontmatter33
;; ============================================================35
(test-group "write-frontmatter"36
(test "produces valid frontmatter"37
(let ((result (write-frontmatter (dict status: "active") "# Body\n")))38
(assert-true (string-starts-with? result "---\n"))39
(assert-true (string-contains? result "status: active"))40
(assert-true (string-contains? result "# Body")))))42
;; ============================================================43
;; roundtrip44
;; ============================================================46
(test-group "frontmatter roundtrip"47
(test "read then write preserves content"48
(let ((original "---\nstatus: active\ngoal: Build folio\n---\n# Project\n\nSome body text\n"))49
(let-values (((fm body) (read-frontmatter original)))50
(let ((result (write-frontmatter fm body)))51
(let-values (((fm2 body2) (read-frontmatter result)))52
(assert-equal (dict-ref fm status:) (dict-ref fm2 status:))53
(assert-equal (dict-ref fm goal:) (dict-ref fm2 goal:))54
(assert-true (string-contains? body2 "Some body text"))))))))