Software /
code /
prosody
Comparison
spec/util_stanza_spec.lua @ 9216:ba38a947020e
util.stanza tests: Add tests for maptags() method
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 19 Aug 2018 21:29:52 +0100 |
parent | 9000:4d64ff0719a6 |
child | 9217:7df29c5fbb9b |
comparison
equal
deleted
inserted
replaced
9215:b087b5047f86 | 9216:ba38a947020e |
---|---|
255 s:remove_children(); | 255 s:remove_children(); |
256 assert.falsy(s.tags[1]); | 256 assert.falsy(s.tags[1]); |
257 end); | 257 end); |
258 end); | 258 end); |
259 | 259 |
260 describe("#maptags", function () | |
261 it("should work", function () | |
262 local s = st.stanza("test") | |
263 :tag("one"):up() | |
264 :tag("two"):up() | |
265 :tag("one"):up() | |
266 :tag("three"):up(); | |
267 | |
268 local function one_filter(tag) | |
269 if tag.name == "one" then | |
270 return nil; | |
271 end | |
272 return tag; | |
273 end | |
274 assert.equal(4, #s.tags); | |
275 s:maptags(one_filter); | |
276 assert.equal(2, #s.tags); | |
277 end); | |
278 | |
279 it("should work with multiple consecutive text nodes", function () | |
280 local s = st.deserialize({ | |
281 "\n"; | |
282 { | |
283 "away"; | |
284 name = "show"; | |
285 attr = {}; | |
286 }; | |
287 "\n"; | |
288 { | |
289 "I am away"; | |
290 name = "status"; | |
291 attr = {}; | |
292 }; | |
293 "\n"; | |
294 { | |
295 "0"; | |
296 name = "priority"; | |
297 attr = {}; | |
298 }; | |
299 "\n"; | |
300 { | |
301 name = "c"; | |
302 attr = { | |
303 xmlns = "http://jabber.org/protocol/caps"; | |
304 node = "http://psi-im.org"; | |
305 hash = "sha-1"; | |
306 }; | |
307 }; | |
308 "\n"; | |
309 "\n"; | |
310 name = "presence"; | |
311 attr = { | |
312 to = "user@example.com/jflsjfld"; | |
313 from = "room@chat.example.org/nick"; | |
314 }; | |
315 }); | |
316 | |
317 assert.equal(4, #s.tags); | |
318 | |
319 s:maptags(function (tag) return tag; end); | |
320 assert.equal(4, #s.tags); | |
321 | |
322 s:maptags(function (tag) | |
323 if tag.name == "c" then | |
324 return nil; | |
325 end | |
326 return tag; | |
327 end); | |
328 assert.equal(3, #s.tags); | |
329 end); | |
330 end); | |
260 end); | 331 end); |