Comparison

spec/util_rsm_spec.lua @ 11200:bf8f2da84007

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 05 Nov 2020 22:31:25 +0100
parent 10762:4fc224c97986
child 11427:83f5499d1f10
comparison
equal deleted inserted replaced
11199:6c7c50a4de32 11200:bf8f2da84007
1 local rsm = require "util.rsm";
2 local xml = require "util.xml";
3
4 local function strip(s)
5 return (s:gsub(">%s+<", "><"));
6 end
7
8 describe("util.rsm", function ()
9 describe("parse", function ()
10 it("works", function ()
11 local test = xml.parse(strip([[
12 <set xmlns='http://jabber.org/protocol/rsm'>
13 <max>10</max>
14 </set>
15 ]]));
16 assert.same({ max = 10 }, rsm.parse(test));
17 end);
18
19 it("works", function ()
20 local test = xml.parse(strip([[
21 <set xmlns='http://jabber.org/protocol/rsm'>
22 <first index='0'>saint@example.org</first>
23 <last>peterpan@neverland.lit</last>
24 <count>800</count>
25 </set>
26 ]]));
27 assert.same({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 }, rsm.parse(test));
28 end);
29
30 it("works", function ()
31 local test = xml.parse(strip([[
32 <set xmlns='http://jabber.org/protocol/rsm'>
33 <max>10</max>
34 <before>peter@pixyland.org</before>
35 </set>
36 ]]));
37 assert.same({ max = 10, before = "peter@pixyland.org" }, rsm.parse(test));
38 end);
39
40 end);
41
42 describe("generate", function ()
43 it("works", function ()
44 local test = xml.parse(strip([[
45 <set xmlns='http://jabber.org/protocol/rsm'>
46 <max>10</max>
47 </set>
48 ]]));
49 local res = rsm.generate({ max = 10 });
50 assert.same(test:get_child_text("max"), res:get_child_text("max"));
51 end);
52
53 it("works", function ()
54 local test = xml.parse(strip([[
55 <set xmlns='http://jabber.org/protocol/rsm'>
56 <first index='0'>saint@example.org</first>
57 <last>peterpan@neverland.lit</last>
58 <count>800</count>
59 </set>
60 ]]));
61 local res = rsm.generate({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 });
62 assert.same(test:get_child("first").attr.index, res:get_child("first").attr.index);
63 assert.same(test:get_child_text("first"), res:get_child_text("first"));
64 assert.same(test:get_child_text("last"), res:get_child_text("last"));
65 assert.same(test:get_child_text("count"), res:get_child_text("count"));
66 end);
67
68 it("works", function ()
69 local test = xml.parse(strip([[
70 <set xmlns='http://jabber.org/protocol/rsm'>
71 <max>10</max>
72 <before>peter@pixyland.org</before>
73 </set>
74 ]]));
75 local res = rsm.generate({ max = 10, before = "peter@pixyland.org" });
76 assert.same(test:get_child_text("max"), res:get_child_text("max"));
77 assert.same(test:get_child_text("before"), res:get_child_text("before"));
78 end);
79
80 it("handles floats", function ()
81 local r1 = rsm.generate({ max = 10.0, count = 100.0, first = { index = 1.0, "foo" } });
82 assert.equal("10", r1:get_child_text("max"));
83 assert.equal("100", r1:get_child_text("count"));
84 assert.equal("1", r1:get_child("first").attr.index);
85 end);
86
87 end);
88 end);
89