Software /
code /
prosody
Annotate
spec/util_rsm_spec.lua @ 11417:f84005d06663
mod_s2s: Check direction in bidi-aware style
Both session.incoming and session.outgoing are truthy here, but
session.direction indicates the "real" direction in the way that matters
for the order of events when opening or closing streams.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 03 Mar 2021 13:26:38 +0100 |
parent | 10762:4fc224c97986 |
child | 11427:83f5499d1f10 |
rev | line source |
---|---|
10760 | 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 | |
10762
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
80 it("handles floats", function () |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
81 local r1 = rsm.generate({ max = 10.0, count = 100.0, first = { index = 1.0, "foo" } }); |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
82 assert.equal("10", r1:get_child_text("max")); |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
83 assert.equal("100", r1:get_child_text("count")); |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
84 assert.equal("1", r1:get_child("first").attr.index); |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
85 end); |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
86 |
10760 | 87 end); |
88 end); | |
89 |