Software /
code /
prosody
Comparison
spec/util_datamapper_spec.lua @ 11439:9abcdfdcdb01
util.datamapper: Add support for mapping of elements where only one attribute matters
E.g. <feature var='foo'/> in XEP-0030 and some other simple
specifications.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 07 Mar 2021 12:48:49 +0100 |
parent | 11438:b7807583de34 |
child | 11453:f0037234b2e9 |
comparison
equal
deleted
inserted
replaced
11438:b7807583de34 | 11439:9abcdfdcdb01 |
---|---|
33 }; | 33 }; |
34 fallback = { | 34 fallback = { |
35 type = "boolean"; | 35 type = "boolean"; |
36 xml = {x_name_is_value = true; name = "fallback"; namespace = "urn:xmpp:fallback:0"}; | 36 xml = {x_name_is_value = true; name = "fallback"; namespace = "urn:xmpp:fallback:0"}; |
37 }; | 37 }; |
38 origin_id = { | |
39 type = "string"; | |
40 xml = {name = "origin-id"; namespace = "urn:xmpp:sid:0"; x_single_attribute = "id"}; | |
41 }; | |
38 }; | 42 }; |
39 }; | 43 }; |
40 | 44 |
41 x = xml.parse [[ | 45 x = xml.parse [[ |
42 <message xmlns="jabber:client" xml:lang="en" to="a@test" from="b@test" type="chat" id="1"> | 46 <message xmlns="jabber:client" xml:lang="en" to="a@test" from="b@test" type="chat" id="1"> |
43 <body>Hello</body> | 47 <body>Hello</body> |
44 <delay xmlns='urn:xmpp:delay' from='test' stamp='2021-03-07T15:59:08+00:00'>Becasue</delay> | 48 <delay xmlns='urn:xmpp:delay' from='test' stamp='2021-03-07T15:59:08+00:00'>Becasue</delay> |
45 <active xmlns='http://jabber.org/protocol/chatstates'/> | 49 <active xmlns='http://jabber.org/protocol/chatstates'/> |
46 <fallback xmlns='urn:xmpp:fallback:0'/> | 50 <fallback xmlns='urn:xmpp:fallback:0'/> |
51 <origin-id xmlns='urn:xmpp:sid:0' id='qgkmMdPB'/> | |
47 </message> | 52 </message> |
48 ]]; | 53 ]]; |
49 | 54 |
50 d = { | 55 d = { |
51 to = "a@test"; | 56 to = "a@test"; |
55 lang = "en"; | 60 lang = "en"; |
56 body = "Hello"; | 61 body = "Hello"; |
57 delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"}; | 62 delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"}; |
58 state = "active"; | 63 state = "active"; |
59 fallback = true; | 64 fallback = true; |
65 origin_id = "qgkmMdPB"; | |
60 }; | 66 }; |
61 end); | 67 end); |
62 | 68 |
63 describe("parse", function() | 69 describe("parse", function() |
64 it("works", function() | 70 it("works", function() |
73 assert.same(x.attr, u.attr); | 79 assert.same(x.attr, u.attr); |
74 assert.equal(#x.tags, #u.tags) | 80 assert.equal(#x.tags, #u.tags) |
75 assert.equal(x:get_child_text("body"), u:get_child_text("body")); | 81 assert.equal(x:get_child_text("body"), u:get_child_text("body")); |
76 assert.equal(x:get_child_text("delay", "urn:xmpp:delay"), u:get_child_text("delay", "urn:xmpp:delay")); | 82 assert.equal(x:get_child_text("delay", "urn:xmpp:delay"), u:get_child_text("delay", "urn:xmpp:delay")); |
77 assert.same(x:get_child("delay", "urn:xmpp:delay").attr, u:get_child("delay", "urn:xmpp:delay").attr); | 83 assert.same(x:get_child("delay", "urn:xmpp:delay").attr, u:get_child("delay", "urn:xmpp:delay").attr); |
84 assert.same(x:get_child("origin-id", "urn:xmpp:sid:0").attr, u:get_child("origin-id", "urn:xmpp:sid:0").attr); | |
78 end); | 85 end); |
79 end); | 86 end); |
80 end) | 87 end) |