Annotate

tests/test_util_json.lua @ 8105:851b50401a26

prosodyctl: Remove example showing deprecated config option
author Kim Alvefur <zash@zash.se>
date Fri, 21 Apr 2017 13:29:04 +0200
parent 7233:71ca252d9f69
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7233
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 function encode(encode, json)
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local function test(f, j, e)
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 if e then
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 assert_equal(f(j), e);
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 end
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 assert_equal(f(j), f(json.decode(f(j))));
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 end
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 test(encode, json.null, "null")
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 test(encode, {}, "{}")
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 test(encode, {a=1});
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 test(encode, {a={1,2,3}});
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 test(encode, {1}, "[1]");
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 end
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 function decode(decode)
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local empty_array = decode("[]");
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 assert_equal(type(empty_array), "table");
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 assert_equal(#empty_array, 0);
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 assert_equal(next(empty_array), nil);
71ca252d9f69 Add tests for util.json
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 end