1describe('decoder', function()
2
3	-- Decode simple function
4	local bytecode = require('bpf.ljbytecode')
5	local f = function (x) return x + 1 end
6
7	it('should decode functions', function()
8		-- Make sure it calls LJ decoder
9		local bc = bytecode.decoder(f)
10		assert.truthy(bc)
11		-- Decode bytecode bytecode to instructions
12		local jutil = require("jit.util")
13		spy.on(jutil, 'funcbc')
14		local pc, op = bc()
15		-- Check bytecode for sanity (starts with ADDVN(x, 1))
16		assert.equal(pc, 1)
17		assert.equal(op, 'ADDVN')
18		for pc, op in bc do
19			assert.truthy(pc and op)
20		end
21		assert.spy(jutil.funcbc).was.called()
22	end)
23	it('should fail on bad input', function()
24		assert.has_error(function() bytecode.decoder(nil)() end)
25		assert.has_error(function() bytecode.decoder(5)() end)
26		assert.has_error(function() bytecode.decoder('test')() end)
27	end)
28	it('should dump bytecode', function()
29		bytecode.dump(f)
30	end)
31end)
32