From 2e83b8d2e3ac6c30a53e7919a1808b732aeff5a4 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 2 Mar 2017 14:27:33 +0100 Subject: [Parsing tests] LEN, CONCAT --- tests/lexparse.js | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'tests') diff --git a/tests/lexparse.js b/tests/lexparse.js index b661d6d..0226e92 100644 --- a/tests/lexparse.js +++ b/tests/lexparse.js @@ -913,4 +913,82 @@ test('TFORCALL, TFORLOOP', function (t) { 6, "Program output is correct" ); +}); + + +test('LEN', function (t) { + let luaCode = ` + local t = {[10000] = "foo"} + local t2 = {1, 2, 3} + local s = "hello" + + return #t, #t2, #s + `, L; + + t.plan(5); + + 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), + 5, + "Program output is correct" + ); + + t.strictEqual( + lapi.lua_tonumber(L, -2), + 3, + "Program output is correct" + ); + + t.strictEqual( + lapi.lua_tonumber(L, -3), + 0, + "Program output is correct" + ); +}); + + +test('CONCAT', function (t) { + let luaCode = ` + return "hello " .. 2 .. " you" + `, 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( + L.stack[L.top - 1].value, + "hello 2 you", + "Program output is correct" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf