summaryrefslogtreecommitdiff
path: root/tests/load.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-03-02 21:15:42 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-03 14:39:45 +0100
commit0ba3c5d516b1a0b67cff6d5f4b4583284086dd4b (patch)
tree72db338fe02e0e4b84238a54e422bbc21b40a5d0 /tests/load.js
parent319c40c4439a9eda7bd4a68769057cb12b04755a (diff)
downloadfengari-0ba3c5d516b1a0b67cff6d5f4b4583284086dd4b.tar.gz
fengari-0ba3c5d516b1a0b67cff6d5f4b4583284086dd4b.tar.bz2
fengari-0ba3c5d516b1a0b67cff6d5f4b4583284086dd4b.zip
load, luaL_loadbuffer(x), luaL_loadstring, lua_replace, lua_isnone, lua_isnoneornil, lua_setupvalue
Diffstat (limited to 'tests/load.js')
-rw-r--r--tests/load.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/load.js b/tests/load.js
new file mode 100644
index 0000000..0f524f3
--- /dev/null
+++ b/tests/load.js
@@ -0,0 +1,82 @@
+"use strict";
+
+const test = require('tape');
+const beautify = require('js-beautify').js_beautify;
+
+const tests = require("./tests.js");
+const getState = tests.getState;
+const toByteCode = tests.toByteCode;
+
+const VM = require("../src/lvm.js");
+const ldo = require("../src/ldo.js");
+const lapi = require("../src/lapi.js");
+const lauxlib = require("../src/lauxlib.js");
+const lua = require('../src/lua.js');
+const linit = require('../src/linit.js');
+const CT = lua.constant_types;
+
+
+test('luaL_loadstring', function (t) {
+ let luaCode = `
+ local a = "hello world"
+ return a
+ `, L;
+
+ t.plan(3);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lauxlib.luaL_loadstring(L, luaCode);
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -1),
+ "hello world",
+ "Correct element(s) on the stack"
+ );
+
+});
+
+
+test('load', function (t) {
+ let luaCode = `
+ local f = load("return 'js running lua running lua'")
+ return f()
+ `, L;
+
+ t.plan(3);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lauxlib.luaL_loadstring(L, luaCode);
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -1),
+ "js running lua running lua",
+ "Correct element(s) on the stack"
+ );
+
+}); \ No newline at end of file