summaryrefslogtreecommitdiff
path: root/tests/modules/xml/test.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-15 19:38:12 +0800
committerruki <[email protected]>2025-11-15 19:38:12 +0800
commitcda90e424674c41c3447d4ebc3709dd290ccf512 (patch)
tree03b40be8dbc5123338c4ec904711e64744d9578a /tests/modules/xml/test.lua
parent7c7c82fa43a10f89a8842ea51dca34f68a1a846d (diff)
add xpath support
Diffstat (limited to 'tests/modules/xml/test.lua')
-rw-r--r--tests/modules/xml/test.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/modules/xml/test.lua b/tests/modules/xml/test.lua
index 60d50d62a..21a4e7745 100644
--- a/tests/modules/xml/test.lua
+++ b/tests/modules/xml/test.lua
@@ -124,3 +124,22 @@ function test_scan_stop(t)
t:are_equal(xml.text_of(found), "NSPrincipalClass")
end
+function test_find_xpath(t)
+ local doc = xml.decode([[
+<root>
+ <items>
+ <item id="a"><value>foo</value></item>
+ <item id="b"><value>bar</value></item>
+ </items>
+ <extras>
+ <item id="c"/>
+ </extras>
+</root>]])
+ local second = xml.find(doc, "root/items/item[2]")
+ t:are_equal(second.attrs.id, "b")
+ local descendant = xml.find(doc, "//item[@id='c']")
+ t:are_equal(descendant.attrs.id, "c")
+ local value = xml.find(doc, "//value[text()='bar']")
+ t:are_equal(xml.text_of(value), "bar")
+end
+