comparison spec/util_dataforms_spec.lua @ 12636:e8934ce6ea0f

util.stanza: Add method for extracting a single attribute value Sometimes you only care about a single attribute, but the child tag itself may be optional, leading to needing `tag and tag.attr.foo` or `stanza:find("tag@foo")`. The `:find()` method is fairly complex, so avoiding it for this kind of simpler use case is a win.
author Kim Alvefur <zash@zash.se>
date Wed, 17 Aug 2022 19:04:30 +0200
parents 05c250fa335a
children
comparison
equal deleted inserted replaced
12635:f928cb5c5d04 12636:e8934ce6ea0f
128 it("XML serialization looks like it should", function () 128 it("XML serialization looks like it should", function ()
129 assert.truthy(xform); 129 assert.truthy(xform);
130 assert.truthy(st.is_stanza(xform)); 130 assert.truthy(st.is_stanza(xform));
131 assert.equal("x", xform.name); 131 assert.equal("x", xform.name);
132 assert.equal("jabber:x:data", xform.attr.xmlns); 132 assert.equal("jabber:x:data", xform.attr.xmlns);
133 assert.equal("FORM_TYPE", xform:find("field@var")); 133 assert.equal("FORM_TYPE", xform:get_child_attr("field", nil, "var"));
134 assert.equal("xmpp:prosody.im/spec/util.dataforms#1", xform:find("field/value#")); 134 assert.equal("xmpp:prosody.im/spec/util.dataforms#1", xform:find("field/value#"));
135 local allowed_direct_children = { 135 local allowed_direct_children = {
136 title = true, 136 title = true,
137 instructions = true, 137 instructions = true,
138 field = true, 138 field = true,