diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-22 17:32:28 +0100 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-02-22 21:15:40 +0100 |
commit | fc911817a8401d0696407e91501f0ef65f05b711 (patch) | |
tree | 828ee9d2d6d02cfc7d0365ca1495f99b3158c5cd /tests/lbaselib.js | |
parent | 4b764aa6a84289f04acde43108425c392d2e4806 (diff) | |
download | fengari-fc911817a8401d0696407e91501f0ef65f05b711.tar.gz fengari-fc911817a8401d0696407e91501f0ef65f05b711.tar.bz2 fengari-fc911817a8401d0696407e91501f0ef65f05b711.zip |
use luaL_argerror/error instead of throwing
Diffstat (limited to 'tests/lbaselib.js')
-rw-r--r-- | tests/lbaselib.js | 47 |
1 files changed, 44 insertions, 3 deletions
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 |