blob: 0e1dfdab9b213b438f1439817fef519273bdf9c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
local xml
local map
setup(function()
xml = require "util.xml";
map = require "util.datamapper";
end);
describe("util.datampper", function()
local s, x, d
setup(function()
local function attr() return {type = "string"; xml = {attribute = true}} end
s = {
type = "object";
xml = {name = "message"; namespace = "jabber:client"};
properties = {
to = attr();
from = attr();
type = attr();
id = attr();
body = "string";
lang = {type = "string"; xml = {attribute = true; prefix = "xml"}};
delay = {
type = "object";
xml = {namespace = "urn:xmpp:delay"; name = "delay"};
properties = {stamp = attr(); from = attr(); reason = {type = "string"; xml = {text = true}}};
};
};
};
x = xml.parse [[
<message xmlns="jabber:client" xml:lang="en" to="a@test" from="b@test" type="chat" id="1">
<body>Hello</body>
<delay xmlns='urn:xmpp:delay' from='test' stamp='2021-03-07T15:59:08+00:00'>Becasue</delay>
</message>
]];
d = {
to = "a@test";
from = "b@test";
type = "chat";
id = "1";
lang = "en";
body = "Hello";
delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"};
};
end);
describe("parse", function()
it("works", function()
assert.same(d, map.parse(s, x));
end);
end);
end)
|