diff options
author | Mark Pulford <mark@kyne.com.au> | 2012-02-02 00:33:58 +1030 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2012-03-04 18:54:36 +1030 |
commit | 95cbf2012ef273b13a494a2c66cef61c334d442f (patch) | |
tree | b9ec33c975dc34a1b5d04a5817613848abc33412 /tests | |
parent | 60e14dbb2b03f2b6d7336a777e017f5787296988 (diff) | |
download | lua-cjson-95cbf2012ef273b13a494a2c66cef61c334d442f.tar.gz lua-cjson-95cbf2012ef273b13a494a2c66cef61c334d442f.tar.bz2 lua-cjson-95cbf2012ef273b13a494a2c66cef61c334d442f.zip |
Add cjson.safe module to suppress exceptions
Add cjson.safe module to suppress exceptions during JSON conversions.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/test.lua b/tests/test.lua index ac6419a..96b47ff 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
@@ -7,6 +7,7 @@ | |||
7 | -- Note: The output of this script is easier to read with "less -S" | 7 | -- Note: The output of this script is easier to read with "less -S" |
8 | 8 | ||
9 | local json = require "cjson" | 9 | local json = require "cjson" |
10 | local json_safe = require "cjson.safe" | ||
10 | local util = require "cjson.util" | 11 | local util = require "cjson.util" |
11 | 12 | ||
12 | local function gen_raw_octets() | 13 | local function gen_raw_octets() |
@@ -386,6 +387,19 @@ local cjson_tests = { | |||
386 | { "Check encode_sparse_array()", | 387 | { "Check encode_sparse_array()", |
387 | function (...) return json.encode_sparse_array(...) end, { }, | 388 | function (...) return json.encode_sparse_array(...) end, { }, |
388 | true, { false, 2, 10 } }, | 389 | true, { false, 2, 10 } }, |
390 | |||
391 | { "Encode (safe) simple value", | ||
392 | json_safe.encode, { true }, | ||
393 | true, { "true" } }, | ||
394 | { "Encode (safe) argument validation [throw error]", | ||
395 | json_safe.encode, { "arg1", "arg2" }, | ||
396 | false, { "bad argument #1 to '?' (expected 1 argument)" } }, | ||
397 | { "Decode (safe) error generation", | ||
398 | json_safe.decode, { "Oops" }, | ||
399 | true, { nil, "Expected value but found invalid token at character 1" } }, | ||
400 | { "Decode (safe) error generation after new()", | ||
401 | function(...) return json_safe.new().decode(...) end, { "Oops" }, | ||
402 | true, { nil, "Expected value but found invalid token at character 1" } }, | ||
389 | } | 403 | } |
390 | 404 | ||
391 | print(("==> Testing Lua CJSON version %s\n"):format(json._VERSION)) | 405 | print(("==> Testing Lua CJSON version %s\n"):format(json._VERSION)) |