# HG changeset patch # User Kim Alvefur # Date 1640955628 -3600 # Node ID 7d6497294d927a3790a3dc624f21c77268218092 # Parent 644ca358383766105d8f9d78e6706399ade3c4cd util.stanza: Increase test coverage to cover validation errors diff -r 644ca3583837 -r 7d6497294d92 spec/util_stanza_spec.lua --- a/spec/util_stanza_spec.lua Fri Dec 31 13:52:11 2021 +0100 +++ b/spec/util_stanza_spec.lua Fri Dec 31 14:00:28 2021 +0100 @@ -85,6 +85,31 @@ assert.same(st.stanza("foo"):text(nil), s_control); assert.same(st.stanza("foo"):text(""), s_control); end); + it("validates names", function () + assert.has_error_match(function () + st.stanza("invalid\0name"); + end, "invalid tag name:") + assert.has_error_match(function () + st.stanza("name", { ["foo\1\2\3bar"] = "baz" }); + end, "invalid attribute name: contains control characters") + assert.has_error_match(function () + st.stanza("name", { ["foo"] = "baz\1\2\3\255moo" }); + end, "invalid attribute value: contains control characters") + end) + it("validates types", function () + assert.has_error_match(function () + st.stanza(1); + end, "invalid tag name: expected string, got number") + assert.has_error_match(function () + st.stanza("name", "string"); + end, "invalid attributes: expected table, got string") + assert.has_error_match(function () + st.stanza("name",{1}); + end, "invalid attribute name: expected string, got number") + assert.has_error_match(function () + st.stanza("name",{foo=1}); + end, "invalid attribute value: expected string, got number") + end) end); describe("#message()", function()