1 -- Additional path that may be required
2 package
.path
= package
.path
.. ';?/init.lua'
7 local successTests
= {}
10 for f
in lfs
.dir("test") do
11 if f
:match("^fail.*\.json") then
12 failTests
[#failTests
+ 1] = "test/" .. f
13 elseif f
:match("^pass.*\.json") then
14 successTests
[#successTests
+ 1] = "test/" .. f
18 local function getFileData(fileName
)
19 local f
= assert(io
.open(fileName
, 'rb'))
20 local data
= f
:read('*a')
25 local function TestParser(parseFunc
)
26 for _
,f
in ipairs(successTests
) do
27 local data
= getFileData(f
)
28 local succeed
= pcall(parseFunc
, data
)
29 if not succeed
then print("Failed on : " .. f
) end
32 for _
,f
in ipairs(failTests
) do
33 local data
= getFileData(f
)
34 local failed
= not pcall(parseFunc
, data
)
35 if not failed
then print("Didn't fail on : " .. f
) end
38 print("Testing lax/fast mode...")
39 TestParser(function(data
) json
.decode(data
) end)
41 print("Testing strict mode...")
42 TestParser(function(data
) json
.decode(data
, true) end)