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