aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2012-01-18 20:00:09 +1030
committerMark Pulford <mark@kyne.com.au>2012-03-04 18:54:35 +1030
commit1a5460be319ac29af31f201fbf9775340262ba9b (patch)
tree590312b65704b47c674b08efe14b8464aa58ce5b /tests
parent90e08aa69d23df8c2eb3e231d57a46281d330f03 (diff)
downloadlua-cjson-1a5460be319ac29af31f201fbf9775340262ba9b.tar.gz
lua-cjson-1a5460be319ac29af31f201fbf9775340262ba9b.tar.bz2
lua-cjson-1a5460be319ac29af31f201fbf9775340262ba9b.zip
Return boolean values from configuration functions
Return boolean values from configuration functions to simplify usage in the common case. Eg,: if not cjson.encode_invalid_numbers() then .. end
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test.lua22
1 files changed, 11 insertions, 11 deletions
diff --git a/tests/test.lua b/tests/test.lua
index 8bb5b95..19fc1af 100755
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -217,7 +217,7 @@ local cjson_tests = {
217 217
218 -- Test decoding invalid numbers 218 -- Test decoding invalid numbers
219 { "Set decode_invalid_numbers(true)", 219 { "Set decode_invalid_numbers(true)",
220 json.decode_invalid_numbers, { true }, true, { "on" } }, 220 json.decode_invalid_numbers, { true }, true, { true } },
221 { "Decode hexadecimal", 221 { "Decode hexadecimal",
222 json.decode, { '0x6' }, true, { 6 } }, 222 json.decode, { '0x6' }, true, { 6 } },
223 { "Decode +-Inf", 223 { "Decode +-Inf",
@@ -234,7 +234,7 @@ local cjson_tests = {
234 json.decode, { 'Noodle' }, 234 json.decode, { 'Noodle' },
235 false, { "Expected value but found invalid token at character 1" } }, 235 false, { "Expected value but found invalid token at character 1" } },
236 { "Set decode_invalid_numbers(false)", 236 { "Set decode_invalid_numbers(false)",
237 json.decode_invalid_numbers, { false }, true, { "off" } }, 237 json.decode_invalid_numbers, { false }, true, { false } },
238 { "Decode hexadecimal [throw error]", 238 { "Decode hexadecimal [throw error]",
239 json.decode, { '0x6' }, 239 json.decode, { '0x6' },
240 false, { "Expected value but found invalid number at character 1" } }, 240 false, { "Expected value but found invalid number at character 1" } },
@@ -248,11 +248,11 @@ local cjson_tests = {
248 json.decode, { '[ +NaN, NaN, -NaN ]' }, 248 json.decode, { '[ +NaN, NaN, -NaN ]' },
249 false, { "Expected value but found invalid token at character 3" } }, 249 false, { "Expected value but found invalid token at character 3" } },
250 { 'Set decode_invalid_numbers("on")', 250 { 'Set decode_invalid_numbers("on")',
251 json.decode_invalid_numbers, { "on" }, true, { "on" } }, 251 json.decode_invalid_numbers, { "on" }, true, { true } },
252 252
253 -- Test encoding invalid numbers 253 -- Test encoding invalid numbers
254 { "Set encode_invalid_numbers(false)", 254 { "Set encode_invalid_numbers(false)",
255 json.encode_invalid_numbers, { false }, true, { "off" } }, 255 json.encode_invalid_numbers, { false }, true, { false } },
256 { "Encode NaN [throw error]", 256 { "Encode NaN [throw error]",
257 json.encode, { NaN }, 257 json.encode, { NaN },
258 false, { "Cannot serialise number: must not be NaN or Inf" } }, 258 false, { "Cannot serialise number: must not be NaN or Inf" } },
@@ -266,17 +266,17 @@ local cjson_tests = {
266 { "Encode Infinity as null", 266 { "Encode Infinity as null",
267 json.encode, { Inf }, true, { "null" } }, 267 json.encode, { Inf }, true, { "null" } },
268 { "Set encode_invalid_numbers(true)", 268 { "Set encode_invalid_numbers(true)",
269 json.encode_invalid_numbers, { true }, true, { "on" } }, 269 json.encode_invalid_numbers, { true }, true, { true } },
270 { "Encode NaN", 270 { "Encode NaN",
271 json.encode, { NaN }, true, { "nan" } }, 271 json.encode, { NaN }, true, { "nan" } },
272 { "Encode Infinity", 272 { "Encode Infinity",
273 json.encode, { Inf }, true, { "inf" } }, 273 json.encode, { Inf }, true, { "inf" } },
274 { 'Set encode_invalid_numbers("off")', 274 { 'Set encode_invalid_numbers("off")',
275 json.encode_invalid_numbers, { "off" }, true, { "off" } }, 275 json.encode_invalid_numbers, { "off" }, true, { false } },
276 276
277 -- Test encoding tables 277 -- Test encoding tables
278 { "Set encode_sparse_array(true, 2, 3)", 278 { "Set encode_sparse_array(true, 2, 3)",
279 json.encode_sparse_array, { true, 2, 3 }, true, { "on", 2, 3 } }, 279 json.encode_sparse_array, { true, 2, 3 }, true, { true, 2, 3 } },
280 { "Encode sparse table as array #1", 280 { "Encode sparse table as array #1",
281 json.encode, { { [3] = "sparse test" } }, 281 json.encode, { { [3] = "sparse test" } },
282 true, { '[null,null,"sparse test"]' } }, 282 true, { '[null,null,"sparse test"]' } },
@@ -290,7 +290,7 @@ local cjson_tests = {
290 json.encode, { { ["2"] = "numeric string key test" } }, 290 json.encode, { { ["2"] = "numeric string key test" } },
291 true, { '{"2":"numeric string key test"}' } }, 291 true, { '{"2":"numeric string key test"}' } },
292 { "Set encode_sparse_array(false)", 292 { "Set encode_sparse_array(false)",
293 json.encode_sparse_array, { false }, true, { "off", 2, 3 } }, 293 json.encode_sparse_array, { false }, true, { false, 2, 3 } },
294 { "Encode table with incompatible key [throw error]", 294 { "Encode table with incompatible key [throw error]",
295 json.encode, { { [false] = "wrong" } }, 295 json.encode, { { [false] = "wrong" } },
296 false, { "Cannot serialise boolean: table key must be a number or string" } }, 296 false, { "Cannot serialise boolean: table key must be a number or string" } },
@@ -339,7 +339,7 @@ local cjson_tests = {
339 339
340 -- Test encode_keep_buffer() and enable_number_precision() 340 -- Test encode_keep_buffer() and enable_number_precision()
341 { "Set encode_keep_buffer(false)", 341 { "Set encode_keep_buffer(false)",
342 json.encode_keep_buffer, { false }, true, { "off" } }, 342 json.encode_keep_buffer, { false }, true, { false } },
343 { "Set encode_number_precision(3)", 343 { "Set encode_number_precision(3)",
344 json.encode_number_precision, { 3 }, true, { 3 } }, 344 json.encode_number_precision, { 3 }, true, { 3 } },
345 { "Encode number with precision 3", 345 { "Encode number with precision 3",
@@ -347,7 +347,7 @@ local cjson_tests = {
347 { "Set encode_number_precision(14)", 347 { "Set encode_number_precision(14)",
348 json.encode_number_precision, { 14 }, true, { 14 } }, 348 json.encode_number_precision, { 14 }, true, { 14 } },
349 { "Set encode_keep_buffer(true)", 349 { "Set encode_keep_buffer(true)",
350 json.encode_keep_buffer, { true }, true, { "on" } }, 350 json.encode_keep_buffer, { true }, true, { true } },
351 351
352 -- Test config API errors 352 -- Test config API errors
353 -- Function is listed as '?' due to pcall 353 -- Function is listed as '?' due to pcall
@@ -380,7 +380,7 @@ local cjson_tests = {
380 -- Wrap in a function to ensure the table returned by json.new() is used 380 -- Wrap in a function to ensure the table returned by json.new() is used
381 { "Check encode_sparse_array()", 381 { "Check encode_sparse_array()",
382 function (...) return json.encode_sparse_array(...) end, { }, 382 function (...) return json.encode_sparse_array(...) end, { },
383 true, { "off", 2, 10 } }, 383 true, { false, 2, 10 } },
384} 384}
385 385
386print(string.format("==> Testing Lua CJSON version %s\n", json._VERSION)) 386print(string.format("==> Testing Lua CJSON version %s\n", json._VERSION))