spec/util_stanza_spec.lua
changeset 12143 7d6497294d92
parent 11790 39164ea2ab9e
child 12145 3ac801630b4b
equal deleted inserted replaced
12142:644ca3583837 12143:7d6497294d92
    83 			local s_control = st.stanza("foo");
    83 			local s_control = st.stanza("foo");
    84 			assert.same(st.stanza("foo"):text(), s_control);
    84 			assert.same(st.stanza("foo"):text(), s_control);
    85 			assert.same(st.stanza("foo"):text(nil), s_control);
    85 			assert.same(st.stanza("foo"):text(nil), s_control);
    86 			assert.same(st.stanza("foo"):text(""), s_control);
    86 			assert.same(st.stanza("foo"):text(""), s_control);
    87 		end);
    87 		end);
       
    88 		it("validates names", function ()
       
    89 			assert.has_error_match(function ()
       
    90 				st.stanza("invalid\0name");
       
    91 			end, "invalid tag name:")
       
    92 			assert.has_error_match(function ()
       
    93 				st.stanza("name", { ["foo\1\2\3bar"] = "baz" });
       
    94 			end, "invalid attribute name: contains control characters")
       
    95 			assert.has_error_match(function ()
       
    96 				st.stanza("name", { ["foo"] = "baz\1\2\3\255moo" });
       
    97 			end, "invalid attribute value: contains control characters")
       
    98 		end)
       
    99 		it("validates types", function ()
       
   100 			assert.has_error_match(function ()
       
   101 				st.stanza(1);
       
   102 			end, "invalid tag name: expected string, got number")
       
   103 			assert.has_error_match(function ()
       
   104 				st.stanza("name", "string");
       
   105 			end, "invalid attributes: expected table, got string")
       
   106 			assert.has_error_match(function ()
       
   107 				st.stanza("name",{1});
       
   108 			end, "invalid attribute name: expected string, got number")
       
   109 			assert.has_error_match(function ()
       
   110 				st.stanza("name",{foo=1});
       
   111 			end, "invalid attribute value: expected string, got number")
       
   112 		end)
    88 	end);
   113 	end);
    89 
   114 
    90 	describe("#message()", function()
   115 	describe("#message()", function()
    91 		it("should work", function()
   116 		it("should work", function()
    92 			local m = st.message();
   117 			local m = st.message();