diff options
author | Kim Alvefur <zash@zash.se> | 2021-03-20 20:45:06 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-03-20 20:45:06 +0100 |
commit | f5962d7193fbd92687248ef97b4673248defc751 (patch) | |
tree | 2ebebcbac764078d4f3e17072cdad64ebe3df0b2 /spec | |
parent | 87474145e51cd0460e8c6608c2dcb7a712d9ef3c (diff) | |
download | prosody-f5962d7193fbd92687248ef97b4673248defc751.tar.gz prosody-f5962d7193fbd92687248ef97b4673248defc751.zip |
util.datamapper: Finally implement support for parsing arrays
Diffstat (limited to 'spec')
-rw-r--r-- | spec/util_datamapper_spec.lua | 63 |
1 files changed, 63 insertions, 0 deletions
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[[ + <iq type="result" id="disco1" from="example.com"> + <query xmlns="http://jabber.org/protocol/disco#info"> + <feature var="urn:example:feature:1">wrong</feature> + <feature var="urn:example:feature:2"/> + <feature var="urn:example:feature:3"/> + <unrelated var="urn:example:feature:not"/> + </query> + </iq> + ]]; + + 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() |