Sync local packages into the registry repo and update index.json and README.md to include all 9 packages.
75 lines
3.3 KiB
Plaintext
75 lines
3.3 KiB
Plaintext
import lib
|
|
|
|
fn test_escape(): Unit with {Test} = {
|
|
Test.assertEqualMsg("<b>hello</b>", lib.escape("<b>hello</b>"), "escape angle brackets")
|
|
Test.assertEqualMsg("a & b", lib.escape("a & b"), "escape ampersand")
|
|
Test.assertEqualMsg(""quoted"", lib.escape("\"quoted\""), "escape quotes")
|
|
}
|
|
|
|
fn test_text_node(): Unit with {Test} = {
|
|
Test.assertEqualMsg("hello", lib.render(lib.text("hello")), "text node simple")
|
|
Test.assertEqualMsg("<b>", lib.render(lib.text("<b>")), "text node escaped")
|
|
}
|
|
|
|
fn test_cdata(): Unit with {Test} = {
|
|
Test.assertEqualMsg("<![CDATA[hello <b>world</b>]]>", lib.render(lib.cdata("hello <b>world</b>")), "cdata node")
|
|
}
|
|
|
|
fn test_raw(): Unit with {Test} = {
|
|
Test.assertEqualMsg("<br/>", lib.render(lib.raw("<br/>")), "raw node")
|
|
}
|
|
|
|
fn test_text_element(): Unit with {Test} = {
|
|
Test.assertEqualMsg("<title>Hello</title>", lib.render(lib.textEl("title", "Hello")), "text element")
|
|
}
|
|
|
|
fn test_element_with_attrs(): Unit with {Test} = {
|
|
let linkEl = lib.element("link", [lib.attr("href", "http://example.com"), lib.attr("rel", "alternate")], [])
|
|
Test.assertEqualMsg("<link href=\"http://example.com\" rel=\"alternate\"/>", lib.render(linkEl), "element with attrs self-closing")
|
|
}
|
|
|
|
fn test_self_closing(): Unit with {Test} = {
|
|
Test.assertEqualMsg("<br/>", lib.render(lib.selfClosing("br", [])), "self-closing no attrs")
|
|
Test.assertEqualMsg("<img src=\"photo.jpg\"/>", lib.render(lib.selfClosing("img", [lib.attr("src", "photo.jpg")])), "self-closing with attr")
|
|
}
|
|
|
|
fn test_nested_elements(): Unit with {Test} = {
|
|
let nested = lib.el("root", [lib.textEl("child1", "a"), lib.textEl("child2", "b")])
|
|
Test.assertEqualMsg("<root><child1>a</child1><child2>b</child2></root>", lib.render(nested), "nested elements")
|
|
}
|
|
|
|
fn test_element_with_attrs_and_children(): Unit with {Test} = {
|
|
let withAttr = lib.element("item", [lib.attr("id", "1")], [lib.textEl("name", "Test")])
|
|
Test.assertEqualMsg("<item id=\"1\"><name>Test</name></item>", lib.render(withAttr), "element with attrs and children")
|
|
}
|
|
|
|
fn test_text_element_with_attrs(): Unit with {Test} = {
|
|
let attrText = lib.textElAttr("a", [lib.attr("href", "/page")], "Click")
|
|
Test.assertEqualMsg("<a href=\"/page\">Click</a>", lib.render(attrText), "text element with attrs")
|
|
}
|
|
|
|
fn test_xml_document(): Unit with {Test} = {
|
|
let doc = lib.document(lib.textEl("root", "content"))
|
|
let expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root>content</root>"
|
|
Test.assertEqualMsg(expected, doc, "xml document")
|
|
}
|
|
|
|
fn test_deeply_nested(): Unit with {Test} = {
|
|
let deep = lib.el("a", [lib.el("b", [lib.el("c", [lib.text("deep")])])])
|
|
Test.assertEqualMsg("<a><b><c>deep</c></b></a>", lib.render(deep), "deeply nested")
|
|
}
|
|
|
|
fn test_empty_element(): Unit with {Test} = {
|
|
Test.assertEqualMsg("<empty/>", lib.render(lib.el("empty", [])), "el empty children self-closes")
|
|
}
|
|
|
|
fn test_attribute_value_escaping(): Unit with {Test} = {
|
|
let escapedAttr = lib.selfClosing("div", [lib.attr("data", "a&b<c")])
|
|
Test.assertEqualMsg("<div data=\"a&b<c\"/>", lib.render(escapedAttr), "attribute value escaping")
|
|
}
|
|
|
|
fn test_mixed_children(): Unit with {Test} = {
|
|
let mixed = lib.el("p", [lib.text("Hello "), lib.raw("<b>world</b>")])
|
|
Test.assertEqualMsg("<p>Hello <b>world</b></p>", lib.render(mixed), "mixed text and raw children")
|
|
}
|