1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
local lunit = require("lunit")
local json = require("json")
if not module then
_ENV = lunit.module("lunit-depth", 'seeall')
else
module("lunit-depth", lunit.testcase, package.seeall)
end
local SAFE_DEPTH = 23
local SAFE_CALL_DEPTH = 31
function test_object_current_max_depth()
local root = {}
for i = 1, SAFE_DEPTH do
root = { x = root }
end
local encoded = json.encode(root)
json.decode(encoded)
end
function test_array_current_max_depth()
local root = {}
for i = 1, SAFE_DEPTH do
root = { root }
end
local encoded = json.encode(root)
json.decode(encoded)
end
function test_function_current_max_depth()
local root = json.util.buildCall("deep")
for i = 1, SAFE_CALL_DEPTH do
root = json.util.buildCall("deep", root)
end
local encoded = json.encode(root)
json.decode(encoded, { calls = { allowUndefined = true }})
end
if os.getenv("TEST_UNSAFE") then
local UNSAFE_DEPTH = 194
local UNSAFE_CALL_DEPTH = UNSAFE_DEPTH
function test_object_unsafe_max_depth()
local root = {}
for i = 1, UNSAFE_DEPTH do
root = { x = root }
end
local encoded = json.encode(root)
json.decode(encoded)
end
function test_array_unsafe_max_depth()
local root = {}
for i = 1, UNSAFE_DEPTH do
root = { root }
end
local encoded = json.encode(root)
json.decode(encoded)
end
function test_function_unsafe_max_depth()
local root = json.util.buildCall("deep")
for i = 1, UNSAFE_CALL_DEPTH do
root = json.util.buildCall("deep", root)
end
local encoded = json.encode(root)
json.decode(encoded, { calls = { allowUndefined = true }})
end
end
|