docs: updates README to reflect new test LPEG platform and Lua 5.3.4 release
[luajson.git] / tests / lunit-nothrow-decode.lua
blob626485de6f49c8fbdfa7414210d1496fe64aac0e
1 local json = require("json")
2 local lunit = require("lunit")
4 -- Test module for handling the simple decoding that behaves more like expected
5 if not module then
6 _ENV = lunit.module("lunit-nothrow-decode", 'seeall')
7 else
8 module("lunit-nothrow-decode", lunit.testcase, package.seeall)
9 end
11 function test_decode_nothrow_bad_data()
12 assert_nil((json.decode('x', {nothrow = true})))
13 assert_nil((json.decode('{x:x}', {nothrow = true})))
14 assert_nil((json.decode('[x:x]', {nothrow = true})))
15 assert_nil((json.decode('[1.fg]', {nothrow = true})))
16 assert_nil((json.decode('["\\xzz"]', {nothrow = true})))
17 end
19 function test_decode_nothrow_ok_data()
20 assert_not_nil((json.decode('"x"', {nothrow = true})))
21 assert_not_nil((json.decode('{x:"x"}', {nothrow = true})))
22 assert_not_nil((json.decode('["x"]', {nothrow = true})))
23 assert_not_nil((json.decode('[1.0]', {nothrow = true})))
24 assert_not_nil((json.decode('["\\u00FF"]', {nothrow = true})))
25 end