From 251f4d3c8a72494586887eb701f181fe0bc94f18 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 16 Dec 2023 13:47:55 +0100 Subject: util.xtemplate: Test the each template function It iterates over childtags, so a template like {foo|each{...}} would be equivalent to root:childtags("foo"), while a deeper query needs the bit that becomes arguments to :childtags as an argument to each, e.g. {foo/bar|each(baz)} would behave like root:get_child("foo"):get_child("bar"):childtags("baz") --- spec/util_xtemplate_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/util_xtemplate_spec.lua b/spec/util_xtemplate_spec.lua index 97ab415c..4561378e 100644 --- a/spec/util_xtemplate_spec.lua +++ b/spec/util_xtemplate_spec.lua @@ -31,5 +31,13 @@ describe("util.xtemplate", function () assert.same(" Hello", xtemplate.render(" {greeting-} ", st.stanza("root"):text_tag("greeting", "Hello"))) assert.same("Hello", xtemplate.render(" {-greeting-} ", st.stanza("root"):text_tag("greeting", "Hello"))) end) + describe("each", function () + it("makes sense", function () + local x = st.stanza("root"):tag("foo"):tag("bar") + for i = 1, 5 do x:text_tag("i", tostring(i)); end + x:reset(); + assert.same("12345", xtemplate.render("{foo/bar|each(i){{#}}}", x)); + end) + end) end) end) -- cgit v1.2.3