From 739b5c1888b38b2580adbe52a42b86372a7d146b Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 16 Feb 2017 11:55:54 +0100 Subject: lua_pushnumber, lua_pushinteger, lua_pushstring, lua_pushboolean --- tests/lapi.js | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) (limited to 'tests/lapi.js') diff --git a/tests/lapi.js b/tests/lapi.js index 251c5a8..6c5d7a4 100644 --- a/tests/lapi.js +++ b/tests/lapi.js @@ -42,7 +42,40 @@ test('luaL_newstate, lua_pushnil, lua_gettop, luaL_typename', function (t) { test('lua_pushnumber', function (t) { let L; - t.plan(3); + t.plan(4); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lapi.lua_pushnumber(L, 10.5); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_gettop(L), + 1, + "top is correct" + ); + + t.strictEqual( + lauxlib.luaL_typename(L, lapi.lua_gettop(L)), + "number", + "Correct element(s) on the stack" + ); + + t.strictEqual( + L.stack[lapi.lua_gettop(L)].value, + 10.5, + "top is correct" + ); +}); + + +test('lua_pushinteger', function (t) { + let L; + + t.plan(4); t.doesNotThrow(function () { @@ -63,4 +96,76 @@ test('lua_pushnumber', function (t) { "number", "Correct element(s) on the stack" ); + + t.strictEqual( + L.stack[lapi.lua_gettop(L)].value, + 10, + "top is correct" + ); +}); + + +test('lua_pushstring', function (t) { + let L; + + t.plan(4); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lapi.lua_pushstring(L, "hello"); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_gettop(L), + 1, + "top is correct" + ); + + t.strictEqual( + lauxlib.luaL_typename(L, lapi.lua_gettop(L)), + "string", + "Correct element(s) on the stack" + ); + + t.strictEqual( + L.stack[lapi.lua_gettop(L)].value, + "hello", + "top is correct" + ); +}); + + +test('lua_pushboolean', function (t) { + let L; + + t.plan(4); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lapi.lua_pushboolean(L, true); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_gettop(L), + 1, + "top is correct" + ); + + t.strictEqual( + lauxlib.luaL_typename(L, lapi.lua_gettop(L)), + "boolean", + "Correct element(s) on the stack" + ); + + t.strictEqual( + L.stack[lapi.lua_gettop(L)].value, + true, + "top is correct" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf