aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_rsm_spec.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-04-23 18:05:00 +0200
committerKim Alvefur <zash@zash.se>2020-04-23 18:05:00 +0200
commitda2a13287ee51d1dc1e1db92c3972c72b5d40081 (patch)
tree35343c5431a02f812b4112a154e25ae80fdf7812 /spec/util_rsm_spec.lua
parent114ff031fcf2aa12596b80bd91dac1b30694b6b8 (diff)
downloadprosody-da2a13287ee51d1dc1e1db92c3972c72b5d40081.tar.gz
prosody-da2a13287ee51d1dc1e1db92c3972c72b5d40081.zip
util.rsm: Add tests
Based on examples from XEP-0059
Diffstat (limited to 'spec/util_rsm_spec.lua')
-rw-r--r--spec/util_rsm_spec.lua82
1 files changed, 82 insertions, 0 deletions
diff --git a/spec/util_rsm_spec.lua b/spec/util_rsm_spec.lua
new file mode 100644
index 00000000..c8ddc47d
--- /dev/null
+++ b/spec/util_rsm_spec.lua
@@ -0,0 +1,82 @@
+local rsm = require "util.rsm";
+local xml = require "util.xml";
+
+local function strip(s)
+ return (s:gsub(">%s+<", "><"));
+end
+
+describe("util.rsm", function ()
+ describe("parse", function ()
+ it("works", function ()
+ local test = xml.parse(strip([[
+ <set xmlns='http://jabber.org/protocol/rsm'>
+ <max>10</max>
+ </set>
+ ]]));
+ assert.same({ max = 10 }, rsm.parse(test));
+ end);
+
+ it("works", function ()
+ local test = xml.parse(strip([[
+ <set xmlns='http://jabber.org/protocol/rsm'>
+ <first index='0'>saint@example.org</first>
+ <last>peterpan@neverland.lit</last>
+ <count>800</count>
+ </set>
+ ]]));
+ assert.same({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 }, rsm.parse(test));
+ end);
+
+ it("works", function ()
+ local test = xml.parse(strip([[
+ <set xmlns='http://jabber.org/protocol/rsm'>
+ <max>10</max>
+ <before>peter@pixyland.org</before>
+ </set>
+ ]]));
+ assert.same({ max = 10, before = "peter@pixyland.org" }, rsm.parse(test));
+ end);
+
+ end);
+
+ describe("generate", function ()
+ it("works", function ()
+ local test = xml.parse(strip([[
+ <set xmlns='http://jabber.org/protocol/rsm'>
+ <max>10</max>
+ </set>
+ ]]));
+ local res = rsm.generate({ max = 10 });
+ assert.same(test:get_child_text("max"), res:get_child_text("max"));
+ end);
+
+ it("works", function ()
+ local test = xml.parse(strip([[
+ <set xmlns='http://jabber.org/protocol/rsm'>
+ <first index='0'>saint@example.org</first>
+ <last>peterpan@neverland.lit</last>
+ <count>800</count>
+ </set>
+ ]]));
+ local res = rsm.generate({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 });
+ assert.same(test:get_child("first").attr.index, res:get_child("first").attr.index);
+ assert.same(test:get_child_text("first"), res:get_child_text("first"));
+ assert.same(test:get_child_text("last"), res:get_child_text("last"));
+ assert.same(test:get_child_text("count"), res:get_child_text("count"));
+ end);
+
+ it("works", function ()
+ local test = xml.parse(strip([[
+ <set xmlns='http://jabber.org/protocol/rsm'>
+ <max>10</max>
+ <before>peter@pixyland.org</before>
+ </set>
+ ]]));
+ local res = rsm.generate({ max = 10, before = "peter@pixyland.org" });
+ assert.same(test:get_child_text("max"), res:get_child_text("max"));
+ assert.same(test:get_child_text("before"), res:get_child_text("before"));
+ end);
+
+ end);
+end);
+