diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-03-21 22:08:54 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-03-21 22:08:54 +0000 |
commit | b05ae66934aec8ae910856f9c90ae89fef9d2fef (patch) | |
tree | 22534ab4096520f751f6c414729ef8f4c6814dca /spec | |
parent | 9306e1a074ac5480754da10722919f147af7d65f (diff) | |
download | prosody-b05ae66934aec8ae910856f9c90ae89fef9d2fef.tar.gz prosody-b05ae66934aec8ae910856f9c90ae89fef9d2fef.zip |
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Diffstat (limited to 'spec')
-rw-r--r-- | spec/util_stanza_spec.lua | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index cd5a0dc3..36bf213f 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -68,6 +68,12 @@ describe("util.stanza", function() assert.are.equal(s.attr.xmlns, "myxmlns"); assert.are.equal(s.attr["Объект"], "&"); end); + it("should allow :text() with nil and empty strings", function () + local s_control = st.stanza("foo"); + assert.same(st.stanza("foo"):text(), s_control); + assert.same(st.stanza("foo"):text(nil), s_control); + assert.same(st.stanza("foo"):text(""), s_control); + end); end); describe("#message()", function() @@ -172,6 +178,7 @@ describe("util.stanza", function() local invalid_data = { ["number"] = 1234, ["table"] = {}; ["utf8"] = string.char(0xF4, 0x90, 0x80, 0x80); + ["nil"] = "nil"; ["boolean"] = true; }; for value_type, value in pairs(invalid_names) do @@ -187,6 +194,7 @@ describe("util.stanza", function() end); end for value_type, value in pairs(invalid_data) do + if value == "nil" then value = nil; end it(value_type.." in tag names", function () assert.error_matches(function () st.stanza(value); @@ -197,16 +205,18 @@ describe("util.stanza", function() st.stanza("valid", { [value] = "valid" }); end, value_type); end); - it(value_type.." in attribute values", function () - assert.error_matches(function () - st.stanza("valid", { valid = value }); - end, value_type); - end); - it(value_type.." in text node", function () - assert.error_matches(function () - st.stanza("valid"):text(value); - end, value_type); - end); + if value ~= nil then + it(value_type.." in attribute values", function () + assert.error_matches(function () + st.stanza("valid", { valid = value }); + end, value_type); + end); + it(value_type.." in text node", function () + assert.error_matches(function () + st.stanza("valid"):text(value); + end, value_type); + end); + end end end); |