7233
|
1
|
|
2 function encode(encode, json)
|
|
3 local function test(f, j, e)
|
|
4 if e then
|
|
5 assert_equal(f(j), e);
|
|
6 end
|
|
7 assert_equal(f(j), f(json.decode(f(j))));
|
|
8 end
|
|
9 test(encode, json.null, "null")
|
|
10 test(encode, {}, "{}")
|
|
11 test(encode, {a=1});
|
|
12 test(encode, {a={1,2,3}});
|
|
13 test(encode, {1}, "[1]");
|
|
14 end
|
|
15
|
|
16 function decode(decode)
|
|
17 local empty_array = decode("[]");
|
|
18 assert_equal(type(empty_array), "table");
|
|
19 assert_equal(#empty_array, 0);
|
|
20 assert_equal(next(empty_array), nil);
|
|
21 end
|