Software /
code /
prosody
Comparison
spec/util_stanza_spec.lua @ 8626:20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 18 Mar 2018 11:32:00 +0000 |
parent | 8621:e3e9479d526e |
child | 8641:c7734b59506f |
comparison
equal
deleted
inserted
replaced
8625:08bf4df6fdb7 | 8626:20532f191f8d |
---|---|
163 assert.are.equal(#r.tags, 1); | 163 assert.are.equal(#r.tags, 1); |
164 assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); | 164 assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); |
165 end); | 165 end); |
166 end); | 166 end); |
167 | 167 |
168 describe("#invalid", function () | 168 describe("should reject #invalid", function () |
169 it("name should be rejected", function () | 169 local invalid_names = { |
170 assert.has_error(function () | 170 ["empty string"] = "", ["characters"] = "<>"; |
171 st.stanza(1234); | 171 } |
172 end); | 172 local invalid_data = { |
173 assert.has_error(function () | 173 ["number"] = 1234, ["table"] = {}; |
174 st.stanza({}); | 174 ["utf8"] = string.char(0xF4, 0x90, 0x80, 0x80); |
175 end); | 175 }; |
176 assert.has_error(function () | 176 |
177 st.stanza(); | 177 for value_type, value in pairs(invalid_names) do |
178 end); | 178 it(value_type.." in tag names", function () |
179 assert.has_error(function () | 179 assert.error_matches(function () |
180 st.stanza(""); | 180 st.stanza(value); |
181 end); | 181 end, value_type); |
182 assert.has_error(function () | 182 end); |
183 st.stanza(string.char(0xC0)); | 183 it(value_type.." in attribute names", function () |
184 end); | 184 assert.error_matches(function () |
185 assert.has_error(function () | 185 st.stanza("valid", { [value] = "valid" }); |
186 st.stanza(string.char(0xF4, 0x90, 0x80, 0x80)); | 186 end, value_type); |
187 end); | 187 end); |
188 assert.has_error(function () | 188 end |
189 st.stanza("<>"); | 189 for value_type, value in pairs(invalid_data) do |
190 end); | 190 it(value_type.." in tag names", function () |
191 assert.has_error(function () | 191 assert.error_matches(function () |
192 st.stanza("&"); | 192 st.stanza(value); |
193 end); | 193 end, value_type); |
194 end); | 194 end); |
195 it("UTF-8 should be rejected", function () | 195 it(value_type.." in attribute names", function () |
196 assert.has_error(function () | 196 assert.error_matches(function () |
197 st.stanza("tag"):text("hello "..string.char(0xF4, 0x90, 0x80, 0x80).." world"); | 197 st.stanza("valid", { [value] = "valid" }); |
198 end); | 198 end, value_type); |
199 end); | 199 end); |
200 it(value_type.." in attribute values", function () | |
201 assert.error_matches(function () | |
202 st.stanza("valid", { valid = value }); | |
203 end, value_type); | |
204 end); | |
205 it(value_type.." in text node", function () | |
206 assert.error_matches(function () | |
207 st.stanza("valid"):text(value); | |
208 end, value_type); | |
209 end); | |
210 end | |
200 end); | 211 end); |
201 | 212 |
202 describe("#is_stanza", function () | 213 describe("#is_stanza", function () |
203 -- is_stanza(any) -> boolean | 214 -- is_stanza(any) -> boolean |
204 it("identifies stanzas as stanzas", function () | 215 it("identifies stanzas as stanzas", function () |