Merge branch '1.1.x' into 1.2.x
[luajson.git] / tests / lunit-encoderfunc.lua
blobc07c7649966d855c088fbaf3aab7c65de8f8594e
1 local json = require("json")
2 local lunit = require("lunit")
3 local math = require("math")
4 local testutil = require("testutil")
6 local setmetatable = setmetatable
8 module("lunit-encoderfunc", lunit.testcase, package.seeall)
10 local function build_call(name, parameters)
11 return json.util.buildCall(name, unpack(parameters, parameters.n))
12 end
14 function test_param_counts()
15 local encoder = json.encode.getEncoder()
16 assert(encoder(build_call('noparam', {})))
17 assert(encoder(build_call('oneparam', {1})))
18 assert(encoder(build_call('multiparam', {1,2})))
19 end
21 function test_output()
22 local encoder = json.encode.getEncoder()
23 assert_equal('b64("hello")', encoder(build_call('b64', {'hello'})))
24 assert_equal('add(1,2)', encoder(build_call('add', {1,2})))
25 assert_equal('dood([b64("hello"),add(1,2)])',
26 encoder(build_call('dood', { {
27 build_call('b64', {'hello'}),
28 build_call('add', {1,2})
29 } })))
30 end