-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shuwen5
committed
Jul 3, 2017
1 parent
9a2c764
commit c377bc4
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
local json = require( "acid.json" ) | ||
local cjson = require( "cjson" ) | ||
|
||
function test.enc(t) | ||
local cases = { | ||
{nil , nil, 'null'}, | ||
{{}, nil, '{}'}, | ||
{{}, {is_array=true}, '[]'}, | ||
{{1, "2"}, nil, cjson.encode({1, "2"})}, | ||
{{a=1, b='2', c={c1=1}}, nil, cjson.encode({a=1, b='2', c={c1=1}})}, | ||
} | ||
|
||
for _, case in ipairs(cases) do | ||
local j, opt, exp = unpack(case) | ||
t:eq(json.enc(j, opt), exp) | ||
end | ||
end | ||
|
||
function test.dec(t) | ||
local cases = { | ||
{nil, nil, nil}, | ||
{'{"a":1, "b":2}', nil, {a=1, b=2}}, | ||
{'{"a":1, "b":2, "c":null}', nil, {a=1, b=2}}, | ||
{'{"a":1, "b":2, "c":null}', {use_nil=false}, {a=1, b=2, c=cjson.null}}, | ||
} | ||
|
||
for _, case in ipairs(cases) do | ||
local j, opt, exp = unpack(case) | ||
t:eqdict(json.dec(j, opt), exp) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ __DATA__ | |
"test_round", | ||
"test_strutil", | ||
"test_tableutil", | ||
"test_json", | ||
}) | ||
'; | ||
} | ||
|