From 699630a97161ef970c40af073f2943c7d90043e7 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 1 Mar 2017 15:07:02 +0100 Subject: [Parsing tests] Unary op, LOADBOOL --- tests/lexparse.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/lexparse.js b/tests/lexparse.js index 2604e72..1a1a7b3 100644 --- a/tests/lexparse.js +++ b/tests/lexparse.js @@ -10,6 +10,7 @@ const lapi = require("../src/lapi.js"); const lauxlib = require("../src/lauxlib.js"); const linit = require('../src/linit.js'); +// Roughly the same tests as test/lvm.js to cover all opcodes test('LOADK, RETURN', function (t) { let luaCode = ` @@ -97,4 +98,33 @@ test('Binary op', function (t) { "Program output is correct" ); -}); \ No newline at end of file +}); + + +test('Unary op, LOADBOOL', function (t) { + let luaCode = ` + local a = 5 + local b = false + return -a, not b, ~a + `, L; + + t.plan(1); + + // t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, null, luaCode, "test", "text"); + + lapi.lua_call(L, 0, -1); + + // }, "JS Lua program ran without error"); + + t.deepEqual( + L.stack.slice(L.top - 3, L.top).map(e => e.value), + [-5, true, -6], + "Program output is correct" + ); +}); -- cgit v1.2.3-54-g00ecf