From eb9ad22e7538a25ef565e93c842eef48dba2469e Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 22 Feb 2017 14:19:19 +0100 Subject: lua_rawlen, rawlen --- tests/lbaselib.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests') diff --git a/tests/lbaselib.js b/tests/lbaselib.js index a7b14d9..21d18aa 100644 --- a/tests/lbaselib.js +++ b/tests/lbaselib.js @@ -517,5 +517,39 @@ test('assert', function (t) { lapi.lua_tostring(L, -1).endsWith("this doesn't makes sense"), "Error is on the stack" ); +}); + + +test('rawlen', function (t) { + let luaCode = ` + return rawlen({1, 2, 3}), rawlen('hello') + `, L; + + t.plan(3); + + t.doesNotThrow(function () { + + let bc = toByteCode(luaCode).dataView; + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + lapi.lua_load(L, bc, "test-rawlen"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tonumber(L, -2), + 3, + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tonumber(L, -1), + 5, + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-70-g09d2