From 005223711f4e11da5c8f24d19d6e8a6b64f603a8 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 2 Mar 2017 14:05:01 +0100 Subject: [Parsing tests] TFORCALL, TFORLOOP --- tests/lexparse.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'tests/lexparse.js') diff --git a/tests/lexparse.js b/tests/lexparse.js index df7cae8..b661d6d 100644 --- a/tests/lexparse.js +++ b/tests/lexparse.js @@ -864,4 +864,53 @@ test('Long SETLIST', function (t) { [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5], "Program output is correct" ); +}); + + +test('TFORCALL, TFORLOOP', function (t) { + let luaCode = ` + local iterator = function (t, i) + i = i + 1 + local v = t[i] + if v then + return i, v + end + end + + local iprs = function(t) + return iterator, t, 0 + end + + local t = {1, 2, 3} + local r = 0 + for k,v in iprs(t) do + r = r + v + end + + return r + `, L; + + t.plan(3); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, null, luaCode, "test", "text"); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lapi.lua_call(L, 0, -1); + + }, "Lua program ran without error"); + + t.strictEqual( + lapi.lua_tonumber(L, -1), + 6, + "Program output is correct" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf