* Applied some expression optimizations.
[luajson.git] / regressionTest.lua
blob30423536d4c87f6a4ceb95508c88a66518ef7d22
1 -- Additional path that may be required
2 package.path = package.path .. ';?/init.lua'
3 require("json")
5 require("lfs")
7 local successTests = {}
8 local failTests = {}
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
15 end
16 end
18 local function getFileData(fileName)
19 local f = assert(io.open(fileName, 'rb'))
20 local data = f:read('*a')
21 f:close()
22 return data
23 end
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
30 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
36 end
37 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)