From c62c5b307ec907b78f309dbbe90b6569fe91a3f8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Mar 2021 12:57:25 +0100 Subject: util.datamapper: Add initial support for parsing arrays --- spec/util_datamapper_spec.lua | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_datamapper_spec.lua b/spec/util_datamapper_spec.lua index 7f5b71de..aacaf995 100644 --- a/spec/util_datamapper_spec.lua +++ b/spec/util_datamapper_spec.lua @@ -46,6 +46,11 @@ describe("util.datampper", function() type = "string"; xml = {name = "origin-id"; namespace = "urn:xmpp:sid:0"; x_single_attribute = "id"}; }; + reactions = { + type = "array"; + xml = {namespace = "urn:xmpp:reactions:0"; wrapped = true}; + items = {type = "string"; xml = {name = "reaction"}}; + }; }; }; @@ -57,6 +62,10 @@ describe("util.datampper", function() + + 👋 + 🐢 + ]]; @@ -71,6 +80,10 @@ describe("util.datampper", function() state = "active"; fallback = true; origin_id = "qgkmMdPB"; + reactions = { + "👋", + "🐢", + }; }; end); @@ -85,11 +98,21 @@ describe("util.datampper", function() local u = map.unparse(s, d); assert.equal("message", u.name); assert.same(x.attr, u.attr); - assert.equal(#x.tags-1, #u.tags) assert.equal(x:get_child_text("body"), u:get_child_text("body")); assert.equal(x:get_child_text("delay", "urn:xmpp:delay"), u:get_child_text("delay", "urn:xmpp:delay")); assert.same(x:get_child("delay", "urn:xmpp:delay").attr, u:get_child("delay", "urn:xmpp:delay").attr); assert.same(x:get_child("origin-id", "urn:xmpp:sid:0").attr, u:get_child("origin-id", "urn:xmpp:sid:0").attr); + for _, tag in ipairs(x.tags) do + if tag.name ~= "UNRELATED" and tag.name ~= "reactions" then + assert.truthy(u:get_child(tag.name, tag.attr.xmlns) or u:get_child(tag.name), tag:top_tag()) + end + end + assert.equal(#x.tags-2, #u.tags) + + pending("arrays", function () + assert.truthy(u:get_child("reactions", "urn:xmpp:reactions:0")) + end); + end); end); end) -- cgit v1.2.3