Comparison

tests/test_util_json.lua @ 7233:71ca252d9f69

Add tests for util.json
author Matthew Wild <mwild1@gmail.com>
date Fri, 04 Mar 2016 22:17:16 +0000
comparison
equal deleted inserted replaced
7231:c018a44b822a 7233:71ca252d9f69
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