From f52c86ef0450dd03ef9f2cd01143d6ed9ac759d1 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 24 Feb 2017 08:31:29 +0100 Subject: table.unpack --- tests/ltablib.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/ltablib.js') diff --git a/tests/ltablib.js b/tests/ltablib.js index 28b9ce0..8221fe0 100644 --- a/tests/ltablib.js +++ b/tests/ltablib.js @@ -75,4 +75,45 @@ test('table.pack', function (t) { [1, 2, 3], "Correct element(s) on the stack" ); +}); + + +test('table.unpack', function (t) { + let luaCode = ` + return table.unpack({1, 2, 3, 4, 5}, 2, 4) + `, L; + + t.plan(4); + + t.doesNotThrow(function () { + + let bc = toByteCode(luaCode).dataView; + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, bc, "test-table.unpack"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tointeger(L, -3), + 2, + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tointeger(L, -2), + 3, + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tointeger(L, -1), + 4, + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf