Mercurial > prosody-hg
comparison spec/util_stanza_spec.lua @ 10411:db2a06b9ff98
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 16 Nov 2019 16:52:31 +0100 |
| parents | 5a2e53bef031 |
| children | 22db763c510c |
comparison
equal
deleted
inserted
replaced
| 10410:659b577f280c | 10411:db2a06b9ff98 |
|---|---|
| 93 end); | 93 end); |
| 94 end); | 94 end); |
| 95 | 95 |
| 96 describe("#iq()", function() | 96 describe("#iq()", function() |
| 97 it("should create an iq stanza", function() | 97 it("should create an iq stanza", function() |
| 98 local i = st.iq({ id = "foo" }); | 98 local i = st.iq({ type = "get", id = "foo" }); |
| 99 assert.are.equal("iq", i.name); | 99 assert.are.equal("iq", i.name); |
| 100 assert.are.equal("foo", i.attr.id); | 100 assert.are.equal("foo", i.attr.id); |
| 101 end); | 101 assert.are.equal("get", i.attr.type); |
| 102 end); | |
| 103 | |
| 104 it("should reject stanzas with no attributes", function () | |
| 105 assert.has.error_match(function () | |
| 106 st.iq(); | |
| 107 end, "attributes"); | |
| 108 end); | |
| 109 | |
| 102 | 110 |
| 103 it("should reject stanzas with no id", function () | 111 it("should reject stanzas with no id", function () |
| 104 assert.has.error_match(function () | 112 assert.has.error_match(function () |
| 105 st.iq(); | 113 st.iq({ type = "get" }); |
| 106 end, "id attribute"); | 114 end, "id attribute"); |
| 107 | 115 end); |
| 116 | |
| 117 it("should reject stanzas with no type", function () | |
| 108 assert.has.error_match(function () | 118 assert.has.error_match(function () |
| 109 st.iq({ foo = "bar" }); | 119 st.iq({ id = "foo" }); |
| 110 end, "id attribute"); | 120 end, "type attribute"); |
| 121 | |
| 111 end); | 122 end); |
| 112 end); | 123 end); |
| 113 | 124 |
| 114 describe("#presence()", function () | 125 describe("#presence()", function () |
| 115 it("should work", function() | 126 it("should work", function() |
| 368 assert.has_error(function () | 379 assert.has_error(function () |
| 369 st.clone("this is not a stanza"); | 380 st.clone("this is not a stanza"); |
| 370 end); | 381 end); |
| 371 end); | 382 end); |
| 372 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); | |
| 373 end); | 415 end); |
