import lib // Snapshot tests: compare full XML output against golden strings // Snapshot: simple HTML page fn test_snapshot_html_page(): Unit with {Test} = { let page = lib.el("html", [ lib.el("head", [lib.textEl("title", "Test")]), lib.el("body", [lib.textEl("p", "Hello")]) ]) let expected = "Test

Hello

" Test.assertEqualMsg(expected, lib.render(page), "snap: HTML page") } // Snapshot: self-closing tags fn test_snapshot_self_closing(): Unit with {Test} = { let node = lib.el("head", [ lib.selfClosing("meta", [lib.attr("charset", "utf-8")]), lib.selfClosing("link", [lib.attr("rel", "stylesheet"), lib.attr("href", "/css/main.css")]) ]) let expected = "" Test.assertEqualMsg(expected, lib.render(node), "snap: self-closing tags") } // Snapshot: XML document with declaration fn test_snapshot_xml_document(): Unit with {Test} = { let root = lib.el("config", [ lib.textEl("name", "MyApp"), lib.textEl("version", "1.0") ]) let expected = "\nMyApp1.0" Test.assertEqualMsg(expected, lib.document(root), "snap: XML document") } // Snapshot: element with escaped content fn test_snapshot_escaped_content(): Unit with {Test} = { let node = lib.textEl("message", "Hello & \"everyone\"") let expected = "Hello <world> & "everyone"" Test.assertEqualMsg(expected, lib.render(node), "snap: escaped content") } // Snapshot: CDATA section fn test_snapshot_cdata(): Unit with {Test} = { let node = lib.el("script", [lib.cdata("if (a < b && c > d) then run()")]) let expected = "" Test.assertEqualMsg(expected, lib.render(node), "snap: CDATA in script") } // Snapshot: mixed node types fn test_snapshot_mixed_nodes(): Unit with {Test} = { let node = lib.el("content", [ lib.text("Normal "), lib.raw("
"), lib.text(" text & "), lib.cdata("") ]) let expected = "Normal
text & ]]>
" Test.assertEqualMsg(expected, lib.render(node), "snap: mixed node types") } // Snapshot: deeply nested structure fn test_snapshot_deep_nesting(): Unit with {Test} = { let node = lib.el("l1", [lib.el("l2", [lib.el("l3", [lib.el("l4", [lib.el("l5", [lib.text("deep")])])])])]) let expected = "deep" Test.assertEqualMsg(expected, lib.render(node), "snap: 5-level nesting") } // Snapshot: attribute escaping fn test_snapshot_attr_escaping(): Unit with {Test} = { let node = lib.selfClosing("div", [ lib.attr("title", "a \"test\" & "), lib.attr("class", "a&b") ]) let expected = "
" Test.assertEqualMsg(expected, lib.render(node), "snap: attribute escaping") } // Snapshot: empty elements fn test_snapshot_empty_elements(): Unit with {Test} = { Test.assertEqualMsg("
", lib.render(lib.el("br", [])), "snap: empty el") Test.assertEqualMsg("
", lib.render(lib.selfClosing("hr", [])), "snap: selfClosing") Test.assertEqualMsg("

", lib.render(lib.textEl("p", "")), "snap: textEl with empty content") } // Snapshot: sitemap entry fn test_snapshot_sitemap_entry(): Unit with {Test} = { let url = lib.el("url", [ lib.textEl("loc", "https://example.com/page"), lib.textEl("lastmod", "2025-01-29"), lib.textEl("changefreq", "weekly"), lib.textEl("priority", "0.8") ]) let expected = "https://example.com/page2025-01-29weekly0.8" Test.assertEqualMsg(expected, lib.render(url), "snap: sitemap URL entry") }