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>2016-08-25 14:44:47 +0300
committerMark Pulford <mark@kyne.com.au>2016-08-25 14:55:24 +0300
commit98eb1d01e952fc60a36f47846f905b86c92a4f58 (patch)
treecef52b6567dae509e4ad6295d9dc6f5fad076332
parentdb12267686af80f0a3643897d09016c137715c8a (diff)
Make sparse array test immune to table hash order
The table hash function was changed in Lua 5.3 which swapped the JSON object output order for the sparse array test. Ignore ordering altogether by checking the JSON output type instead.
-rwxr-xr-xtests/test.lua15
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/test.lua b/tests/test.lua
index b8fce84..9690db4 100755
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -10,6 +10,17 @@ local json = require "cjson"
local json_safe = require "cjson.safe"
local util = require "cjson.util"
+local function json_encode_output_type(value)
+ local text = json.encode(value)
+ if string.match(text, "{.*}") then
+ return "object"
+ elseif string.match(text, "%[.*%]") then
+ return "array"
+ else
+ return "scalar"
+ end
+end
+
local function gen_raw_octets()
local chars = {}
for i = 0, 255 do chars[i + 1] = string.char(i) end
@@ -292,8 +303,8 @@ local cjson_tests = {
json.encode, { { [1] = "one", [4] = "sparse test" } },
true, { '["one",null,null,"sparse test"]' } },
{ "Encode sparse array as object",
- json.encode, { { [1] = "one", [5] = "sparse test" } },
- true, { '{"1":"one","5":"sparse test"}' } },
+ json_encode_output_type, { { [1] = "one", [5] = "sparse test" } },
+ true, { 'object' } },
{ "Encode table with numeric string key as object",
json.encode, { { ["2"] = "numeric string key test" } },
true, { '{"2":"numeric string key test"}' } },