Software /
code /
prosody
Comparison
spec/util_datamapper_spec.lua @ 11466:c098d07e6717
util.datamapper: Finally implement support for parsing arrays
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 20 Mar 2021 20:45:06 +0100 |
parent | 11462:d1982b7eb00d |
child | 11468:348b191cd850 |
comparison
equal
deleted
inserted
replaced
11465:19a88b61ab4e | 11466:c098d07e6717 |
---|---|
7 end); | 7 end); |
8 | 8 |
9 describe("util.datampper", function() | 9 describe("util.datampper", function() |
10 | 10 |
11 local s, x, d | 11 local s, x, d |
12 local disco, disco_info, disco_schema | |
12 setup(function() | 13 setup(function() |
13 | 14 |
14 local function attr() return {type = "string"; xml = {attribute = true}} end | 15 local function attr() return {type = "string"; xml = {attribute = true}} end |
15 s = { | 16 s = { |
16 type = "object"; | 17 type = "object"; |
89 "👋", | 90 "👋", |
90 "🐢", | 91 "🐢", |
91 }; | 92 }; |
92 }; | 93 }; |
93 }; | 94 }; |
95 | |
96 disco_schema = { | |
97 type = "object"; | |
98 xml = { | |
99 name = "iq"; | |
100 namespace = "jabber:client" | |
101 }; | |
102 properties = { | |
103 to = attr(); | |
104 from = attr(); | |
105 type = attr(); | |
106 id = attr(); | |
107 disco = { | |
108 type = "object"; | |
109 xml = { | |
110 name = "query"; | |
111 namespace = "http://jabber.org/protocol/disco#info" | |
112 }; | |
113 properties = { | |
114 features = { | |
115 type = "array"; | |
116 items = { | |
117 type = "string"; | |
118 xml = { | |
119 name = "feature"; | |
120 x_single_attribute = "var"; | |
121 }; | |
122 }; | |
123 }; | |
124 }; | |
125 }; | |
126 }; | |
127 }; | |
128 | |
129 disco_info = xml.parse[[ | |
130 <iq type="result" id="disco1" from="example.com"> | |
131 <query xmlns="http://jabber.org/protocol/disco#info"> | |
132 <feature var="urn:example:feature:1">wrong</feature> | |
133 <feature var="urn:example:feature:2"/> | |
134 <feature var="urn:example:feature:3"/> | |
135 <unrelated var="urn:example:feature:not"/> | |
136 </query> | |
137 </iq> | |
138 ]]; | |
139 | |
140 disco = { | |
141 type="result"; | |
142 id="disco1"; | |
143 from="example.com"; | |
144 disco = { | |
145 features = { | |
146 "urn:example:feature:1"; | |
147 "urn:example:feature:2"; | |
148 "urn:example:feature:3"; | |
149 }; | |
150 }; | |
151 }; | |
94 end); | 152 end); |
95 | 153 |
96 describe("parse", function() | 154 describe("parse", function() |
97 it("works", function() | 155 it("works", function() |
98 assert.same(d, map.parse(s, x)); | 156 assert.same(d, map.parse(s, x)); |
99 end); | 157 end); |
158 | |
159 it("handles arrays", function () | |
160 assert.same(disco, map.parse(disco_schema, disco_info)); | |
161 end); | |
162 | |
100 end); | 163 end); |
101 | 164 |
102 describe("unparse", function() | 165 describe("unparse", function() |
103 it("works", function() | 166 it("works", function() |
104 local u = map.unparse(s, d); | 167 local u = map.unparse(s, d); |