From f5962d7193fbd92687248ef97b4673248defc751 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 20 Mar 2021 20:45:06 +0100 Subject: util.datamapper: Finally implement support for parsing arrays --- spec/util_datamapper_spec.lua | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'spec/util_datamapper_spec.lua') diff --git a/spec/util_datamapper_spec.lua b/spec/util_datamapper_spec.lua index 6d75facf..cbb579dc 100644 --- a/spec/util_datamapper_spec.lua +++ b/spec/util_datamapper_spec.lua @@ -9,6 +9,7 @@ end); describe("util.datampper", function() local s, x, d + local disco, disco_info, disco_schema setup(function() local function attr() return {type = "string"; xml = {attribute = true}} end @@ -91,12 +92,74 @@ describe("util.datampper", function() }; }; }; + + disco_schema = { + type = "object"; + xml = { + name = "iq"; + namespace = "jabber:client" + }; + properties = { + to = attr(); + from = attr(); + type = attr(); + id = attr(); + disco = { + type = "object"; + xml = { + name = "query"; + namespace = "http://jabber.org/protocol/disco#info" + }; + properties = { + features = { + type = "array"; + items = { + type = "string"; + xml = { + name = "feature"; + x_single_attribute = "var"; + }; + }; + }; + }; + }; + }; + }; + + disco_info = xml.parse[[ + + + wrong + + + + + + ]]; + + disco = { + type="result"; + id="disco1"; + from="example.com"; + disco = { + features = { + "urn:example:feature:1"; + "urn:example:feature:2"; + "urn:example:feature:3"; + }; + }; + }; end); describe("parse", function() it("works", function() assert.same(d, map.parse(s, x)); end); + + it("handles arrays", function () + assert.same(disco, map.parse(disco_schema, disco_info)); + end); + end); describe("unparse", function() -- cgit v1.2.3