aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-03-18 11:32:00 +0000
committerMatthew Wild <mwild1@gmail.com>2018-03-18 11:32:00 +0000
commit65f4b853a0d32f8b390f526d2044ba66fb20a603 (patch)
tree76240d77c93f0068bcbcd6ec907a7863f41f605f /spec
parent1490ff5472f84062ff4c08c27fdebe1c1fb91288 (diff)
downloadprosody-65f4b853a0d32f8b390f526d2044ba66fb20a603.tar.gz
prosody-65f4b853a0d32f8b390f526d2044ba66fb20a603.zip
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Diffstat (limited to 'spec')
-rw-r--r--spec/util_stanza_spec.lua63
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 ()