aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_rsm_spec.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-11-05 22:31:25 +0100
committerKim Alvefur <zash@zash.se>2020-11-05 22:31:25 +0100
commit0c94d96263cffcdbe0cf5ea59ef0b172b32258c2 (patch)
tree58547de6e7795740633c1b93e67c217eb621fe8f /spec/util_rsm_spec.lua
parent20cb21003f0374e7078e1a29ffb36a7028c6b9ef (diff)
parent4afbfc6854ebc374acc34729fdc6e472b44b07f1 (diff)
downloadprosody-0c94d96263cffcdbe0cf5ea59ef0b172b32258c2.tar.gz
prosody-0c94d96263cffcdbe0cf5ea59ef0b172b32258c2.zip
Merge 0.11->trunk
Diffstat (limited to 'spec/util_rsm_spec.lua')
-rw-r--r--spec/util_rsm_spec.lua89
1 files changed, 89 insertions, 0 deletions
diff --git a/spec/util_rsm_spec.lua b/spec/util_rsm_spec.lua
new file mode 100644
index 00000000..08fb1b02
--- /dev/null
+++ b/spec/util_rsm_spec.lua
@@ -0,0 +1,89 @@
+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);
+
+ it("handles floats", function ()
+ local r1 = rsm.generate({ max = 10.0, count = 100.0, first = { index = 1.0, "foo" } });
+ assert.equal("10", r1:get_child_text("max"));
+ assert.equal("100", r1:get_child_text("count"));
+ assert.equal("1", r1:get_child("first").attr.index);
+ end);
+
+ end);
+end);
+