summaryrefslogtreecommitdiff
path: root/tests
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
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')
-rw-r--r--tests/C/Makefile7
-rw-r--r--tests/C/lua_pushboolean.c21
-rw-r--r--tests/C/lua_pushinteger.c21
-rw-r--r--tests/C/lua_pushnumber.c2
-rw-r--r--tests/C/lua_pushstring.c21
-rw-r--r--tests/lapi.js107
-rw-r--r--tests/tests.js2
7 files changed, 176 insertions, 5 deletions
diff --git a/tests/C/Makefile b/tests/C/Makefile
index 28ff1c2..bc153a5 100644
--- a/tests/C/Makefile
+++ b/tests/C/Makefile
@@ -4,5 +4,8 @@ CFLAGS= -g -Wall -Wextra
LIBS= -lm -llua
all:
- $(CC) $(CFLAGS) $(LIBS) lua_pushnil.c -o lua_pushnil.out
- $(CC) $(CFLAGS) $(LIBS) lua_pushnumber.c -o lua_pushnumber.out \ No newline at end of file
+ $(CC) $(CFLAGS) $(LIBS) lua_pushnil.c -o lua_pushnil.out
+ $(CC) $(CFLAGS) $(LIBS) lua_pushnumber.c -o lua_pushnumber.out
+ $(CC) $(CFLAGS) $(LIBS) lua_pushinteger.c -o lua_pushinteger.out
+ $(CC) $(CFLAGS) $(LIBS) lua_pushstring.c -o lua_pushstring.out
+ $(CC) $(CFLAGS) $(LIBS) lua_pushboolean.c -o lua_pushboolean.out \ No newline at end of file
diff --git a/tests/C/lua_pushboolean.c b/tests/C/lua_pushboolean.c
new file mode 100644
index 0000000..d592691
--- /dev/null
+++ b/tests/C/lua_pushboolean.c
@@ -0,0 +1,21 @@
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(void) {
+
+ lua_State *L = luaL_newstate();
+
+ luaL_openlibs(L);
+
+ lua_pushboolean(L, 1);
+
+ printf("L->top(%d): %s\n", lua_gettop(L), luaL_typename(L, lua_gettop(L)));
+
+ lua_close(L);
+
+ return 0;
+
+} \ No newline at end of file
diff --git a/tests/C/lua_pushinteger.c b/tests/C/lua_pushinteger.c
new file mode 100644
index 0000000..0c9a49f
--- /dev/null
+++ b/tests/C/lua_pushinteger.c
@@ -0,0 +1,21 @@
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(void) {
+
+ lua_State *L = luaL_newstate();
+
+ luaL_openlibs(L);
+
+ lua_pushinteger(L, 10);
+
+ printf("L->top(%d): %s\n", lua_gettop(L), luaL_typename(L, lua_gettop(L)));
+
+ lua_close(L);
+
+ return 0;
+
+} \ No newline at end of file
diff --git a/tests/C/lua_pushnumber.c b/tests/C/lua_pushnumber.c
index eca2564..697258f 100644
--- a/tests/C/lua_pushnumber.c
+++ b/tests/C/lua_pushnumber.c
@@ -10,7 +10,7 @@ int main(void) {
luaL_openlibs(L);
- lua_pushnumber(L, 10);
+ lua_pushnumber(L, 10.5);
printf("L->top(%d): %s\n", lua_gettop(L), luaL_typename(L, lua_gettop(L)));
diff --git a/tests/C/lua_pushstring.c b/tests/C/lua_pushstring.c
new file mode 100644
index 0000000..fc675c7
--- /dev/null
+++ b/tests/C/lua_pushstring.c
@@ -0,0 +1,21 @@
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(void) {
+
+ lua_State *L = luaL_newstate();
+
+ luaL_openlibs(L);
+
+ lua_pushstring(L, "hello");
+
+ printf("L->top(%d): %s\n", lua_gettop(L), luaL_typename(L, lua_gettop(L)));
+
+ lua_close(L);
+
+ return 0;
+
+} \ No newline at end of file
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
diff --git a/tests/tests.js b/tests/tests.js
index 9994ad5..02dac80 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -21,7 +21,7 @@ const toByteCode = function (luaCode) {
bclist = fs.readFileSync(`${luaFile.name}.bc.txt`, 'utf8');
- console.log(bclist);
+ // console.log(bclist);
return {
dataView: new DataView(fs.readFileSync(`${luaFile.name}.bc`)),