Skip to content

Commit

Permalink
add test_json testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
shuwen5 committed Jul 3, 2017
1 parent 9a2c764 commit c377bc4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/test_json.lua
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
1 change: 1 addition & 0 deletions t/test_all.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ __DATA__
"test_round",
"test_strutil",
"test_tableutil",
"test_json",
})
';
}
Expand Down

0 comments on commit c377bc4

Please sign in to comment.