decoder: fixes compatibility with lpeg 0.12 by closing off 0-length captures in loops
[luajson.git] / tests / lunit-depth.lua
blobc49186e551bbbbc09227e7aefc6e3851bc971def
1 local lunit = require("lunit")
2 local json = require("json")
4 module("lunit-depth", lunit.testcase, package.seeall)
6 local SAFE_DEPTH = 23
7 local SAFE_CALL_DEPTH = 31
9 function test_object_current_max_depth()
10 local root = {}
11 for i = 1, SAFE_DEPTH do
12 root = { x = root }
13 end
14 local encoded = json.encode(root)
15 json.decode(encoded)
16 end
18 function test_array_current_max_depth()
19 local root = {}
20 for i = 1, SAFE_DEPTH do
21 root = { root }
22 end
23 local encoded = json.encode(root)
24 json.decode(encoded)
25 end
27 function test_function_current_max_depth()
28 local root = json.util.buildCall("deep")
29 for i = 1, SAFE_CALL_DEPTH do
30 root = json.util.buildCall("deep", root)
31 end
32 local encoded = json.encode(root)
33 json.decode(encoded, { calls = { allowUndefined = true }})
34 end
36 if os.getenv("TEST_UNSAFE") then
37 local UNSAFE_DEPTH = 194
38 local UNSAFE_CALL_DEPTH = UNSAFE_DEPTH
39 function test_object_unsafe_max_depth()
40 local root = {}
41 for i = 1, UNSAFE_DEPTH do
42 root = { x = root }
43 end
44 local encoded = json.encode(root)
45 json.decode(encoded)
46 end
48 function test_array_unsafe_max_depth()
49 local root = {}
50 for i = 1, UNSAFE_DEPTH do
51 root = { root }
52 end
53 local encoded = json.encode(root)
54 json.decode(encoded)
55 end
57 function test_function_unsafe_max_depth()
58 local root = json.util.buildCall("deep")
59 for i = 1, UNSAFE_CALL_DEPTH do
60 root = json.util.buildCall("deep", root)
61 end
62 local encoded = json.encode(root)
63 json.decode(encoded, { calls = { allowUndefined = true }})
64 end
66 end