aboutsummaryrefslogtreecommitdiff
path: root/tests/common.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/common.lua')
-rw-r--r--tests/common.lua17
1 files changed, 11 insertions, 6 deletions
diff --git a/tests/common.lua b/tests/common.lua
index b8ce01d..63d37c0 100644
--- a/tests/common.lua
+++ b/tests/common.lua
@@ -29,7 +29,7 @@ function is_array(table)
29 return max 29 return max
30end 30end
31 31
32function serialise_table(value, indent) 32function serialise_table(value, indent, depth)
33 local spacing, spacing2, indent2 33 local spacing, spacing2, indent2
34 if indent then 34 if indent then
35 spacing = "\n" .. indent 35 spacing = "\n" .. indent
@@ -38,6 +38,10 @@ function serialise_table(value, indent)
38 else 38 else
39 spacing, spacing2, indent2 = " ", " ", false 39 spacing, spacing2, indent2 = " ", " ", false
40 end 40 end
41 depth = depth + 1
42 if depth > 50 then
43 return "ERROR: Too many nested tables"
44 end
41 45
42 local max = is_array(value) 46 local max = is_array(value)
43 47
@@ -49,7 +53,7 @@ function serialise_table(value, indent)
49 if comma then 53 if comma then
50 table.insert(fragment, "," .. spacing2) 54 table.insert(fragment, "," .. spacing2)
51 end 55 end
52 table.insert(fragment, serialise_value(value[i], indent2)) 56 table.insert(fragment, serialise_value(value[i], indent2, depth))
53 comma = true 57 comma = true
54 end 58 end
55 elseif max < 0 then 59 elseif max < 0 then
@@ -59,8 +63,8 @@ function serialise_table(value, indent)
59 table.insert(fragment, "," .. spacing2) 63 table.insert(fragment, "," .. spacing2)
60 end 64 end
61 table.insert(fragment, string.format( 65 table.insert(fragment, string.format(
62 "[%s] = %s", serialise_value(k, indent2), 66 "[%s] = %s", serialise_value(k, indent2, depth),
63 serialise_value(v, indent2)) 67 serialise_value(v, indent2, depth))
64 ) 68 )
65 comma = true 69 comma = true
66 end 70 end
@@ -70,8 +74,9 @@ function serialise_table(value, indent)
70 return table.concat(fragment) 74 return table.concat(fragment)
71end 75end
72 76
73function serialise_value(value, indent) 77function serialise_value(value, indent, depth)
74 if indent == nil then indent = "" end 78 if indent == nil then indent = "" end
79 if depth == nil then depth = 0 end
75 80
76 if value == cjson.null then 81 if value == cjson.null then
77 return "cjson.null" 82 return "cjson.null"
@@ -81,7 +86,7 @@ function serialise_value(value, indent)
81 type(value) == "boolean" then 86 type(value) == "boolean" then
82 return tostring(value) 87 return tostring(value)
83 elseif type(value) == "table" then 88 elseif type(value) == "table" then
84 return serialise_table(value, indent) 89 return serialise_table(value, indent, depth)
85 else 90 else
86 return "\"<" .. type(value) .. ">\"" 91 return "\"<" .. type(value) .. ">\""
87 end 92 end