Software /
code /
prosody
Diff
spec/util_stanza_spec.lua @ 8626:20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 18 Mar 2018 11:32:00 +0000 |
parent | 8621:e3e9479d526e |
child | 8641:c7734b59506f |
line wrap: on
line diff
--- a/spec/util_stanza_spec.lua Sat Mar 17 22:03:08 2018 +0000 +++ b/spec/util_stanza_spec.lua Sun Mar 18 11:32:00 2018 +0000 @@ -165,38 +165,49 @@ 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({}); - end); - assert.has_error(function () - st.stanza(); - 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)); + 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(string.char(0xF4, 0x90, 0x80, 0x80)); - 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("&"); + it(value_type.." in attribute values", function () + assert.error_matches(function () + st.stanza("valid", { valid = value }); + end, value_type); 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"); + it(value_type.." in text node", function () + assert.error_matches(function () + st.stanza("valid"):text(value); + end, value_type); end); - end); + end end); describe("#is_stanza", function ()