aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_stanza_spec.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2021-09-12 10:31:02 +0100
committerMatthew Wild <mwild1@gmail.com>2021-09-12 10:31:02 +0100
commiteba0bacfdaeaddd47c323f6681c79d57228d93a5 (patch)
treea2cf45d410616f3dc87a5449aa815fb910db50f1 /spec/util_stanza_spec.lua
parentbee45656d7fe68ebc8009d50f4572e6e194dafe1 (diff)
downloadprosody-eba0bacfdaeaddd47c323f6681c79d57228d93a5.tar.gz
prosody-eba0bacfdaeaddd47c323f6681c79d57228d93a5.zip
util.stanza: Add :get_child_with_attr() + tests
Diffstat (limited to 'spec/util_stanza_spec.lua')
-rw-r--r--spec/util_stanza_spec.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index b9ab1e31..5306c05b 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -455,6 +455,26 @@ describe("util.stanza", function()
end);
end);
+ describe("get_child_with_attr", function ()
+ local s = st.message({ type = "chat" })
+ :text_tag("body", "Hello world", { ["xml:lang"] = "en" })
+ :text_tag("body", "Bonjour le monde", { ["xml:lang"] = "fr" })
+ :text_tag("body", "Hallo Welt", { ["xml:lang"] = "de" })
+
+ it("works", function ()
+ assert.equal(s:get_child_with_attr("body", nil, "xml:lang", "en"):get_text(), "Hello world");
+ assert.equal(s:get_child_with_attr("body", nil, "xml:lang", "de"):get_text(), "Hallo Welt");
+ assert.equal(s:get_child_with_attr("body", nil, "xml:lang", "fr"):get_text(), "Bonjour le monde");
+ assert.is_nil(s:get_child_with_attr("body", nil, "xml:lang", "FR"));
+ assert.is_nil(s:get_child_with_attr("body", nil, "xml:lang", "es"));
+ end);
+
+ it("supports normalization", function ()
+ assert.equal(s:get_child_with_attr("body", nil, "xml:lang", "EN", string.upper):get_text(), "Hello world");
+ assert.is_nil(s:get_child_with_attr("body", nil, "xml:lang", "ES", string.upper));
+ end);
+ end);
+
describe("#clone", function ()
it("works", function ()
local s = st.message({type="chat"}, "Hello"):reset();