From a40719dc74b8dbb0d6c8fc0272c0d79ad8a7a9ea Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 22 Feb 2017 09:00:12 +0100 Subject: select --- tests/lbaselib.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'tests/lbaselib.js') diff --git a/tests/lbaselib.js b/tests/lbaselib.js index 53191eb..73d13a3 100644 --- a/tests/lbaselib.js +++ b/tests/lbaselib.js @@ -289,7 +289,7 @@ test('error, protected', function (t) { t.ok( lapi.lua_tostring(L, -1).endsWith("you fucked up"), "Error is on the stack" - ) + ); }); @@ -321,7 +321,7 @@ test('pcall', function (t) { t.ok( lapi.lua_tostring(L, -1).endsWith("you fucked up"), "Error is on the stack" - ) + ); }); @@ -359,12 +359,12 @@ test('xpcall', function (t) { t.ok( lapi.lua_tostring(L, -1).startsWith("Something's wrong:"), "msgh was called and modified the error" - ) + ); t.ok( lapi.lua_tostring(L, -1).endsWith("you fucked up"), "msgh was called and modified the error" - ) + ); }); @@ -390,7 +390,7 @@ test('ipairs', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-pcall"); + lapi.lua_load(L, bc, "test-ipairs"); lapi.lua_call(L, 0, -1); @@ -400,5 +400,46 @@ test('ipairs', function (t) { lapi.lua_tointeger(L, -1), 15, "Correct element(s) on the stack" - ) + ); +}); + + +test('select', function (t) { + let luaCode = ` + return {select('#', 1, 2, 3)}, {select(2, 1, 2, 3)}, {select(-2, 1, 2, 3)} + `, 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-select"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.deepEqual( + lapi.lua_topointer(L, -3).array.map(e => e.value), + [3], + "Correct element(s) on the stack" + ); + + t.deepEqual( + lapi.lua_topointer(L, -2).array.map(e => e.value), + [2, 3], + "Correct element(s) on the stack" + ); + + t.deepEqual( + lapi.lua_topointer(L, -1).array.map(e => e.value), + [2, 3], + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf