Comparison

spec/util_datamapper_spec.lua @ 11437:87a684df4b65

util.datamapper: Invent extension for using tag name as value Useful for certain enum-like uses where the element name is the relevant information, e.g. chat states.
author Kim Alvefur <zash@zash.se>
date Sat, 06 Mar 2021 23:14:23 +0100
parent 11436:5df9ffc25bb4
child 11438:b7807583de34
comparison
equal deleted inserted replaced
11436:5df9ffc25bb4 11437:87a684df4b65
25 delay = { 25 delay = {
26 type = "object"; 26 type = "object";
27 xml = {namespace = "urn:xmpp:delay"; name = "delay"}; 27 xml = {namespace = "urn:xmpp:delay"; name = "delay"};
28 properties = {stamp = attr(); from = attr(); reason = {type = "string"; xml = {text = true}}}; 28 properties = {stamp = attr(); from = attr(); reason = {type = "string"; xml = {text = true}}};
29 }; 29 };
30 state = {
31 type = "string";
32 xml = {x_name_is_value = true; namespace = "http://jabber.org/protocol/chatstates"};
33 };
30 }; 34 };
31 }; 35 };
32 36
33 x = xml.parse [[ 37 x = xml.parse [[
34 <message xmlns="jabber:client" xml:lang="en" to="a@test" from="b@test" type="chat" id="1"> 38 <message xmlns="jabber:client" xml:lang="en" to="a@test" from="b@test" type="chat" id="1">
35 <body>Hello</body> 39 <body>Hello</body>
36 <delay xmlns='urn:xmpp:delay' from='test' stamp='2021-03-07T15:59:08+00:00'>Becasue</delay> 40 <delay xmlns='urn:xmpp:delay' from='test' stamp='2021-03-07T15:59:08+00:00'>Becasue</delay>
37 </message> 41 <active xmlns='http://jabber.org/protocol/chatstates'/>
38 ]]; 42 </message>
43 ]];
39 44
40 d = { 45 d = {
41 to = "a@test"; 46 to = "a@test";
42 from = "b@test"; 47 from = "b@test";
43 type = "chat"; 48 type = "chat";
44 id = "1"; 49 id = "1";
45 lang = "en"; 50 lang = "en";
46 body = "Hello"; 51 body = "Hello";
47 delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"}; 52 delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"};
53 state = "active";
48 }; 54 };
49 end); 55 end);
50 56
51 describe("parse", function() 57 describe("parse", function()
52 it("works", function() 58 it("works", function()