From 29fbfdef99861931d81578eac3434f452efddb8e Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 15 Nov 2025 00:48:55 +0800 Subject: add xml module --- tests/modules/xml/test.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/modules/xml/test.lua (limited to 'tests/modules/xml/test.lua') diff --git a/tests/modules/xml/test.lua b/tests/modules/xml/test.lua new file mode 100644 index 000000000..eb01aad86 --- /dev/null +++ b/tests/modules/xml/test.lua @@ -0,0 +1,29 @@ +import("core.base.xml") + +function test_parse_basic(t) + local doc = xml.decode([[foo]]) + t:are_equal(doc.name, "root") + t:are_equal(doc.attrs.id, "1") + t:are_equal(#doc.children, 2) + t:are_equal(doc.children[1].name, "item") + t:are_equal(xml.text_of(doc.children[1]), "foo") + t:are_equal(doc.children[2].attrs.id, "2") +end + +function test_encode(t) + local doc = xml.new("root", {id = "1"}, { + xml.new("item", {}, {xml.text("foo")}), + xml.new("item", {id = "2"}) + }) + local compact = xml.encode(doc) + t:are_equal(compact, 'foo') + local pretty = xml.encode(doc, {pretty = true, indent = 2}) + local expected = table.concat({ + '', + ' foo', + ' ', + '' + }, "\n") + t:are_equal(pretty, expected) +end + -- cgit v1.3.1