diff options
author | Mark Pulford <mark@kyne.com.au> | 2012-01-16 23:48:29 +1030 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2012-03-04 18:54:35 +1030 |
commit | ea4a5f19fd539a332a84047025ceba0c11465b93 (patch) | |
tree | 5028ef0fc76a023b78dc6f6de1eb5467c70077e7 /tests | |
parent | 4500ab5520d0000bfeadfd550c13813ddf5eee60 (diff) | |
download | lua-cjson-ea4a5f19fd539a332a84047025ceba0c11465b93.tar.gz lua-cjson-ea4a5f19fd539a332a84047025ceba0c11465b93.tar.bz2 lua-cjson-ea4a5f19fd539a332a84047025ceba0c11465b93.zip |
Add "throw error" to test descriptions
Add "throw error" to descriptions for tests which are intended to
generate errors.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test.lua | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/tests/test.lua b/tests/test.lua index f432b22..3deb3e9 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
@@ -111,40 +111,40 @@ local cjson_tests = { | |||
111 | true, { { "one", json.null, "three" } } }, | 111 | true, { { "one", json.null, "three" } } }, |
112 | 112 | ||
113 | -- Test decoding errors | 113 | -- Test decoding errors |
114 | { "Decode UTF-16BE", | 114 | { "Decode UTF-16BE [throw error]", |
115 | json.decode, { '\0"\0"' }, | 115 | json.decode, { '\0"\0"' }, |
116 | false, { "JSON parser does not support UTF-16 or UTF-32" } }, | 116 | false, { "JSON parser does not support UTF-16 or UTF-32" } }, |
117 | { "Decode UTF-16LE", | 117 | { "Decode UTF-16LE [throw error]", |
118 | json.decode, { '"\0"\0' }, | 118 | json.decode, { '"\0"\0' }, |
119 | false, { "JSON parser does not support UTF-16 or UTF-32" } }, | 119 | false, { "JSON parser does not support UTF-16 or UTF-32" } }, |
120 | { "Decode UTF-32BE", | 120 | { "Decode UTF-32BE [throw error]", |
121 | json.decode, { '\0\0\0"' }, | 121 | json.decode, { '\0\0\0"' }, |
122 | false, { "JSON parser does not support UTF-16 or UTF-32" } }, | 122 | false, { "JSON parser does not support UTF-16 or UTF-32" } }, |
123 | { "Decode UTF-32LE", | 123 | { "Decode UTF-32LE [throw error]", |
124 | json.decode, { '"\0\0\0' }, | 124 | json.decode, { '"\0\0\0' }, |
125 | false, { "JSON parser does not support UTF-16 or UTF-32" } }, | 125 | false, { "JSON parser does not support UTF-16 or UTF-32" } }, |
126 | { "Decode partial JSON", | 126 | { "Decode partial JSON [throw error]", |
127 | json.decode, { '{ "unexpected eof": ' }, | 127 | json.decode, { '{ "unexpected eof": ' }, |
128 | false, { "Expected value but found T_END at character 21" } }, | 128 | false, { "Expected value but found T_END at character 21" } }, |
129 | { "Decode with extra comma", | 129 | { "Decode with extra comma [throw error]", |
130 | json.decode, { '{ "extra data": true }, false' }, | 130 | json.decode, { '{ "extra data": true }, false' }, |
131 | false, { "Expected the end but found T_COMMA at character 23" } }, | 131 | false, { "Expected the end but found T_COMMA at character 23" } }, |
132 | { "Decode invalid escape code", | 132 | { "Decode invalid escape code [throw error]", |
133 | json.decode, { [[ { "bad escape \q code" } ]] }, | 133 | json.decode, { [[ { "bad escape \q code" } ]] }, |
134 | false, { "Expected object key string but found invalid escape code at character 16" } }, | 134 | false, { "Expected object key string but found invalid escape code at character 16" } }, |
135 | { "Decode invalid unicode escape", | 135 | { "Decode invalid unicode escape [throw error]", |
136 | json.decode, { [[ { "bad unicode \u0f6 escape" } ]] }, | 136 | json.decode, { [[ { "bad unicode \u0f6 escape" } ]] }, |
137 | false, { "Expected object key string but found invalid unicode escape code at character 17" } }, | 137 | false, { "Expected object key string but found invalid unicode escape code at character 17" } }, |
138 | { "Decode invalid keyword", | 138 | { "Decode invalid keyword [throw error]", |
139 | json.decode, { ' [ "bad barewood", test ] ' }, | 139 | json.decode, { ' [ "bad barewood", test ] ' }, |
140 | false, { "Expected value but found invalid token at character 20" } }, | 140 | false, { "Expected value but found invalid token at character 20" } }, |
141 | { "Decode invalid number #1", | 141 | { "Decode invalid number #1 [throw error]", |
142 | json.decode, { '[ -+12 ]' }, | 142 | json.decode, { '[ -+12 ]' }, |
143 | false, { "Expected value but found invalid number at character 3" } }, | 143 | false, { "Expected value but found invalid number at character 3" } }, |
144 | { "Decode invalid number #2", | 144 | { "Decode invalid number #2 [throw error]", |
145 | json.decode, { '-v' }, | 145 | json.decode, { '-v' }, |
146 | false, { "Expected value but found invalid number at character 1" } }, | 146 | false, { "Expected value but found invalid number at character 1" } }, |
147 | { "Decode invalid number exponent", | 147 | { "Decode invalid number exponent [throw error]", |
148 | json.decode, { '[ 0.4eg10 ]' }, | 148 | json.decode, { '[ 0.4eg10 ]' }, |
149 | false, { "Expected comma or array end but found invalid token at character 6" } }, | 149 | false, { "Expected comma or array end but found invalid token at character 6" } }, |
150 | 150 | ||
@@ -154,13 +154,13 @@ local cjson_tests = { | |||
154 | { "Decode array at nested limit", | 154 | { "Decode array at nested limit", |
155 | json.decode, { '[[[[[ "nested" ]]]]]' }, | 155 | json.decode, { '[[[[[ "nested" ]]]]]' }, |
156 | true, { {{{{{ "nested" }}}}} } }, | 156 | true, { {{{{{ "nested" }}}}} } }, |
157 | { "Decode array over nested limit", | 157 | { "Decode array over nested limit [throw error]", |
158 | json.decode, { '[[[[[[ "nested" ]]]]]]' }, | 158 | json.decode, { '[[[[[[ "nested" ]]]]]]' }, |
159 | false, { "Too many nested data structures" } }, | 159 | false, { "Too many nested data structures" } }, |
160 | { "Decode object at nested limit", | 160 | { "Decode object at nested limit", |
161 | json.decode, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' }, | 161 | json.decode, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' }, |
162 | true, { {a={b={c={d={e="nested"}}}}} } }, | 162 | true, { {a={b={c={d={e="nested"}}}}} } }, |
163 | { "Decode object over nested limit", | 163 | { "Decode object over nested limit [throw error]", |
164 | json.decode, { '{"a":{"b":{"c":{"d":{"e":{"f":"nested"}}}}}}' }, | 164 | json.decode, { '{"a":{"b":{"c":{"d":{"e":{"f":"nested"}}}}}}' }, |
165 | false, { "Too many nested data structures" } }, | 165 | false, { "Too many nested data structures" } }, |
166 | { "Set decode_max_depth(1000)", | 166 | { "Set decode_max_depth(1000)", |
@@ -171,16 +171,16 @@ local cjson_tests = { | |||
171 | json.encode_max_depth, { 5 }, true, { 5 } }, | 171 | json.encode_max_depth, { 5 }, true, { 5 } }, |
172 | { "Encode nested table as array at nested limit", | 172 | { "Encode nested table as array at nested limit", |
173 | json.encode, { {{{{{"nested"}}}}} }, true, { '[[[[["nested"]]]]]' } }, | 173 | json.encode, { {{{{{"nested"}}}}} }, true, { '[[[[["nested"]]]]]' } }, |
174 | { "Encode nested table as array after nested limit", | 174 | { "Encode nested table as array after nested limit [throw error]", |
175 | json.encode, { { {{{{{"nested"}}}}} } }, | 175 | json.encode, { { {{{{{"nested"}}}}} } }, |
176 | false, { "Cannot serialise, excessive nesting (6)" } }, | 176 | false, { "Cannot serialise, excessive nesting (6)" } }, |
177 | { "Encode nested table as object at nested limit", | 177 | { "Encode nested table as object at nested limit", |
178 | json.encode, { {a={b={c={d={e="nested"}}}}} }, | 178 | json.encode, { {a={b={c={d={e="nested"}}}}} }, |
179 | true, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' } }, | 179 | true, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' } }, |
180 | { "Encode nested table as object over nested limit", | 180 | { "Encode nested table as object over nested limit [throw error]", |
181 | json.encode, { {a={b={c={d={e={f="nested"}}}}}} }, | 181 | json.encode, { {a={b={c={d={e={f="nested"}}}}}} }, |
182 | false, { "Cannot serialise, excessive nesting (6)" } }, | 182 | false, { "Cannot serialise, excessive nesting (6)" } }, |
183 | { "Encode table with cycle", | 183 | { "Encode table with cycle [throw error]", |
184 | json.encode, { testdata.table_cycle }, | 184 | json.encode, { testdata.table_cycle }, |
185 | false, { "Cannot serialise, excessive nesting (6)" } }, | 185 | false, { "Cannot serialise, excessive nesting (6)" } }, |
186 | { "Set encode_max_depth(1000)", | 186 | { "Set encode_max_depth(1000)", |
@@ -199,7 +199,7 @@ local cjson_tests = { | |||
199 | json.encode, { 10 }, true, { '10' } }, | 199 | json.encode, { 10 }, true, { '10' } }, |
200 | { "Encode string", | 200 | { "Encode string", |
201 | json.encode, { "hello" }, true, { '"hello"' } }, | 201 | json.encode, { "hello" }, true, { '"hello"' } }, |
202 | { "Encode Lua function", | 202 | { "Encode Lua function [throw error]", |
203 | json.encode, { function () end }, | 203 | json.encode, { function () end }, |
204 | false, { "Cannot serialise function: type not supported" } }, | 204 | false, { "Cannot serialise function: type not supported" } }, |
205 | 205 | ||
@@ -215,24 +215,24 @@ local cjson_tests = { | |||
215 | true, { { Inf, Inf, -Inf } } }, | 215 | true, { { Inf, Inf, -Inf } } }, |
216 | { "Decode +-NaN", | 216 | { "Decode +-NaN", |
217 | json.decode, { '[ +NaN, NaN, -NaN ]' }, true, { { NaN, NaN, NaN } } }, | 217 | json.decode, { '[ +NaN, NaN, -NaN ]' }, true, { { NaN, NaN, NaN } } }, |
218 | { "Decode Infrared (not infinity)", | 218 | { "Decode Infrared (not infinity) [throw error]", |
219 | json.decode, { 'Infrared' }, | 219 | json.decode, { 'Infrared' }, |
220 | false, { "Expected the end but found invalid token at character 4" } }, | 220 | false, { "Expected the end but found invalid token at character 4" } }, |
221 | { "Decode Noodle (not NaN)", | 221 | { "Decode Noodle (not NaN) [throw error]", |
222 | json.decode, { 'Noodle' }, | 222 | json.decode, { 'Noodle' }, |
223 | false, { "Expected value but found invalid token at character 1" } }, | 223 | false, { "Expected value but found invalid token at character 1" } }, |
224 | { "Set decode_invalid_numbers(false)", | 224 | { "Set decode_invalid_numbers(false)", |
225 | json.decode_invalid_numbers, { false }, true, { "off" } }, | 225 | json.decode_invalid_numbers, { false }, true, { "off" } }, |
226 | { "Decode hexadecimal (throw error)", | 226 | { "Decode hexadecimal [throw error]", |
227 | json.decode, { '0x6' }, | 227 | json.decode, { '0x6' }, |
228 | false, { "Expected value but found invalid number at character 1" } }, | 228 | false, { "Expected value but found invalid number at character 1" } }, |
229 | { "Decode +-Inf (throw error)", | 229 | { "Decode +-Inf [throw error]", |
230 | json.decode, { '[ +Inf, Inf, -Inf ]' }, | 230 | json.decode, { '[ +Inf, Inf, -Inf ]' }, |
231 | false, { "Expected value but found invalid token at character 3" } }, | 231 | false, { "Expected value but found invalid token at character 3" } }, |
232 | { "Decode +-Infinity (throw error)", | 232 | { "Decode +-Infinity [throw error]", |
233 | json.decode, { '[ +Infinity, Infinity, -Infinity ]' }, | 233 | json.decode, { '[ +Infinity, Infinity, -Infinity ]' }, |
234 | false, { "Expected value but found invalid token at character 3" } }, | 234 | false, { "Expected value but found invalid token at character 3" } }, |
235 | { "Decode +-NaN (throw error)", | 235 | { "Decode +-NaN [throw error]", |
236 | json.decode, { '[ +NaN, NaN, -NaN ]' }, | 236 | json.decode, { '[ +NaN, NaN, -NaN ]' }, |
237 | false, { "Expected value but found invalid token at character 3" } }, | 237 | false, { "Expected value but found invalid token at character 3" } }, |
238 | { 'Set decode_invalid_numbers("on")', | 238 | { 'Set decode_invalid_numbers("on")', |
@@ -241,10 +241,10 @@ local cjson_tests = { | |||
241 | -- Test encoding invalid numbers | 241 | -- Test encoding invalid numbers |
242 | { "Set encode_invalid_numbers(false)", | 242 | { "Set encode_invalid_numbers(false)", |
243 | json.encode_invalid_numbers, { false }, true, { "off" } }, | 243 | json.encode_invalid_numbers, { false }, true, { "off" } }, |
244 | { "Encode NaN (invalid numbers disabled)", | 244 | { "Encode NaN [throw error]", |
245 | json.encode, { NaN }, | 245 | json.encode, { NaN }, |
246 | false, { "Cannot serialise number: must not be NaN or Inf" } }, | 246 | false, { "Cannot serialise number: must not be NaN or Inf" } }, |
247 | { "Encode Infinity (invalid numbers disabled)", | 247 | { "Encode Infinity [throw error]", |
248 | json.encode, { Inf }, | 248 | json.encode, { Inf }, |
249 | false, { "Cannot serialise number: must not be NaN or Inf" } }, | 249 | false, { "Cannot serialise number: must not be NaN or Inf" } }, |
250 | { "Set encode_invalid_numbers(\"null\")", | 250 | { "Set encode_invalid_numbers(\"null\")", |
@@ -279,7 +279,7 @@ local cjson_tests = { | |||
279 | true, { '{"2":"numeric string key test"}' } }, | 279 | true, { '{"2":"numeric string key test"}' } }, |
280 | { "Set encode_sparse_array(false)", | 280 | { "Set encode_sparse_array(false)", |
281 | json.encode_sparse_array, { false }, true, { "off", 2, 3 } }, | 281 | json.encode_sparse_array, { false }, true, { "off", 2, 3 } }, |
282 | { "Encode table with incompatible key", | 282 | { "Encode table with incompatible key [throw error]", |
283 | json.encode, { { [false] = "wrong" } }, | 283 | json.encode, { { [false] = "wrong" } }, |
284 | false, { "Cannot serialise boolean: table key must be a number or string" } }, | 284 | false, { "Cannot serialise boolean: table key must be a number or string" } }, |
285 | 285 | ||
@@ -292,19 +292,19 @@ local cjson_tests = { | |||
292 | json.decode, { [["\uF800"]] }, true, { "\239\160\128" } }, | 292 | json.decode, { [["\uF800"]] }, true, { "\239\160\128" } }, |
293 | { "Decode all UTF-16 escapes (including surrogate combinations)", | 293 | { "Decode all UTF-16 escapes (including surrogate combinations)", |
294 | json.decode, { testdata.utf16_escaped }, true, { testdata.utf8_raw } }, | 294 | json.decode, { testdata.utf16_escaped }, true, { testdata.utf8_raw } }, |
295 | { "Decode swapped surrogate pair", | 295 | { "Decode swapped surrogate pair [throw error]", |
296 | json.decode, { [["\uDC00\uD800"]] }, | 296 | json.decode, { [["\uDC00\uD800"]] }, |
297 | false, { "Expected value but found invalid unicode escape code at character 2" } }, | 297 | false, { "Expected value but found invalid unicode escape code at character 2" } }, |
298 | { "Decode duplicate high surrogate", | 298 | { "Decode duplicate high surrogate [throw error]", |
299 | json.decode, { [["\uDB00\uDB00"]] }, | 299 | json.decode, { [["\uDB00\uDB00"]] }, |
300 | false, { "Expected value but found invalid unicode escape code at character 2" } }, | 300 | false, { "Expected value but found invalid unicode escape code at character 2" } }, |
301 | { "Decode duplicate low surrogate", | 301 | { "Decode duplicate low surrogate [throw error]", |
302 | json.decode, { [["\uDB00\uDB00"]] }, | 302 | json.decode, { [["\uDB00\uDB00"]] }, |
303 | false, { "Expected value but found invalid unicode escape code at character 2" } }, | 303 | false, { "Expected value but found invalid unicode escape code at character 2" } }, |
304 | { "Decode missing low surrogate", | 304 | { "Decode missing low surrogate [throw error]", |
305 | json.decode, { [["\uDB00"]] }, | 305 | json.decode, { [["\uDB00"]] }, |
306 | false, { "Expected value but found invalid unicode escape code at character 2" } }, | 306 | false, { "Expected value but found invalid unicode escape code at character 2" } }, |
307 | { "Decode invalid low surrogate", | 307 | { "Decode invalid low surrogate [throw error]", |
308 | json.decode, { [["\uDB00\uD"]] }, | 308 | json.decode, { [["\uDB00\uD"]] }, |
309 | false, { "Expected value but found invalid unicode escape code at character 2" } }, | 309 | false, { "Expected value but found invalid unicode escape code at character 2" } }, |
310 | 310 | ||
@@ -339,28 +339,28 @@ local cjson_tests = { | |||
339 | 339 | ||
340 | -- Test config API errors | 340 | -- Test config API errors |
341 | -- Function is listed as '?' due to pcall | 341 | -- Function is listed as '?' due to pcall |
342 | { "Set encode_number_precision(0)", | 342 | { "Set encode_number_precision(0) [throw error]", |
343 | json.encode_number_precision, { 0 }, | 343 | json.encode_number_precision, { 0 }, |
344 | false, { "bad argument #1 to '?' (expected integer between 1 and 14)" } }, | 344 | false, { "bad argument #1 to '?' (expected integer between 1 and 14)" } }, |
345 | { "Set encode_number_precision(\"five\")", | 345 | { "Set encode_number_precision(\"five\") [throw error]", |
346 | json.encode_number_precision, { "five" }, | 346 | json.encode_number_precision, { "five" }, |
347 | false, { "bad argument #1 to '?' (number expected, got string)" } }, | 347 | false, { "bad argument #1 to '?' (number expected, got string)" } }, |
348 | { "Set encode_keep_buffer(nil, true)", | 348 | { "Set encode_keep_buffer(nil, true) [throw error]", |
349 | json.encode_keep_buffer, { nil, true }, | 349 | json.encode_keep_buffer, { nil, true }, |
350 | false, { "bad argument #2 to '?' (found too many arguments)" } }, | 350 | false, { "bad argument #2 to '?' (found too many arguments)" } }, |
351 | { "Set encode_max_depth(\"wrong\")", | 351 | { "Set encode_max_depth(\"wrong\") [throw error]", |
352 | json.encode_max_depth, { "wrong" }, | 352 | json.encode_max_depth, { "wrong" }, |
353 | false, { "bad argument #1 to '?' (number expected, got string)" } }, | 353 | false, { "bad argument #1 to '?' (number expected, got string)" } }, |
354 | { "Set decode_max_depth(0)", | 354 | { "Set decode_max_depth(0) [throw error]", |
355 | json.decode_max_depth, { "0" }, | 355 | json.decode_max_depth, { "0" }, |
356 | false, { "bad argument #1 to '?' (expected integer between 1 and 2147483647)" } }, | 356 | false, { "bad argument #1 to '?' (expected integer between 1 and 2147483647)" } }, |
357 | { "Set encode_invalid_numbers(-2)", | 357 | { "Set encode_invalid_numbers(-2) [throw error]", |
358 | json.encode_invalid_numbers, { -2 }, | 358 | json.encode_invalid_numbers, { -2 }, |
359 | false, { "bad argument #1 to '?' (invalid option '-2')" } }, | 359 | false, { "bad argument #1 to '?' (invalid option '-2')" } }, |
360 | { "Set decode_invalid_numbers(true, false)", | 360 | { "Set decode_invalid_numbers(true, false) [throw error]", |
361 | json.decode_invalid_numbers, { true, false }, | 361 | json.decode_invalid_numbers, { true, false }, |
362 | false, { "bad argument #2 to '?' (found too many arguments)" } }, | 362 | false, { "bad argument #2 to '?' (found too many arguments)" } }, |
363 | { "Set encode_sparse_array(\"not quite on\")", | 363 | { "Set encode_sparse_array(\"not quite on\") [throw error]", |
364 | json.encode_sparse_array, { "not quite on" }, | 364 | json.encode_sparse_array, { "not quite on" }, |
365 | false, { "bad argument #1 to '?' (invalid option 'not quite on')" } }, | 365 | false, { "bad argument #1 to '?' (invalid option 'not quite on')" } }, |
366 | 366 | ||
@@ -371,7 +371,7 @@ local cjson_tests = { | |||
371 | true, { "off", 2, 10 } }, | 371 | true, { "off", 2, 10 } }, |
372 | } | 372 | } |
373 | 373 | ||
374 | print(string.format("Testing Lua CJSON version %s\n", json._VERSION)) | 374 | print(string.format("==> Testing Lua CJSON version %s\n", json._VERSION)) |
375 | 375 | ||
376 | util.run_test_group(cjson_tests) | 376 | util.run_test_group(cjson_tests) |
377 | 377 | ||