From 3da8070fa77b518baeba0cdea7265f7d41f497fe Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 1 Mar 2017 15:12:11 +0100 Subject: [Parsing tests] NEWTABLE --- tests/lexparse.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/lexparse.js b/tests/lexparse.js index 1a1a7b3..1132ef1 100644 --- a/tests/lexparse.js +++ b/tests/lexparse.js @@ -9,6 +9,7 @@ const toByteCode = tests.toByteCode; const lapi = require("../src/lapi.js"); const lauxlib = require("../src/lauxlib.js"); const linit = require('../src/linit.js'); +const Table = require("../src/lobject.js").Table; // Roughly the same tests as test/lvm.js to cover all opcodes @@ -108,9 +109,9 @@ test('Unary op, LOADBOOL', function (t) { return -a, not b, ~a `, L; - t.plan(1); + t.plan(2); - // t.doesNotThrow(function () { + t.doesNotThrow(function () { L = lauxlib.luaL_newstate(); @@ -120,7 +121,7 @@ test('Unary op, LOADBOOL', function (t) { lapi.lua_call(L, 0, -1); - // }, "JS Lua program ran without error"); + }, "JS Lua program ran without error"); t.deepEqual( L.stack.slice(L.top - 3, L.top).map(e => e.value), @@ -128,3 +129,30 @@ test('Unary op, LOADBOOL', function (t) { "Program output is correct" ); }); + + +test('NEWTABLE', function (t) { + let luaCode = ` + local a = {} + return a + `, L; + + t.plan(2); + + 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.ok( + L.stack[lapi.index2addr_(L, -1)] instanceof Table, + "Program output is correct" + ); +}); \ No newline at end of file -- cgit v1.2.3-70-g09d2