import lib // Integration tests: realistic document processing workflows // Parse a complete blog post and extract all metadata fn test_complete_blog_post(): Unit with {Test} = { let content = "---\ntitle: My First Post\ndate: 2025-01-29\ndescription: A great introduction\ntags: web lux programming\nauthor: Brandon\n---\nThis is the body of my post.\n\nIt has multiple paragraphs." let doc = lib.parse(content) Test.assertEqualMsg(true, lib.hasFrontmatter(doc), "has frontmatter") Test.assertEqualMsg("My First Post", lib.title(doc), "title") Test.assertEqualMsg("2025-01-29", lib.date(doc), "date") Test.assertEqualMsg("A great introduction", lib.description(doc), "description") Test.assertEqualMsg(3, List.length(lib.tags(doc)), "tag count") Test.assertEqualMsg("Brandon", lib.getOrDefault(doc, "author", ""), "author field") Test.assert(String.startsWith(lib.body(doc), "This is the body"), "body starts correctly") } // Parse multiple documents and compare metadata fn test_parse_multiple_documents(): Unit with {Test} = { let doc1 = lib.parse("---\ntitle: Post A\ndate: 2025-01-01\n---\nBody A") let doc2 = lib.parse("---\ntitle: Post B\ndate: 2025-02-01\n---\nBody B") let doc3 = lib.parse("---\ntitle: Post C\ndate: 2025-03-01\n---\nBody C") Test.assertEqualMsg("Post A", lib.title(doc1), "doc1 title") Test.assertEqualMsg("Post B", lib.title(doc2), "doc2 title") Test.assertEqualMsg("Post C", lib.title(doc3), "doc3 title") Test.assertEqualMsg(true, lib.hasFrontmatter(doc1), "doc1 has frontmatter") Test.assertEqualMsg(true, lib.hasFrontmatter(doc2), "doc2 has frontmatter") } // Simulate a static site generator reading a page fn test_ssg_page_workflow(): Unit with {Test} = { let page = "---\ntitle: About Me\ndescription: Learn about the author\nlayout: page\n---\n# About\n\nI write software." let doc = lib.parse(page) let pageTitle = lib.title(doc) let pageDesc = lib.description(doc) let layout = lib.getOrDefault(doc, "layout", "default") let body = lib.body(doc) Test.assertEqualMsg("About Me", pageTitle, "page title") Test.assertEqualMsg("Learn about the author", pageDesc, "page description") Test.assertEqualMsg("page", layout, "layout field") Test.assert(String.startsWith(body, "# About"), "body starts with heading") } // Extract custom fields beyond the standard ones fn test_custom_fields(): Unit with {Test} = { let doc = lib.parse("---\ntitle: Post\nslug: custom-slug\ndraft: true\nweight: 10\n---\nContent") Test.assertEqualMsg("custom-slug", lib.getOrDefault(doc, "slug", ""), "custom slug field") Test.assertEqualMsg("true", lib.getOrDefault(doc, "draft", "false"), "custom draft field") Test.assertEqualMsg("10", lib.getOrDefault(doc, "weight", "0"), "custom weight field") } // Iterate over entries and collect all keys fn test_iterate_entries(): Unit with {Test} = { let doc = lib.parse("---\na: 1\nb: 2\nc: 3\n---\nBody") let es = lib.entries(doc) Test.assertEqualMsg(3, List.length(es), "three entries") match List.head(es) { Some(e) => Test.assertEqualMsg("a", lib.entryKey(e), "first entry key"), None => Test.assert(false, "should have entries"), } } // Document with frontmatter but no body fn test_frontmatter_only_document(): Unit with {Test} = { let doc = lib.parse("---\ntitle: Metadata Only\ntags: meta\n---") Test.assertEqualMsg("Metadata Only", lib.title(doc), "title from frontmatter-only doc") Test.assertEqualMsg(1, List.length(lib.tags(doc)), "one tag") Test.assertEqualMsg("", lib.body(doc), "empty body") } // Document with all convenience fields fn test_all_convenience_fields(): Unit with {Test} = { let doc = lib.parse("---\ntitle: Full Post\ndate: 2025-06-15\ndescription: Complete metadata\ntags: a b c d\n---\nBody text") Test.assertEqualMsg("Full Post", lib.title(doc), "title convenience") Test.assertEqualMsg("2025-06-15", lib.date(doc), "date convenience") Test.assertEqualMsg("Complete metadata", lib.description(doc), "description convenience") Test.assertEqualMsg(4, List.length(lib.tags(doc)), "tags convenience") } // Fallback behavior when fields are missing fn test_missing_field_defaults(): Unit with {Test} = { let doc = lib.parse("---\ntitle: Minimal\n---\nBody") Test.assertEqualMsg("Minimal", lib.title(doc), "title present") Test.assertEqualMsg("", lib.date(doc), "date defaults to empty") Test.assertEqualMsg("", lib.description(doc), "description defaults to empty") Test.assertEqualMsg(0, List.length(lib.tags(doc)), "tags defaults to empty") }