import lib
// Integration tests: building real-world XML documents
// Build an HTML page structure
fn test_build_html_page(): Unit with {Test} = {
let head = lib.el("head", [
lib.textEl("title", "My Page"),
lib.selfClosing("meta", [lib.attr("charset", "utf-8")]),
lib.selfClosing("link", [lib.attr("rel", "stylesheet"), lib.attr("href", "style.css")])
])
let body = lib.el("body", [
lib.el("header", [lib.textEl("h1", "Welcome")]),
lib.el("main", [lib.textEl("p", "Hello world")]),
lib.el("footer", [lib.textEl("p", "Copyright 2025")])
])
let html = lib.el("html", [head, body])
let result = lib.render(html)
Test.assert(String.contains(result, "
My Page"), "page has title")
Test.assert(String.contains(result, ""), "page has meta charset")
Test.assert(String.contains(result, "
Welcome
"), "page has h1")
Test.assert(String.contains(result, "
Hello world
"), "page has paragraph")
Test.assert(String.startsWith(result, ""), "starts with html tag")
Test.assert(String.endsWith(result, ""), "ends with html tag")
}
// Build a sitemap.xml
fn test_build_sitemap(): Unit with {Test} = {
let url1 = lib.el("url", [
lib.textEl("loc", "https://example.com/"),
lib.textEl("lastmod", "2025-01-29"),
lib.textEl("priority", "1.0")
])
let url2 = lib.el("url", [
lib.textEl("loc", "https://example.com/about"),
lib.textEl("lastmod", "2025-01-15"),
lib.textEl("priority", "0.8")
])
let urlset = lib.element("urlset", [lib.attr("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")], [url1, url2])
let sitemap = lib.document(urlset)
Test.assert(String.startsWith(sitemap, "https://example.com/"), "sitemap has first URL")
Test.assert(String.contains(sitemap, "https://example.com/about"), "sitemap has second URL")
}
// Build a form with various input types
fn test_build_form(): Unit with {Test} = {
let form = lib.element("form", [lib.attr("action", "/submit"), lib.attr("method", "post")], [
lib.selfClosing("input", [lib.attr("type", "text"), lib.attr("name", "username")]),
lib.selfClosing("input", [lib.attr("type", "password"), lib.attr("name", "pass")]),
lib.textElAttr("button", [lib.attr("type", "submit")], "Login")
])
let result = lib.render(form)
Test.assert(String.contains(result, "action=\"/submit\""), "form has action")
Test.assert(String.contains(result, "type=\"text\""), "has text input")
Test.assert(String.contains(result, "type=\"password\""), "has password input")
Test.assert(String.contains(result, ""), "has submit button")
}
// Build nested table structure
fn test_build_table(): Unit with {Test} = {
let headerRow = lib.el("tr", [lib.textEl("th", "Name"), lib.textEl("th", "Age")])
let row1 = lib.el("tr", [lib.textEl("td", "Alice"), lib.textEl("td", "30")])
let row2 = lib.el("tr", [lib.textEl("td", "Bob"), lib.textEl("td", "25")])
let table = lib.el("table", [lib.el("thead", [headerRow]), lib.el("tbody", [row1, row2])])
let result = lib.render(table)
Test.assert(String.contains(result, "