From fc911817a8401d0696407e91501f0ef65f05b711 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 22 Feb 2017 17:32:28 +0100 Subject: use luaL_argerror/error instead of throwing --- tests/lbaselib.js | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'tests/lbaselib.js') diff --git a/tests/lbaselib.js b/tests/lbaselib.js index d71e3ab..d2f0e0e 100644 --- a/tests/lbaselib.js +++ b/tests/lbaselib.js @@ -426,19 +426,19 @@ test('select', function (t) { }, "JS Lua program ran without error"); t.deepEqual( - lapi.lua_topointer(L, -3).map(e => e.value), + [...lapi.lua_topointer(L, -3).entries()].map(e => e[1].value), [3], "Correct element(s) on the stack" ); t.deepEqual( - lapi.lua_topointer(L, -2).map(e => e.value), + [...lapi.lua_topointer(L, -2).entries()].map(e => e[1].value).sort(), [2, 3], "Correct element(s) on the stack" ); t.deepEqual( - lapi.lua_topointer(L, -1).map(e => e.value), + [...lapi.lua_topointer(L, -1).entries()].map(e => e[1].value).sort(), [2, 3], "Correct element(s) on the stack" ); @@ -552,4 +552,45 @@ test('rawlen', function (t) { 5, "Correct element(s) on the stack" ); +}); + + +test('next', function (t) { + let luaCode = ` + local total = 0 + local t = { + 1, + two = 2, + 3, + four = 4 + } + + for k,v in next, t, nil do + total = total + v + end + + return total + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + let bc = toByteCode(luaCode).dataView; + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, bc, "test-next"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tonumber(L, -1), + 10, + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf