Mercurial > prosody-hg
comparison spec/util_stanza_spec.lua @ 9924:5a2e53bef031
util.stanza: Fix :top_tag() handling of namespaced attributes
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 25 Mar 2019 14:37:43 +0000 |
| parents | 51583ea2b4fd |
| children | 22db763c510c |
comparison
equal
deleted
inserted
replaced
| 9923:e83dfcdeab59 | 9924:5a2e53bef031 |
|---|---|
| 379 assert.has_error(function () | 379 assert.has_error(function () |
| 380 st.clone("this is not a stanza"); | 380 st.clone("this is not a stanza"); |
| 381 end); | 381 end); |
| 382 end); | 382 end); |
| 383 end); | 383 end); |
| 384 | |
| 385 describe("top_tag", function () | |
| 386 local xml_parse = require "util.xml".parse; | |
| 387 it("works", function () | |
| 388 local s = st.message({type="chat"}, "Hello"); | |
| 389 local top_tag = s:top_tag(); | |
| 390 assert.is_string(top_tag); | |
| 391 assert.not_equal("/>", top_tag:sub(-2, -1)); | |
| 392 assert.equal(">", top_tag:sub(-1, -1)); | |
| 393 local s2 = xml_parse(top_tag.."</message>"); | |
| 394 assert(st.is_stanza(s2)); | |
| 395 assert.equal("message", s2.name); | |
| 396 assert.equal(0, #s2); | |
| 397 assert.equal(0, #s2.tags); | |
| 398 assert.equal("chat", s2.attr.type); | |
| 399 end); | |
| 400 | |
| 401 it("works with namespaced attributes", function () | |
| 402 local s = xml_parse[[<message foo:bar='true' xmlns:foo='my-awesome-ns'/>]]; | |
| 403 local top_tag = s:top_tag(); | |
| 404 assert.is_string(top_tag); | |
| 405 assert.not_equal("/>", top_tag:sub(-2, -1)); | |
| 406 assert.equal(">", top_tag:sub(-1, -1)); | |
| 407 local s2 = xml_parse(top_tag.."</message>"); | |
| 408 assert(st.is_stanza(s2)); | |
| 409 assert.equal("message", s2.name); | |
| 410 assert.equal(0, #s2); | |
| 411 assert.equal(0, #s2.tags); | |
| 412 assert.equal("true", s2.attr["my-awesome-ns\1bar"]); | |
| 413 end); | |
| 414 end); | |
| 384 end); | 415 end); |
