1 local json
= require("json")
2 local lunit
= require("lunit")
4 module("lunit-encoding", lunit
.testcase
, package
.seeall
)
6 function test_cloned_array_sibling()
9 json
.encode({obj
, obj
})
13 function test_cloned_object_sibling()
15 assert_pass(function()
16 json
.encode({x
= obj
, y
= obj
})
20 function test_cloned_array_deep_sibling()
22 assert_pass(function()
29 function test_cloned_array_multilevel_sibling()
31 assert_pass(function()
38 function test_recursive_object()
41 assert_error(function()
46 function test_recursive_array()
49 assert_error(function()
54 function test_custom_encode()
55 local obj
= { x
= "y" }
57 local function preProcessor(value
, isObjectKey
)
60 assert_true(isObjectKey
)
62 assert_false(isObjectKey
)
66 local encoder
= json
.encode
.getEncoder({
67 preProcess
= preProcessor
74 function test_custom_array()
75 assert_equal("[]", json
.encode(setmetatable({}, {__is_luajson_array
= true})))
76 assert_equal("[]", json
.encode(json
.util
.InitArray({})))