File: testutil.lua

package info (click to toggle)
lua-json 1.3.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 688 kB
  • sloc: makefile: 71; php: 3
file content (27 lines) | stat: -rw-r--r-- 542 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local pcall, error = pcall, error

local lunit = require("lunit")
local assert_error = lunit.assert_error

-- Allow module to alter decoder
local function setDecoder(d)
	_G.decode = d
end

local function buildPatchedDecoder(f, newDecoder)
	return function()
		setDecoder(newDecoder)
		f()
	end
end
local function buildFailedPatchedDecoder(f, newDecoder)
	return function()
		setDecoder(newDecoder)
		assert_error(f)
	end
end

return {
    buildPatchedDecoder = buildPatchedDecoder,
    buildFailedPatchedDecoder = buildFailedPatchedDecoder
}