diff options
author | Mark Pulford <mark@kyne.com.au> | 2012-02-01 18:03:58 +0400 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2012-03-04 12:24:36 +0400 |
commit | 95cbf2012ef273b13a494a2c66cef61c334d442f (patch) | |
tree | b9ec33c975dc34a1b5d04a5817613848abc33412 /tests | |
parent | 60e14dbb2b03f2b6d7336a777e017f5787296988 (diff) |
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 @@ -- Note: The output of this script is easier to read with "less -S" local json = require "cjson" +local json_safe = require "cjson.safe" local util = require "cjson.util" local function gen_raw_octets() @@ -386,6 +387,19 @@ local cjson_tests = { { "Check encode_sparse_array()", function (...) return json.encode_sparse_array(...) end, { }, true, { false, 2, 10 } }, + + { "Encode (safe) simple value", + json_safe.encode, { true }, + true, { "true" } }, + { "Encode (safe) argument validation [throw error]", + json_safe.encode, { "arg1", "arg2" }, + false, { "bad argument #1 to '?' (expected 1 argument)" } }, + { "Decode (safe) error generation", + json_safe.decode, { "Oops" }, + true, { nil, "Expected value but found invalid token at character 1" } }, + { "Decode (safe) error generation after new()", + function(...) return json_safe.new().decode(...) end, { "Oops" }, + true, { nil, "Expected value but found invalid token at character 1" } }, } print(("==> Testing Lua CJSON version %s\n"):format(json._VERSION)) |