import lib // Snapshot tests: verify complete parse output against golden values // Snapshot: full blog post parse fn test_snapshot_blog_post(): Unit with {Test} = { let input = "---\ntitle: Understanding Algebraic Effects\ndate: 2025-03-15\ndescription: A deep dive into effect systems\ntags: lux effects programming\nauthor: Brandon\nlayout: post\n---\n# Understanding Algebraic Effects\n\nAlgebraic effects are a powerful way to handle side effects.\n\n## What are they?\n\nThey let you declare what effects your code uses." let doc = lib.parse(input) Test.assertEqualMsg("Understanding Algebraic Effects", lib.title(doc), "snap: title") Test.assertEqualMsg("2025-03-15", lib.date(doc), "snap: date") Test.assertEqualMsg("A deep dive into effect systems", lib.description(doc), "snap: description") Test.assertEqualMsg(3, List.length(lib.tags(doc)), "snap: tag count") Test.assertEqualMsg("Brandon", lib.getOrDefault(doc, "author", ""), "snap: author") Test.assertEqualMsg("post", lib.getOrDefault(doc, "layout", ""), "snap: layout") Test.assertEqualMsg(6, List.length(lib.entries(doc)), "snap: entry count") Test.assert(String.startsWith(lib.body(doc), "# Understanding"), "snap: body starts with heading") Test.assert(String.contains(lib.body(doc), "## What are they?"), "snap: body contains subheading") } // Snapshot: minimal frontmatter fn test_snapshot_minimal(): Unit with {Test} = { let input = "---\ntitle: Hello\n---\nWorld" let doc = lib.parse(input) Test.assertEqualMsg("Hello", lib.title(doc), "snap: minimal title") Test.assertEqualMsg("", lib.date(doc), "snap: minimal no date") Test.assertEqualMsg("", lib.description(doc), "snap: minimal no description") Test.assertEqualMsg(0, List.length(lib.tags(doc)), "snap: minimal no tags") Test.assertEqualMsg(1, List.length(lib.entries(doc)), "snap: minimal one entry") Test.assert(String.startsWith(lib.body(doc), "World"), "snap: minimal body") } // Snapshot: no frontmatter at all fn test_snapshot_no_frontmatter(): Unit with {Test} = { let input = "This is just plain text.\nNo frontmatter here." let doc = lib.parse(input) Test.assertEqualMsg(false, lib.hasFrontmatter(doc), "snap: no frontmatter") Test.assertEqualMsg("", lib.title(doc), "snap: no fm title") Test.assertEqualMsg("", lib.date(doc), "snap: no fm date") Test.assertEqualMsg(0, List.length(lib.entries(doc)), "snap: no fm entries") } // Snapshot: quoted values with various quote styles fn test_snapshot_quoted_values(): Unit with {Test} = { let input = "---\ntitle: \"Double Quoted: Title\"\nsubtitle: 'Single Quoted: Subtitle'\nplain: Just a plain value\n---\nBody" let doc = lib.parse(input) Test.assertEqualMsg("Double Quoted: Title", lib.title(doc), "snap: double-quoted") Test.assertEqualMsg("Single Quoted: Subtitle", lib.getOrDefault(doc, "subtitle", ""), "snap: single-quoted") Test.assertEqualMsg("Just a plain value", lib.getOrDefault(doc, "plain", ""), "snap: unquoted") } // Snapshot: document with many entries fn test_snapshot_many_entries(): Unit with {Test} = { let input = "---\ntitle: Complex Post\ndate: 2025-06-01\ndescription: A complex post\ntags: a b c d e\nauthor: Alice\nlayout: page\ncategory: tech\nslug: complex-post\ndraft: false\nweight: 42\n---\nBody content here." let doc = lib.parse(input) Test.assertEqualMsg(10, List.length(lib.entries(doc)), "snap: ten entries") Test.assertEqualMsg("Complex Post", lib.title(doc), "snap: title") Test.assertEqualMsg("2025-06-01", lib.date(doc), "snap: date") Test.assertEqualMsg(5, List.length(lib.tags(doc)), "snap: five tags") Test.assertEqualMsg("Alice", lib.getOrDefault(doc, "author", ""), "snap: author") Test.assertEqualMsg("page", lib.getOrDefault(doc, "layout", ""), "snap: layout") Test.assertEqualMsg("tech", lib.getOrDefault(doc, "category", ""), "snap: category") Test.assertEqualMsg("complex-post", lib.getOrDefault(doc, "slug", ""), "snap: slug") Test.assertEqualMsg("false", lib.getOrDefault(doc, "draft", ""), "snap: draft") Test.assertEqualMsg("42", lib.getOrDefault(doc, "weight", ""), "snap: weight") } // Snapshot: entry iteration order fn test_snapshot_entry_order(): Unit with {Test} = { let input = "---\nfirst: 1\nsecond: 2\nthird: 3\n---\n" let doc = lib.parse(input) let es = lib.entries(doc) match List.head(es) { Some(e) => { Test.assertEqualMsg("first", lib.entryKey(e), "snap: first entry key") Test.assertEqualMsg("1", lib.entryValue(e), "snap: first entry value") }, None => Test.assert(false, "snap: should have entries"), } }