Mercurial > prosody-hg
comparison spec/util_stanza_spec.lua @ 9675:7d8e08f80dbd
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 02 Dec 2018 02:38:36 +0100 |
| parents | e7e75b091c96 |
| children | 51583ea2b4fd 9d1e21c23784 |
comparison
equal
deleted
inserted
replaced
| 9671:e50559a42dfe | 9675:7d8e08f80dbd |
|---|---|
| 2 local st = require "util.stanza"; | 2 local st = require "util.stanza"; |
| 3 | 3 |
| 4 describe("util.stanza", function() | 4 describe("util.stanza", function() |
| 5 describe("#preserialize()", function() | 5 describe("#preserialize()", function() |
| 6 it("should work", function() | 6 it("should work", function() |
| 7 local stanza = st.stanza("message", { a = "a" }); | 7 local stanza = st.stanza("message", { type = "chat" }):text_tag("body", "Hello"); |
| 8 local stanza2 = st.preserialize(stanza); | 8 local stanza2 = st.preserialize(stanza); |
| 9 assert.is_string(stanza2 and stanza.name, "preserialize returns a stanza"); | 9 assert.is_table(stanza2, "Preserialized stanza is a table"); |
| 10 assert.is_nil(getmetatable(stanza2), "Preserialized stanza has no metatable"); | |
| 11 assert.is_string(stanza2.name, "Preserialized stanza has a name field"); | |
| 12 assert.equal(stanza.name, stanza2.name, "Preserialized stanza has same name as the input stanza"); | |
| 13 assert.same(stanza.attr, stanza2.attr, "Preserialized stanza same attr table as input stanza"); | |
| 10 assert.is_nil(stanza2.tags, "Preserialized stanza has no tag list"); | 14 assert.is_nil(stanza2.tags, "Preserialized stanza has no tag list"); |
| 11 assert.is_nil(stanza2.last_add, "Preserialized stanza has no last_add marker"); | 15 assert.is_nil(stanza2.last_add, "Preserialized stanza has no last_add marker"); |
| 12 assert.is_nil(getmetatable(stanza2), "Preserialized stanza has no metatable"); | 16 assert.is_table(stanza2[1], "Preserialized child element preserved"); |
| 13 end); | 17 assert.equal("body", stanza2[1].name, "Preserialized child element name preserved"); |
| 14 end); | 18 end); |
| 15 | 19 end); |
| 16 describe("#preserialize()", function() | 20 |
| 17 it("should work", function() | 21 describe("#deserialize()", function() |
| 18 local stanza = st.stanza("message", { a = "a" }); | 22 it("should work", function() |
| 23 local stanza = { name = "message", attr = { type = "chat" }, { name = "body", attr = { }, "Hello" } }; | |
| 19 local stanza2 = st.deserialize(st.preserialize(stanza)); | 24 local stanza2 = st.deserialize(st.preserialize(stanza)); |
| 20 assert.is_string(stanza2 and stanza.name, "deserialize returns a stanza"); | 25 |
| 21 assert.is_table(stanza2.attr, "Deserialized stanza has attributes"); | 26 assert.is_table(stanza2, "Deserialized stanza is a table"); |
| 22 assert.are.equal(stanza2.attr.a, "a", "Deserialized stanza retains attributes"); | 27 assert.equal(st.stanza_mt, getmetatable(stanza2), "Deserialized stanza has stanza metatable"); |
| 23 assert.is_table(getmetatable(stanza2), "Deserialized stanza has metatable"); | 28 assert.is_string(stanza2.name, "Deserialized stanza has a name field"); |
| 29 assert.equal(stanza.name, stanza2.name, "Deserialized stanza has same name as the input table"); | |
| 30 assert.same(stanza.attr, stanza2.attr, "Deserialized stanza same attr table as input table"); | |
| 31 assert.is_table(stanza2.tags, "Deserialized stanza has tag list"); | |
| 32 assert.is_table(stanza2[1], "Deserialized child element preserved"); | |
| 33 assert.equal("body", stanza2[1].name, "Deserialized child element name preserved"); | |
| 24 end); | 34 end); |
| 25 end); | 35 end); |
| 26 | 36 |
| 27 describe("#stanza()", function() | 37 describe("#stanza()", function() |
| 28 it("should work", function() | 38 it("should work", function() |
