1 local json
= require("json")
2 local lunit
= require("lunit")
5 _ENV
= lunit
.module("lunit-encoding", 'seeall')
7 module("lunit-encoding", lunit
.testcase
, package
.seeall
)
10 function test_cloned_array_sibling()
12 assert_pass(function()
13 json
.encode({obj
, obj
})
17 function test_cloned_object_sibling()
19 assert_pass(function()
20 json
.encode({x
= obj
, y
= obj
})
24 function test_cloned_array_deep_sibling()
26 assert_pass(function()
33 function test_cloned_array_multilevel_sibling()
35 assert_pass(function()
42 function test_recursive_object()
45 assert_error(function()
50 function test_recursive_array()
53 assert_error(function()
58 function test_custom_encode()
59 local obj
= { x
= "y" }
61 local function preProcessor(value
, isObjectKey
)
64 assert_true(isObjectKey
)
66 assert_false(isObjectKey
)
70 local encoder
= json
.encode
.getEncoder({
71 preProcess
= preProcessor
78 function test_custom_array()
79 assert_equal("[]", json
.encode(setmetatable({}, {__is_luajson_array
= true})))
80 assert_equal("[]", json
.encode(json
.util
.InitArray({})))