Changeset

8641:c7734b59506f

util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
author Matthew Wild <mwild1@gmail.com>
date Wed, 21 Mar 2018 22:08:54 +0000
parents 8640:8f13ec2ceb06
children 8642:d2556f237bc2
files spec/util_stanza_spec.lua
diffstat 1 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/spec/util_stanza_spec.lua	Wed Mar 21 22:04:20 2018 +0000
+++ b/spec/util_stanza_spec.lua	Wed Mar 21 22:08:54 2018 +0000
@@ -68,6 +68,12 @@
 			assert.are.equal(s.attr.xmlns, "myxmlns");
 			assert.are.equal(s.attr["Объект"], "&");
 		end);
+		it("should allow :text() with nil and empty strings", function ()
+			local s_control = st.stanza("foo");
+			assert.same(st.stanza("foo"):text(), s_control);
+			assert.same(st.stanza("foo"):text(nil), s_control);
+			assert.same(st.stanza("foo"):text(""), s_control);
+		end);
 	end);
 
 	describe("#message()", function()
@@ -172,6 +178,7 @@
 		local invalid_data = {
 			["number"] = 1234, ["table"] = {};
 			["utf8"] = string.char(0xF4, 0x90, 0x80, 0x80);
+			["nil"] = "nil"; ["boolean"] = true;
 		};
 
 		for value_type, value in pairs(invalid_names) do
@@ -187,6 +194,7 @@
 			end);
 		end
 		for value_type, value in pairs(invalid_data) do
+			if value == "nil" then value = nil; end
 			it(value_type.." in tag names", function ()
 				assert.error_matches(function ()
 					st.stanza(value);
@@ -197,16 +205,18 @@
 					st.stanza("valid", { [value] = "valid" });
 				end, value_type);
 			end);
-			it(value_type.." in attribute values", function ()
-				assert.error_matches(function ()
-					st.stanza("valid", { valid = value });
-				end, value_type);
-			end);
-			it(value_type.." in text node", function ()
-				assert.error_matches(function ()
-					st.stanza("valid"):text(value);
-				end, value_type);
-			end);
+			if value ~= nil then
+				it(value_type.." in attribute values", function ()
+					assert.error_matches(function ()
+						st.stanza("valid", { valid = value });
+					end, value_type);
+				end);
+				it(value_type.." in text node", function ()
+					assert.error_matches(function ()
+						st.stanza("valid"):text(value);
+					end, value_type);
+				end);
+			end
 		end
 	end);