diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-03-18 11:32:00 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-03-18 11:32:00 +0000 |
commit | 7d4e55d56724da8a4d393cee7d2a9d40f2cbb46a (patch) | |
tree | 76240d77c93f0068bcbcd6ec907a7863f41f605f /spec/util_stanza_spec.lua | |
parent | a87f39878abf4897c2fd0430898dc1b8cc4fc33e (diff) | |
download | prosody-7d4e55d56724da8a4d393cee7d2a9d40f2cbb46a.tar.gz prosody-7d4e55d56724da8a4d393cee7d2a9d40f2cbb46a.zip |
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Diffstat (limited to 'spec/util_stanza_spec.lua')
-rw-r--r-- | spec/util_stanza_spec.lua | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index f7759385..cd5a0dc3 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -165,38 +165,49 @@ describe("util.stanza", function() end); end); - describe("#invalid", function () - it("name should be rejected", function () - assert.has_error(function () - st.stanza(1234); + describe("should reject #invalid", function () + local invalid_names = { + ["empty string"] = "", ["characters"] = "<>"; + } + local invalid_data = { + ["number"] = 1234, ["table"] = {}; + ["utf8"] = string.char(0xF4, 0x90, 0x80, 0x80); + }; + + for value_type, value in pairs(invalid_names) do + it(value_type.." in tag names", function () + assert.error_matches(function () + st.stanza(value); + end, value_type); end); - assert.has_error(function () - st.stanza({}); + it(value_type.." in attribute names", function () + assert.error_matches(function () + st.stanza("valid", { [value] = "valid" }); + end, value_type); end); - assert.has_error(function () - st.stanza(); + end + for value_type, value in pairs(invalid_data) do + it(value_type.." in tag names", function () + assert.error_matches(function () + st.stanza(value); + end, value_type); end); - assert.has_error(function () - st.stanza(""); + it(value_type.." in attribute names", function () + assert.error_matches(function () + st.stanza("valid", { [value] = "valid" }); + end, value_type); end); - assert.has_error(function () - st.stanza(string.char(0xC0)); + it(value_type.." in attribute values", function () + assert.error_matches(function () + st.stanza("valid", { valid = value }); + end, value_type); end); - assert.has_error(function () - st.stanza(string.char(0xF4, 0x90, 0x80, 0x80)); + it(value_type.." in text node", function () + assert.error_matches(function () + st.stanza("valid"):text(value); + end, value_type); end); - assert.has_error(function () - st.stanza("<>"); - end); - assert.has_error(function () - st.stanza("&"); - end); - end); - it("UTF-8 should be rejected", function () - assert.has_error(function () - st.stanza("tag"):text("hello "..string.char(0xF4, 0x90, 0x80, 0x80).." world"); - end); - end); + end end); describe("#is_stanza", function () |