Software /
code /
prosody
Comparison
spec/util_rsm_spec.lua @ 10760:c9d1d9c80e1e
util.rsm: Add tests
Based on examples from XEP-0059
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 23 Apr 2020 18:05:00 +0200 |
child | 10762:4fc224c97986 |
comparison
equal
deleted
inserted
replaced
10759:817f1d6b499e | 10760:c9d1d9c80e1e |
---|---|
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 end); | |
81 end); | |
82 |