Sync local packages into the registry repo and update index.json and README.md to include all 9 packages.
96 lines
4.0 KiB
Plaintext
96 lines
4.0 KiB
Plaintext
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 = "<html><head><title>Test</title></head><body><p>Hello</p></body></html>"
|
|
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 = "<head><meta charset=\"utf-8\"/><link rel=\"stylesheet\" href=\"/css/main.css\"/></head>"
|
|
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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<config><name>MyApp</name><version>1.0</version></config>"
|
|
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 <world> & \"everyone\"")
|
|
let expected = "<message>Hello <world> & "everyone"</message>"
|
|
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 = "<script><![CDATA[if (a < b && c > d) then run()]]></script>"
|
|
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("<br/>"),
|
|
lib.text(" text & "),
|
|
lib.cdata("<special>")
|
|
])
|
|
let expected = "<content>Normal <br/> text & <![CDATA[<special>]]></content>"
|
|
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 = "<l1><l2><l3><l4><l5>deep</l5></l4></l3></l2></l1>"
|
|
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\" & <more>"),
|
|
lib.attr("class", "a&b")
|
|
])
|
|
let expected = "<div title=\"a "test" & <more>\" class=\"a&b\"/>"
|
|
Test.assertEqualMsg(expected, lib.render(node), "snap: attribute escaping")
|
|
}
|
|
|
|
// Snapshot: empty elements
|
|
fn test_snapshot_empty_elements(): Unit with {Test} = {
|
|
Test.assertEqualMsg("<br/>", lib.render(lib.el("br", [])), "snap: empty el")
|
|
Test.assertEqualMsg("<hr/>", lib.render(lib.selfClosing("hr", [])), "snap: selfClosing")
|
|
Test.assertEqualMsg("<p></p>", 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 = "<url><loc>https://example.com/page</loc><lastmod>2025-01-29</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url>"
|
|
Test.assertEqualMsg(expected, lib.render(url), "snap: sitemap URL entry")
|
|
}
|