From 490ee0d109671b6f7e9d3d56e8122f41647fed4c Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 2 Mar 2017 09:54:45 +0100 Subject: [Parsing tests] FORPREP, FORLOOP --- tests/lexparse.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'tests/lexparse.js') diff --git a/tests/lexparse.js b/tests/lexparse.js index 7ef5fe3..7a12985 100644 --- a/tests/lexparse.js +++ b/tests/lexparse.js @@ -467,4 +467,70 @@ test('TEST (false)', function (t) { "goodbye", "Program output is correct" ); +}); + + +test('FORPREP, FORLOOP (int)', function (t) { + let luaCode = ` + local total = 0 + + for i = 0, 10 do + total = total + i + end + + return total + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, null, luaCode, "test", "text"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tointeger(L, -1), + 55, + "Program output is correct" + ); +}); + + +test('FORPREP, FORLOOP (float)', function (t) { + let luaCode = ` + local total = 0 + + for i = 0.5, 10.5 do + total = total + i + end + + return total + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, null, luaCode, "test", "text"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tonumber(L, -1), + 60.5, + "Program output is correct" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf