1 local json
= require("json")
2 local lunit
= require("lunit")
4 -- Test module for handling the simple decoding that behaves more like expected
6 _ENV
= lunit
.module("lunit-nothrow-decode", 'seeall')
8 module("lunit-nothrow-decode", lunit
.testcase
, package
.seeall
)
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})))
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})))