From 573a9c3b39bf1570a575ce3f077a33e752439165 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 16 Feb 2017 12:08:55 +0100 Subject: lua_pushvalue --- tests/lapi.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests/lapi.js') diff --git a/tests/lapi.js b/tests/lapi.js index 6c5d7a4..8dd2680 100644 --- a/tests/lapi.js +++ b/tests/lapi.js @@ -168,4 +168,51 @@ test('lua_pushboolean', function (t) { true, "top is correct" ); +}); + + +test('lua_pushvalue', function (t) { + let L; + + t.plan(6); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lapi.lua_pushstring(L, "hello"); + + lapi.lua_pushvalue(L, -1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_gettop(L), + 2, + "top is correct" + ); + + t.strictEqual( + lauxlib.luaL_typename(L, -1), + "string", + "Correct element(s) on the stack" + ); + + t.strictEqual( + lauxlib.luaL_typename(L, -2), + "string", + "Correct element(s) on the stack" + ); + + t.strictEqual( + L.stack[lapi.lua_gettop(L)].value, + "hello", + "top is correct" + ); + + t.strictEqual( + L.stack[lapi.lua_gettop(L) - 1].value, + "hello", + "top is correct" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf