tests: updates to Lua 5.2/5.3 requirements
[luajson.git] / tests / lunit-encoderfunc.lua
blob9606c657818d5ab774a09aed59a759ec8d44ab5d
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 if not module then
9 _ENV = lunit.module("lunit-encoderfunc", 'seeall')
10 else
11 module("lunit-encoderfunc", lunit.testcase, package.seeall)
12 end
14 local function build_call(name, parameters)
15 return json.util.buildCall(name, unpack(parameters, parameters.n))
16 end
18 function test_param_counts()
19 local encoder = json.encode.getEncoder()
20 assert(encoder(build_call('noparam', {})))
21 assert(encoder(build_call('oneparam', {1})))
22 assert(encoder(build_call('multiparam', {1,2})))
23 end
25 function test_output()
26 local encoder = json.encode.getEncoder()
27 assert_equal('b64("hello")', encoder(build_call('b64', {'hello'})))
28 assert_equal('add(1,2)', encoder(build_call('add', {1,2})))
29 assert_equal('dood([b64("hello"),add(1,2)])',
30 encoder(build_call('dood', { {
31 build_call('b64', {'hello'}),
32 build_call('add', {1,2})
33 } })))
34 end