aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_stanza_spec.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-08-19 21:29:52 +0100
committerMatthew Wild <mwild1@gmail.com>2018-08-19 21:29:52 +0100
commitc17a7856044ebd780de1cc5272210a6a77150dda (patch)
tree6648bb6f6c557fc3569b412a8efffc6275249eab /spec/util_stanza_spec.lua
parent1c68fe88f708454b3c1fd9203d478c017df1b1cb (diff)
downloadprosody-c17a7856044ebd780de1cc5272210a6a77150dda.tar.gz
prosody-c17a7856044ebd780de1cc5272210a6a77150dda.zip
util.stanza tests: Add tests for maptags() method
Diffstat (limited to 'spec/util_stanza_spec.lua')
-rw-r--r--spec/util_stanza_spec.lua71
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index 8abc6096..aabeeadc 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -257,4 +257,75 @@ describe("util.stanza", function()
end);
end);
+ describe("#maptags", function ()
+ it("should work", function ()
+ local s = st.stanza("test")
+ :tag("one"):up()
+ :tag("two"):up()
+ :tag("one"):up()
+ :tag("three"):up();
+
+ local function one_filter(tag)
+ if tag.name == "one" then
+ return nil;
+ end
+ return tag;
+ end
+ assert.equal(4, #s.tags);
+ s:maptags(one_filter);
+ assert.equal(2, #s.tags);
+ end);
+
+ it("should work with multiple consecutive text nodes", function ()
+ local s = st.deserialize({
+ "\n";
+ {
+ "away";
+ name = "show";
+ attr = {};
+ };
+ "\n";
+ {
+ "I am away";
+ name = "status";
+ attr = {};
+ };
+ "\n";
+ {
+ "0";
+ name = "priority";
+ attr = {};
+ };
+ "\n";
+ {
+ name = "c";
+ attr = {
+ xmlns = "http://jabber.org/protocol/caps";
+ node = "http://psi-im.org";
+ hash = "sha-1";
+ };
+ };
+ "\n";
+ "\n";
+ name = "presence";
+ attr = {
+ to = "user@example.com/jflsjfld";
+ from = "room@chat.example.org/nick";
+ };
+ });
+
+ assert.equal(4, #s.tags);
+
+ s:maptags(function (tag) return tag; end);
+ assert.equal(4, #s.tags);
+
+ s:maptags(function (tag)
+ if tag.name == "c" then
+ return nil;
+ end
+ return tag;
+ end);
+ assert.equal(3, #s.tags);
+ end);
+ end);
end);