tests: enhances coverage for NaN handling
[luajson.git] / tests / lunit-encoderfunc.lua
blobf265d766ccd9f80186acfd2515b201f7dc36161e
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
9 if not module then
10 _ENV = lunit.module("lunit-encoderfunc", 'seeall')
11 else
12 module("lunit-encoderfunc", lunit.testcase, package.seeall)
13 end
15 local function build_call(name, parameters)
16 return json.util.buildCall(name, unpack(parameters, parameters.n))
17 end
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})))
24 end
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})
34 } })))
35 end