summaryrefslogtreecommitdiff
path: root/tests/lapi.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-16 11:55:54 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-16 11:55:54 +0100
commit739b5c1888b38b2580adbe52a42b86372a7d146b (patch)
tree0c66b7a13dd7eb61e77b143b904b3f0f4ff76a49 /tests/lapi.js
parente14d05a2c3994352c671d4d4af7194aa47967ca6 (diff)
downloadfengari-739b5c1888b38b2580adbe52a42b86372a7d146b.tar.gz
fengari-739b5c1888b38b2580adbe52a42b86372a7d146b.tar.bz2
fengari-739b5c1888b38b2580adbe52a42b86372a7d146b.zip
lua_pushnumber, lua_pushinteger, lua_pushstring, lua_pushboolean
Diffstat (limited to 'tests/lapi.js')
-rw-r--r--tests/lapi.js107
1 files changed, 106 insertions, 1 deletions
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