1 local json
= require("json")
2 local lunit
= require("lunit")
3 local testutil
= require("testutil")
4 -- DECODE NOT 'local' due to requirement for testutil to access it
5 decode
= json
.decode
.getDecoder(false)
7 module("lunit-tests", lunit
.testcase
, package
.seeall
)
10 _G
["decode"] = json
.decode
.getDecoder(false)
13 function test_array_empty()
14 local ret
= assert_table(decode("[]"))
19 function test_array_trailComma_nostrict()
20 local ret
= assert_table(decode("[true,]"))
21 assert_equal(true, ret
[1])
22 assert_nil(next(ret
, 1))
26 function test_array_innerComma()
27 assert_error(function()
28 decode("[true,,true]")
32 local strictDecoder
= json
.decode
.getDecoder(true)
34 local function buildStrictDecoder(f
)
35 return testutil
.buildPatchedDecoder(f
, strictDecoder
)
37 local function buildFailedStrictDecoder(f
)
38 return testutil
.buildFailedPatchedDecoder(f
, strictDecoder
)
40 -- SETUP CHECKS FOR SEQUENCE OF DECODERS
41 for k
, v
in pairs(_M
) do
42 if k
:match("^test_") and not k
:match("_gen$") then
43 if k
:match("_nostrict") then
44 _M
[k
.. "_strict_gen"] = buildFailedStrictDecoder(v
)
46 _M
[k
.. "_strict_gen"] = buildStrictDecoder(v
)