Mercurial > prosody-hg
comparison spec/util_stanza_spec.lua @ 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 | 20532f191f8d |
| children | 4d64ff0719a6 |
comparison
equal
deleted
inserted
replaced
| 8640:8f13ec2ceb06 | 8641:c7734b59506f |
|---|---|
| 65 it("should work with unicode values", function () | 65 it("should work with unicode values", function () |
| 66 local s = st.stanza("Объект", { xmlns = "myxmlns", ["Объект"] = "&" }); | 66 local s = st.stanza("Объект", { xmlns = "myxmlns", ["Объект"] = "&" }); |
| 67 assert.are.equal(s.name, "Объект"); | 67 assert.are.equal(s.name, "Объект"); |
| 68 assert.are.equal(s.attr.xmlns, "myxmlns"); | 68 assert.are.equal(s.attr.xmlns, "myxmlns"); |
| 69 assert.are.equal(s.attr["Объект"], "&"); | 69 assert.are.equal(s.attr["Объект"], "&"); |
| 70 end); | |
| 71 it("should allow :text() with nil and empty strings", function () | |
| 72 local s_control = st.stanza("foo"); | |
| 73 assert.same(st.stanza("foo"):text(), s_control); | |
| 74 assert.same(st.stanza("foo"):text(nil), s_control); | |
| 75 assert.same(st.stanza("foo"):text(""), s_control); | |
| 70 end); | 76 end); |
| 71 end); | 77 end); |
| 72 | 78 |
| 73 describe("#message()", function() | 79 describe("#message()", function() |
| 74 it("should work", function() | 80 it("should work", function() |
| 170 ["empty string"] = "", ["characters"] = "<>"; | 176 ["empty string"] = "", ["characters"] = "<>"; |
| 171 } | 177 } |
| 172 local invalid_data = { | 178 local invalid_data = { |
| 173 ["number"] = 1234, ["table"] = {}; | 179 ["number"] = 1234, ["table"] = {}; |
| 174 ["utf8"] = string.char(0xF4, 0x90, 0x80, 0x80); | 180 ["utf8"] = string.char(0xF4, 0x90, 0x80, 0x80); |
| 181 ["nil"] = "nil"; ["boolean"] = true; | |
| 175 }; | 182 }; |
| 176 | 183 |
| 177 for value_type, value in pairs(invalid_names) do | 184 for value_type, value in pairs(invalid_names) do |
| 178 it(value_type.." in tag names", function () | 185 it(value_type.." in tag names", function () |
| 179 assert.error_matches(function () | 186 assert.error_matches(function () |
| 185 st.stanza("valid", { [value] = "valid" }); | 192 st.stanza("valid", { [value] = "valid" }); |
| 186 end, value_type); | 193 end, value_type); |
| 187 end); | 194 end); |
| 188 end | 195 end |
| 189 for value_type, value in pairs(invalid_data) do | 196 for value_type, value in pairs(invalid_data) do |
| 197 if value == "nil" then value = nil; end | |
| 190 it(value_type.." in tag names", function () | 198 it(value_type.." in tag names", function () |
| 191 assert.error_matches(function () | 199 assert.error_matches(function () |
| 192 st.stanza(value); | 200 st.stanza(value); |
| 193 end, value_type); | 201 end, value_type); |
| 194 end); | 202 end); |
| 195 it(value_type.." in attribute names", function () | 203 it(value_type.." in attribute names", function () |
| 196 assert.error_matches(function () | 204 assert.error_matches(function () |
| 197 st.stanza("valid", { [value] = "valid" }); | 205 st.stanza("valid", { [value] = "valid" }); |
| 198 end, value_type); | 206 end, value_type); |
| 199 end); | 207 end); |
| 200 it(value_type.." in attribute values", function () | 208 if value ~= nil then |
| 201 assert.error_matches(function () | 209 it(value_type.." in attribute values", function () |
| 202 st.stanza("valid", { valid = value }); | 210 assert.error_matches(function () |
| 203 end, value_type); | 211 st.stanza("valid", { valid = value }); |
| 204 end); | 212 end, value_type); |
| 205 it(value_type.." in text node", function () | 213 end); |
| 206 assert.error_matches(function () | 214 it(value_type.." in text node", function () |
| 207 st.stanza("valid"):text(value); | 215 assert.error_matches(function () |
| 208 end, value_type); | 216 st.stanza("valid"):text(value); |
| 209 end); | 217 end, value_type); |
| 218 end); | |
| 219 end | |
| 210 end | 220 end |
| 211 end); | 221 end); |
| 212 | 222 |
| 213 describe("#is_stanza", function () | 223 describe("#is_stanza", function () |
| 214 -- is_stanza(any) -> boolean | 224 -- is_stanza(any) -> boolean |
