aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_stanza_spec.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-12-02 02:16:21 +0100
committerKim Alvefur <zash@zash.se>2018-12-02 02:16:21 +0100
commit1bf2e5f5f4953df1e8155a0221704fee99aaac24 (patch)
tree445e9f46ca04de38f652b9844d5bb4c74fe7ff97 /spec/util_stanza_spec.lua
parent41656354bf9ff7b97d3482b7b623d15f2fe99e68 (diff)
downloadprosody-1bf2e5f5f4953df1e8155a0221704fee99aaac24.tar.gz
prosody-1bf2e5f5f4953df1e8155a0221704fee99aaac24.zip
util.stanza: Improve tests
Diffstat (limited to 'spec/util_stanza_spec.lua')
-rw-r--r--spec/util_stanza_spec.lua28
1 files changed, 19 insertions, 9 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index 7fe836c7..6fbae41a 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -4,23 +4,33 @@ local st = require "util.stanza";
describe("util.stanza", function()
describe("#preserialize()", function()
it("should work", function()
- local stanza = st.stanza("message", { a = "a" });
+ local stanza = st.stanza("message", { type = "chat" }):text_tag("body", "Hello");
local stanza2 = st.preserialize(stanza);
- assert.is_string(stanza2 and stanza.name, "preserialize returns a stanza");
+ assert.is_table(stanza2, "Preserialized stanza is a table");
+ assert.is_nil(getmetatable(stanza2), "Preserialized stanza has no metatable");
+ assert.is_string(stanza2.name, "Preserialized stanza has a name field");
+ assert.equal(stanza.name, stanza2.name, "Preserialized stanza has same name as the input stanza");
+ assert.same(stanza.attr, stanza2.attr, "Preserialized stanza same attr table as input stanza");
assert.is_nil(stanza2.tags, "Preserialized stanza has no tag list");
assert.is_nil(stanza2.last_add, "Preserialized stanza has no last_add marker");
- assert.is_nil(getmetatable(stanza2), "Preserialized stanza has no metatable");
+ assert.is_table(stanza2[1], "Preserialized child element preserved");
+ assert.equal("body", stanza2[1].name, "Preserialized child element name preserved");
end);
end);
- describe("#preserialize()", function()
+ describe("#deserialize()", function()
it("should work", function()
- local stanza = st.stanza("message", { a = "a" });
+ local stanza = { name = "message", attr = { type = "chat" }, { name = "body", attr = { }, "Hello" } };
local stanza2 = st.deserialize(st.preserialize(stanza));
- assert.is_string(stanza2 and stanza.name, "deserialize returns a stanza");
- assert.is_table(stanza2.attr, "Deserialized stanza has attributes");
- assert.are.equal(stanza2.attr.a, "a", "Deserialized stanza retains attributes");
- assert.is_table(getmetatable(stanza2), "Deserialized stanza has metatable");
+
+ assert.is_table(stanza2, "Deserialized stanza is a table");
+ assert.equal(st.stanza_mt, getmetatable(stanza2), "Deserialized stanza has stanza metatable");
+ assert.is_string(stanza2.name, "Deserialized stanza has a name field");
+ assert.equal(stanza.name, stanza2.name, "Deserialized stanza has same name as the input table");
+ assert.same(stanza.attr, stanza2.attr, "Deserialized stanza same attr table as input table");
+ assert.is_table(stanza2.tags, "Deserialized stanza has tag list");
+ assert.is_table(stanza2[1], "Deserialized child element preserved");
+ assert.equal("body", stanza2[1].name, "Deserialized child element name preserved");
end);
end);