Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpx/lua-cjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-05-06 22:18:58 +0400
committerMark Pulford <mark@kyne.com.au>2011-05-06 22:18:58 +0400
commitd75e1cb7f0418615e208f49c6209b7c144591f14 (patch)
tree318bbaa76d34472b956cc21e7128e2a322210693 /tests/common.lua
parent7befa3e83bd60f1b749d80420ee5189d095f4682 (diff)
Add test to compare objects after decode/encode
Diffstat (limited to 'tests/common.lua')
-rw-r--r--tests/common.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/common.lua b/tests/common.lua
index e935032..219de3f 100644
--- a/tests/common.lua
+++ b/tests/common.lua
@@ -76,4 +76,35 @@ function benchmark(tests, iter, rep)
return test_results
end
+function compare_values(val1, val2)
+ local type1 = type(val1)
+ local type2 = type(val2)
+ if type1 ~= type2 then
+ return false
+ end
+ if type1 ~= "table" then
+ return val1 == val2
+ end
+ local val1_keys = {}
+ -- Note all the keys in val1 need to be checked
+ for k, _ in pairs(val1) do
+ check_keys[k] = true
+ end
+ for k, v in pairs(val2) do
+ if not check_keys[k] then
+ -- Key didn't exist in val1
+ return false
+ end
+ if not compare_value(val1[k], val2[k]) then
+ return false
+ end
+ check_keys[k] = nil
+ end
+ for k, _ in pairs(check_keys) do
+ -- Not the same if any keys left to check
+ return false
+ end
+ return true
+end
+
-- vi:ai et sw=4 ts=4: