summaryrefslogtreecommitdiff
path: root/tests/agentzh.t
diff options
context:
space:
mode:
authorYichun Zhang (agentzh) <agentzh@gmail.com>2014-02-18 14:33:37 -0800
committerYichun Zhang (agentzh) <agentzh@gmail.com>2014-02-18 14:33:37 -0800
commitcdb1a73615415e88ac8ef1b2eeec216fe72b9794 (patch)
tree6d87656c1852ab07dbf348d4dc340a08775eab17 /tests/agentzh.t
parent5fd54895cebd6bdf1e53718ed0691014ce0d2794 (diff)
downloadlua-cjson-cdb1a73615415e88ac8ef1b2eeec216fe72b9794.tar.gz
lua-cjson-cdb1a73615415e88ac8ef1b2eeec216fe72b9794.tar.bz2
lua-cjson-cdb1a73615415e88ac8ef1b2eeec216fe72b9794.zip
feature: applied Jiale Zhi's patch to add the new config function encode_empty_table_as_object so that we can encode empty Lua tables into empty JSON arrays.2.1.0.1
Diffstat (limited to '')
-rw-r--r--tests/agentzh.t41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/agentzh.t b/tests/agentzh.t
new file mode 100644
index 0000000..aeebd67
--- /dev/null
+++ b/tests/agentzh.t
@@ -0,0 +1,41 @@
1use TestLua;
2
3plan tests => 2 * blocks();
4
5run_tests();
6
7__DATA__
8
9=== TEST 1: empty tables as objects
10--- lua
11local cjson = require "cjson"
12print(cjson.encode({}))
13print(cjson.encode({dogs = {}}))
14--- out
15{}
16{"dogs":{}}
17
18
19
20=== TEST 2: empty tables as arrays
21--- lua
22local cjson = require "cjson"
23cjson.encode_empty_table_as_object(false)
24print(cjson.encode({}))
25print(cjson.encode({dogs = {}}))
26--- out
27[]
28{"dogs":[]}
29
30
31
32=== TEST 3: empty tables as objects (explicit)
33--- lua
34local cjson = require "cjson"
35cjson.encode_empty_table_as_object(true)
36print(cjson.encode({}))
37print(cjson.encode({dogs = {}}))
38--- out
39{}
40{"dogs":{}}
41