mopac-pdf v0: markdown to beautiful PDFs via digest-pinned typst
Go CLI that turns the markdown currency of this stack (Redmine notes, Discourse posts, briefing output) into typeset PDFs: two embedded typst templates (report with title page/TOC/headers, dense brief), front-matter (title/subtitle/author/date/classification/template), GFM tables, and bar charts rendered in pure Go (go-chart) from fenced chart data blocks. Engine is a prebuilt typst 0.15.1 container pinned by digest and run --network none; PDF bytes to stdout or -o. Exit codes 0/1/2. All dev in docker (dev.sh/Makefile); unit tests + golden typst fixtures plus a host-side smoke against the real engine container. Generated with Crush Assisted-by: Crush:glm-5.2
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package frontmatter
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSplitFull(t *testing.T) {
|
||||
meta, body, err := Split("---\ntitle: Q3 Brief\nsubtitle: Ops\nclassification: INTERNAL\ntemplate: brief\nauthor: A B\ndate: 2026-08-29\nextra: kept\n---\n\n# Body\n")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if meta.Title != "Q3 Brief" || meta.Subtitle != "Ops" || meta.Classification != "INTERNAL" ||
|
||||
meta.Template != "brief" || meta.Author != "A B" || meta.Date != "2026-08-29" {
|
||||
t.Fatalf("meta: %+v", meta)
|
||||
}
|
||||
if meta.Extra["extra"] != "kept" {
|
||||
t.Fatalf("extra keys dropped: %+v", meta.Extra)
|
||||
}
|
||||
if body != "# Body\n" {
|
||||
t.Fatalf("body: %q", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitQuoted(t *testing.T) {
|
||||
meta, _, err := Split("---\ntitle: \"The: Quoted Title\"\n---\nx")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if meta.Title != "The: Quoted Title" {
|
||||
t.Fatalf("title: %q", meta.Title)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitNone(t *testing.T) {
|
||||
meta, body, err := Split("# Just markdown\n\nBody.")
|
||||
if err != nil || meta.Title != "" || body != "# Just markdown\n\nBody." {
|
||||
t.Fatalf("meta=%+v body=%q err=%v", meta, body, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitUnclosed(t *testing.T) {
|
||||
_, _, err := Split("---\ntitle: x\n")
|
||||
if err == nil {
|
||||
t.Fatal("want error for unclosed block")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitBadLine(t *testing.T) {
|
||||
_, _, err := Split("---\nnope\n---\n")
|
||||
if err == nil {
|
||||
t.Fatal("want error for non key: value line")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitCommentsBlank(t *testing.T) {
|
||||
_, body, err := Split("---\n# comment\n\ntitle: t\n---\nbody here")
|
||||
if err != nil || body != "body here" {
|
||||
t.Fatalf("body=%q err=%v", body, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user