Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpx/lua-cjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2012-01-16 17:18:29 +0400
committerMark Pulford <mark@kyne.com.au>2012-03-04 12:24:35 +0400
commitea4a5f19fd539a332a84047025ceba0c11465b93 (patch)
tree5028ef0fc76a023b78dc6f6de1eb5467c70077e7 /tests
parent4500ab5520d0000bfeadfd550c13813ddf5eee60 (diff)
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-xtests/test.lua82
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 = {
true, { { "one", json.null, "three" } } },
-- Test decoding errors
- { "Decode UTF-16BE",
+ { "Decode UTF-16BE [throw error]",
json.decode, { '\0"\0"' },
false, { "JSON parser does not support UTF-16 or UTF-32" } },
- { "Decode UTF-16LE",
+ { "Decode UTF-16LE [throw error]",
json.decode, { '"\0"\0' },
false, { "JSON parser does not support UTF-16 or UTF-32" } },
- { "Decode UTF-32BE",
+ { "Decode UTF-32BE [throw error]",
json.decode, { '\0\0\0"' },
false, { "JSON parser does not support UTF-16 or UTF-32" } },
- { "Decode UTF-32LE",
+ { "Decode UTF-32LE [throw error]",
json.decode, { '"\0\0\0' },
false, { "JSON parser does not support UTF-16 or UTF-32" } },
- { "Decode partial JSON",
+ { "Decode partial JSON [throw error]",
json.decode, { '{ "unexpected eof": ' },
false, { "Expected value but found T_END at character 21" } },
- { "Decode with extra comma",
+ { "Decode with extra comma [throw error]",
json.decode, { '{ "extra data": true }, false' },
false, { "Expected the end but found T_COMMA at character 23" } },
- { "Decode invalid escape code",
+ { "Decode invalid escape code [throw error]",
json.decode, { [[ { "bad escape \q code" } ]] },
false, { "Expected object key string but found invalid escape code at character 16" } },
- { "Decode invalid unicode escape",
+ { "Decode invalid unicode escape [throw error]",
json.decode, { [[ { "bad unicode \u0f6 escape" } ]] },
false, { "Expected object key string but found invalid unicode escape code at character 17" } },
- { "Decode invalid keyword",
+ { "Decode invalid keyword [throw error]",
json.decode, { ' [ "bad barewood", test ] ' },
false, { "Expected value but found invalid token at character 20" } },
- { "Decode invalid number #1",
+ { "Decode invalid number #1 [throw error]",
json.decode, { '[ -+12 ]' },
false, { "Expected value but found invalid number at character 3" } },
- { "Decode invalid number #2",
+ { "Decode invalid number #2 [throw error]",
json.decode, { '-v' },
false, { "Expected value but found invalid number at character 1" } },
- { "Decode invalid number exponent",
+ { "Decode invalid number exponent [throw error]",
json.decode, { '[ 0.4eg10 ]' },
false, { "Expected comma or array end but found invalid token at character 6" } },
@@ -154,13 +154,13 @@ local cjson_tests = {
{ "Decode array at nested limit",
json.decode, { '[[[[[ "nested" ]]]]]' },
true, { {{{{{ "nested" }}}}} } },
- { "Decode array over nested limit",
+ { "Decode array over nested limit [throw error]",
json.decode, { '[[[[[[ "nested" ]]]]]]' },
false, { "Too many nested data structures" } },
{ "Decode object at nested limit",
json.decode, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' },
true, { {a={b={c={d={e="nested"}}}}} } },
- { "Decode object over nested limit",
+ { "Decode object over nested limit [throw error]",
json.decode, { '{"a":{"b":{"c":{"d":{"e":{"f":"nested"}}}}}}' },
false, { "Too many nested data structures" } },
{ "Set decode_max_depth(1000)",
@@ -171,16 +171,16 @@ local cjson_tests = {
json.encode_max_depth, { 5 }, true, { 5 } },
{ "Encode nested table as array at nested limit",
json.encode, { {{{{{"nested"}}}}} }, true, { '[[[[["nested"]]]]]' } },
- { "Encode nested table as array after nested limit",
+ { "Encode nested table as array after nested limit [throw error]",
json.encode, { { {{{{{"nested"}}}}} } },
false, { "Cannot serialise, excessive nesting (6)" } },
{ "Encode nested table as object at nested limit",
json.encode, { {a={b={c={d={e="nested"}}}}} },
true, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' } },
- { "Encode nested table as object over nested limit",
+ { "Encode nested table as object over nested limit [throw error]",
json.encode, { {a={b={c={d={e={f="nested"}}}}}} },
false, { "Cannot serialise, excessive nesting (6)" } },
- { "Encode table with cycle",
+ { "Encode table with cycle [throw error]",
json.encode, { testdata.table_cycle },
false, { "Cannot serialise, excessive nesting (6)" } },
{ "Set encode_max_depth(1000)",
@@ -199,7 +199,7 @@ local cjson_tests = {
json.encode, { 10 }, true, { '10' } },
{ "Encode string",
json.encode, { "hello" }, true, { '"hello"' } },
- { "Encode Lua function",
+ { "Encode Lua function [throw error]",
json.encode, { function () end },
false, { "Cannot serialise function: type not supported" } },
@@ -215,24 +215,24 @@ local cjson_tests = {
true, { { Inf, Inf, -Inf } } },
{ "Decode +-NaN",
json.decode, { '[ +NaN, NaN, -NaN ]' }, true, { { NaN, NaN, NaN } } },
- { "Decode Infrared (not infinity)",
+ { "Decode Infrared (not infinity) [throw error]",
json.decode, { 'Infrared' },
false, { "Expected the end but found invalid token at character 4" } },
- { "Decode Noodle (not NaN)",
+ { "Decode Noodle (not NaN) [throw error]",
json.decode, { 'Noodle' },
false, { "Expected value but found invalid token at character 1" } },
{ "Set decode_invalid_numbers(false)",
json.decode_invalid_numbers, { false }, true, { "off" } },
- { "Decode hexadecimal (throw error)",
+ { "Decode hexadecimal [throw error]",
json.decode, { '0x6' },
false, { "Expected value but found invalid number at character 1" } },
- { "Decode +-Inf (throw error)",
+ { "Decode +-Inf [throw error]",
json.decode, { '[ +Inf, Inf, -Inf ]' },
false, { "Expected value but found invalid token at character 3" } },
- { "Decode +-Infinity (throw error)",
+ { "Decode +-Infinity [throw error]",
json.decode, { '[ +Infinity, Infinity, -Infinity ]' },
false, { "Expected value but found invalid token at character 3" } },
- { "Decode +-NaN (throw error)",
+ { "Decode +-NaN [throw error]",
json.decode, { '[ +NaN, NaN, -NaN ]' },
false, { "Expected value but found invalid token at character 3" } },
{ 'Set decode_invalid_numbers("on")',
@@ -241,10 +241,10 @@ local cjson_tests = {
-- Test encoding invalid numbers
{ "Set encode_invalid_numbers(false)",
json.encode_invalid_numbers, { false }, true, { "off" } },
- { "Encode NaN (invalid numbers disabled)",
+ { "Encode NaN [throw error]",
json.encode, { NaN },
false, { "Cannot serialise number: must not be NaN or Inf" } },
- { "Encode Infinity (invalid numbers disabled)",
+ { "Encode Infinity [throw error]",
json.encode, { Inf },
false, { "Cannot serialise number: must not be NaN or Inf" } },
{ "Set encode_invalid_numbers(\"null\")",
@@ -279,7 +279,7 @@ local cjson_tests = {
true, { '{"2":"numeric string key test"}' } },
{ "Set encode_sparse_array(false)",
json.encode_sparse_array, { false }, true, { "off", 2, 3 } },
- { "Encode table with incompatible key",
+ { "Encode table with incompatible key [throw error]",
json.encode, { { [false] = "wrong" } },
false, { "Cannot serialise boolean: table key must be a number or string" } },
@@ -292,19 +292,19 @@ local cjson_tests = {
json.decode, { [["\uF800"]] }, true, { "\239\160\128" } },
{ "Decode all UTF-16 escapes (including surrogate combinations)",
json.decode, { testdata.utf16_escaped }, true, { testdata.utf8_raw } },
- { "Decode swapped surrogate pair",
+ { "Decode swapped surrogate pair [throw error]",
json.decode, { [["\uDC00\uD800"]] },
false, { "Expected value but found invalid unicode escape code at character 2" } },
- { "Decode duplicate high surrogate",
+ { "Decode duplicate high surrogate [throw error]",
json.decode, { [["\uDB00\uDB00"]] },
false, { "Expected value but found invalid unicode escape code at character 2" } },
- { "Decode duplicate low surrogate",
+ { "Decode duplicate low surrogate [throw error]",
json.decode, { [["\uDB00\uDB00"]] },
false, { "Expected value but found invalid unicode escape code at character 2" } },
- { "Decode missing low surrogate",
+ { "Decode missing low surrogate [throw error]",
json.decode, { [["\uDB00"]] },
false, { "Expected value but found invalid unicode escape code at character 2" } },
- { "Decode invalid low surrogate",
+ { "Decode invalid low surrogate [throw error]",
json.decode, { [["\uDB00\uD"]] },
false, { "Expected value but found invalid unicode escape code at character 2" } },
@@ -339,28 +339,28 @@ local cjson_tests = {
-- Test config API errors
-- Function is listed as '?' due to pcall
- { "Set encode_number_precision(0)",
+ { "Set encode_number_precision(0) [throw error]",
json.encode_number_precision, { 0 },
false, { "bad argument #1 to '?' (expected integer between 1 and 14)" } },
- { "Set encode_number_precision(\"five\")",
+ { "Set encode_number_precision(\"five\") [throw error]",
json.encode_number_precision, { "five" },
false, { "bad argument #1 to '?' (number expected, got string)" } },
- { "Set encode_keep_buffer(nil, true)",
+ { "Set encode_keep_buffer(nil, true) [throw error]",
json.encode_keep_buffer, { nil, true },
false, { "bad argument #2 to '?' (found too many arguments)" } },
- { "Set encode_max_depth(\"wrong\")",
+ { "Set encode_max_depth(\"wrong\") [throw error]",
json.encode_max_depth, { "wrong" },
false, { "bad argument #1 to '?' (number expected, got string)" } },
- { "Set decode_max_depth(0)",
+ { "Set decode_max_depth(0) [throw error]",
json.decode_max_depth, { "0" },
false, { "bad argument #1 to '?' (expected integer between 1 and 2147483647)" } },
- { "Set encode_invalid_numbers(-2)",
+ { "Set encode_invalid_numbers(-2) [throw error]",
json.encode_invalid_numbers, { -2 },
false, { "bad argument #1 to '?' (invalid option '-2')" } },
- { "Set decode_invalid_numbers(true, false)",
+ { "Set decode_invalid_numbers(true, false) [throw error]",
json.decode_invalid_numbers, { true, false },
false, { "bad argument #2 to '?' (found too many arguments)" } },
- { "Set encode_sparse_array(\"not quite on\")",
+ { "Set encode_sparse_array(\"not quite on\") [throw error]",
json.encode_sparse_array, { "not quite on" },
false, { "bad argument #1 to '?' (invalid option 'not quite on')" } },
@@ -371,7 +371,7 @@ local cjson_tests = {
true, { "off", 2, 10 } },
}
-print(string.format("Testing Lua CJSON version %s\n", json._VERSION))
+print(string.format("==> Testing Lua CJSON version %s\n", json._VERSION))
util.run_test_group(cjson_tests)