1 local json
= require("json")
2 local lunit
= require("lunit")
3 local math
= require("math")
4 local testutil
= require("testutil")
5 local unpack
= require("table").unpack
or unpack
7 local setmetatable
= setmetatable
10 _ENV
= lunit
.module("lunit-encoderfunc", 'seeall')
12 module("lunit-encoderfunc", lunit
.testcase
, package
.seeall
)
15 local function build_call(name
, parameters
)
16 return json
.util
.buildCall(name
, unpack(parameters
, parameters
.n
))
19 function test_param_counts()
20 local encoder
= json
.encode
.getEncoder()
21 assert(encoder(build_call('noparam', {})))
22 assert(encoder(build_call('oneparam', {1})))
23 assert(encoder(build_call('multiparam', {1,2})))
26 function test_output()
27 local encoder
= json
.encode
.getEncoder()
28 assert_equal('b64("hello")', encoder(build_call('b64', {'hello'})))
29 assert_equal('add(1,2)', encoder(build_call('add', {1,2})))
30 assert_equal('dood([b64("hello"),add(1,2)])',
31 encoder(build_call('dood', { {
32 build_call('b64', {'hello'}),
33 build_call('add', {1,2})