aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-03 13:51:20 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-03 15:07:21 +0200
commit278fd3edb6ead6cd65c2293f823887d19e4fbc8e (patch)
tree3ad7b42a93bd51d856e0ccef43395fa1b64fe890 /tests
parentd231ed14d0816eb26856e948a9ab72f64d46c1eb (diff)
downloadfengari-278fd3edb6ead6cd65c2293f823887d19e4fbc8e.tar.gz
fengari-278fd3edb6ead6cd65c2293f823887d19e4fbc8e.tar.bz2
fengari-278fd3edb6ead6cd65c2293f823887d19e4fbc8e.zip
require
Diffstat (limited to 'tests')
-rw-r--r--tests/loadlib.js68
-rw-r--r--tests/module-hello.lua3
2 files changed, 71 insertions, 0 deletions
diff --git a/tests/loadlib.js b/tests/loadlib.js
new file mode 100644
index 0000000..933991c
--- /dev/null
+++ b/tests/loadlib.js
@@ -0,0 +1,68 @@
+"use strict";
+
+const test = require('tape');
+
+const lauxlib = require("../src/lauxlib.js");
+const lua = require('../src/lua.js');
+
+test('require an existing module', function (t) {
+ let luaCode = `
+ return require('os')
+ `, L;
+
+ t.plan(3);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ lauxlib.luaL_openlibs(L);
+
+ lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lua.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.ok(
+ lua.lua_istable(L, -1),
+ "Correct element(s) on the stack"
+ );
+
+});
+
+
+test('require a file', function (t) {
+ let luaCode = `
+ return require('tests/module-hello')()
+ `, L;
+
+ t.plan(3);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ lauxlib.luaL_openlibs(L);
+
+ lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lua.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.strictEqual(
+ lua.lua_tojsstring(L, -1),
+ "hello from module",
+ "Correct element(s) on the stack"
+ );
+
+});
diff --git a/tests/module-hello.lua b/tests/module-hello.lua
new file mode 100644
index 0000000..4de5890
--- /dev/null
+++ b/tests/module-hello.lua
@@ -0,0 +1,3 @@
+return function()
+ return 'hello from module'
+end