summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-01 11:51:00 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-01 11:51:00 +0100
commit444182dbbb18f44cf7cafc378f092c28006be365 (patch)
treea7d539ec3698c113c6cb68697bd3ec6f39b499e0 /tests
parentae8b95ee9c3871f506b20c74367fdc9e8cb098e2 (diff)
downloadfengari-444182dbbb18f44cf7cafc378f092c28006be365.tar.gz
fengari-444182dbbb18f44cf7cafc378f092c28006be365.tar.bz2
fengari-444182dbbb18f44cf7cafc378f092c28006be365.zip
Loading tests (binary/text)
Diffstat (limited to 'tests')
-rw-r--r--tests/lapi.js6
-rw-r--r--tests/lbaselib.js34
-rw-r--r--tests/lcorolib.js10
-rw-r--r--tests/ldebug.js14
-rw-r--r--tests/lexparse.js39
-rw-r--r--tests/lmathlib.js26
-rw-r--r--tests/load.js8
-rw-r--r--tests/ltablib.js16
8 files changed, 96 insertions, 57 deletions
diff --git a/tests/lapi.js b/tests/lapi.js
index 6761425..c422ada 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -329,7 +329,7 @@ test('lua_pcall that breaks', function (t) {
t.doesNotThrow(function () {
let fn = function(L) {
- return undefined_value;
+ return "undefined_value";
};
L = lauxlib.luaL_newstate();
@@ -382,7 +382,7 @@ test('lua_load and lua_call it', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_load(L, bc, "test-lua_load")
+ lapi.lua_load(L, null, bc, "test-lua_load", "binary");
lapi.lua_call(L, 0, 1);
@@ -409,7 +409,7 @@ test('lua script reads js upvalues', function (t) {
L = lauxlib.luaL_newstate();
- lapi.lua_load(L, bc, "test-lua_load")
+ lapi.lua_load(L, null, bc, "test-lua_load", "binary");
lapi.lua_pushstring(L, "hello");
lapi.lua_setglobal(L, "js");
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index 72a2f15..be741dc 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -31,7 +31,7 @@ test('print', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-print");
+ lapi.lua_load(L, null, bc, "test-print", "binary");
lapi.lua_call(L, 0, -1);
@@ -65,7 +65,7 @@ test('setmetatable, getmetatable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-setmetatable-getmetatable");
+ lapi.lua_load(L, null, bc, "test-setmetatable-getmetatable", "binary");
lapi.lua_call(L, 0, -1);
@@ -110,7 +110,7 @@ test('rawequal', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-rawequal");
+ lapi.lua_load(L, null, bc, "test-rawequal", "binary");
lapi.lua_call(L, 0, -1);
@@ -156,7 +156,7 @@ test('rawset, rawget', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-rawequal");
+ lapi.lua_load(L, null, bc, "test-rawequal", "binary");
lapi.lua_call(L, 0, -1);
@@ -203,7 +203,7 @@ test('type', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-type");
+ lapi.lua_load(L, null, bc, "test-type", "binary");
lapi.lua_call(L, 0, -1);
@@ -256,7 +256,7 @@ test('error', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-error");
+ lapi.lua_load(L, null, bc, "test-error", "binary");
lapi.lua_call(L, 0, -1);
@@ -279,7 +279,7 @@ test('error, protected', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-error");
+ lapi.lua_load(L, null, bc, "test-error", "binary");
lapi.lua_pcall(L, 0, -1, 0);
@@ -311,7 +311,7 @@ test('pcall', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-pcall");
+ lapi.lua_load(L, null, bc, "test-pcall", "binary");
lapi.lua_call(L, 0, -1);
@@ -347,7 +347,7 @@ test('xpcall', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-pcall");
+ lapi.lua_load(L, null, bc, "test-pcall", "binary");
lapi.lua_call(L, 0, -1);
@@ -389,7 +389,7 @@ test('ipairs', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-ipairs");
+ lapi.lua_load(L, null, bc, "test-ipairs", "binary");
lapi.lua_call(L, 0, -1);
@@ -418,7 +418,7 @@ test('select', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-select");
+ lapi.lua_load(L, null, bc, "test-select", "binary");
lapi.lua_call(L, 0, -1);
@@ -459,7 +459,7 @@ test('tonumber', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-tonumber");
+ lapi.lua_load(L, null, bc, "test-tonumber", "binary");
lapi.lua_call(L, 0, -1);
@@ -506,7 +506,7 @@ test('assert', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-assert");
+ lapi.lua_load(L, null, bc, "test-assert", "binary");
lapi.lua_pcall(L, 0, -1, 0);
@@ -534,7 +534,7 @@ test('rawlen', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-rawlen");
+ lapi.lua_load(L, null, bc, "test-rawlen", "binary");
lapi.lua_call(L, 0, -1);
@@ -581,7 +581,7 @@ test('next', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-next");
+ lapi.lua_load(L, null, bc, "test-next", "binary");
lapi.lua_call(L, 0, -1);
@@ -622,7 +622,7 @@ test('pairs', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-pairs");
+ lapi.lua_load(L, null, bc, "test-pairs", "binary");
lapi.lua_call(L, 0, -1);
@@ -672,7 +672,7 @@ test('pairs with __pairs', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-pairs");
+ lapi.lua_load(L, null, bc, "test-pairs", "binary");
lapi.lua_call(L, 0, -1);
diff --git a/tests/lcorolib.js b/tests/lcorolib.js
index 022cda6..9c1d9b1 100644
--- a/tests/lcorolib.js
+++ b/tests/lcorolib.js
@@ -40,7 +40,7 @@ test('coroutine.create, coroutine.yield, coroutine.resume', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-coroutine");
+ lapi.lua_load(L, null, bc, "test-coroutine", "binary");
lapi.lua_call(L, 0, -1);
@@ -83,7 +83,7 @@ test('coroutine.status', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-coroutine.status");
+ lapi.lua_load(L, null, bc, "test-coroutine.status", "binary");
lapi.lua_call(L, 0, -1);
@@ -124,7 +124,7 @@ test('coroutine.isyieldable', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-coroutine.isyieldable");
+ lapi.lua_load(L, null, bc, "test-coroutine.isyieldable", "binary");
lapi.lua_call(L, 0, -1);
@@ -165,7 +165,7 @@ test('coroutine.running', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-coroutine.running");
+ lapi.lua_load(L, null, bc, "test-coroutine.running", "binary");
lapi.lua_call(L, 0, -1);
@@ -206,7 +206,7 @@ test('coroutine.wrap', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-coroutine.wrap");
+ lapi.lua_load(L, null, bc, "test-coroutine.wrap", "binary");
lapi.lua_call(L, 0, -1);
diff --git a/tests/ldebug.js b/tests/ldebug.js
index 45194e9..472c66b 100644
--- a/tests/ldebug.js
+++ b/tests/ldebug.js
@@ -30,7 +30,7 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-typeerror");
+ lapi.lua_load(L, null, bc, "test-typeerror", "binary");
lapi.lua_pcall(L, 0, -1, 0);
@@ -60,7 +60,7 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-typeerror");
+ lapi.lua_load(L, null, bc, "test-typeerror", "binary");
lapi.lua_pcall(L, 0, -1, 0);
@@ -89,7 +89,7 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-typeerror");
+ lapi.lua_load(L, null, bc, "test-typeerror", "binary");
lapi.lua_pcall(L, 0, -1, 0);
@@ -118,7 +118,7 @@ test('luaG_typeerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-typeerror");
+ lapi.lua_load(L, null, bc, "test-typeerror", "binary");
lapi.lua_pcall(L, 0, -1, 0);
@@ -146,7 +146,7 @@ test('luaG_concaterror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-typeerror");
+ lapi.lua_load(L, null, bc, "test-typeerror", "binary");
lapi.lua_pcall(L, 0, -1, 0);
@@ -174,7 +174,7 @@ test('luaG_opinterror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-typeerror");
+ lapi.lua_load(L, null, bc, "test-typeerror", "binary");
lapi.lua_pcall(L, 0, -1, 0);
@@ -202,7 +202,7 @@ test('luaG_tointerror', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-typeerror");
+ lapi.lua_load(L, null, bc, "test-typeerror", "binary");
lapi.lua_pcall(L, 0, -1, 0);
diff --git a/tests/lexparse.js b/tests/lexparse.js
new file mode 100644
index 0000000..8320588
--- /dev/null
+++ b/tests/lexparse.js
@@ -0,0 +1,39 @@
+"use strict";
+
+const test = require('tape');
+const beautify = require('js-beautify').js_beautify;
+
+const tests = require("./tests.js");
+const toByteCode = tests.toByteCode;
+
+const lapi = require("../src/lapi.js");
+const lauxlib = require("../src/lauxlib.js");
+const linit = require('../src/linit.js');
+
+
+test('Hello World', function (t) {
+ let luaCode = `
+ return "hello world"
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, null, luaCode, "test-load", "text");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -1),
+ "hello world",
+ "Correct element(s) on the stack"
+ );
+
+}); \ No newline at end of file
diff --git a/tests/lmathlib.js b/tests/lmathlib.js
index 48ae1a2..ae0c40b 100644
--- a/tests/lmathlib.js
+++ b/tests/lmathlib.js
@@ -33,7 +33,7 @@ test('math.abs, math.sin, math.cos, math.tan, math.asin, math.acos, math.atan',
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -98,7 +98,7 @@ test('math.ceil, math.floor', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -134,7 +134,7 @@ test('math.deg, math.rad', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -170,7 +170,7 @@ test('math.log', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -212,7 +212,7 @@ test('math.exp', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -242,7 +242,7 @@ test('math.min, math.max', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -278,7 +278,7 @@ test('math.random', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -312,7 +312,7 @@ test('math.sqrt', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -342,7 +342,7 @@ test('math.tointeger', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -372,7 +372,7 @@ test('math.type', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -414,7 +414,7 @@ test('math.ult', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -444,7 +444,7 @@ test('math.fmod', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
@@ -474,7 +474,7 @@ test('math.modf', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-math");
+ lapi.lua_load(L, null, bc, "test-math", "binary");
lapi.lua_call(L, 0, -1);
diff --git a/tests/load.js b/tests/load.js
index 4df3f6a..a71de6b 100644
--- a/tests/load.js
+++ b/tests/load.js
@@ -25,7 +25,7 @@ test('lua_load, binary mode', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, bc, "test-math", "binary");
+ lapi.lua_load(L, null, bc, "test-load", "binary");
lapi.lua_call(L, 0, -1);
@@ -47,17 +47,17 @@ test('lua_load, text mode', function (t) {
t.plan(2);
- // t.doesNotThrow(function () {
+ t.doesNotThrow(function () {
L = lauxlib.luaL_newstate();
linit.luaL_openlibs(L);
- lapi.lua_load(L, null, luaCode, "test-math", "text");
+ lapi.lua_load(L, null, luaCode, "test-load", "text");
lapi.lua_call(L, 0, -1);
- // }, "JS Lua program ran without error");
+ }, "JS Lua program ran without error");
t.strictEqual(
lapi.lua_tostring(L, -1),
diff --git a/tests/ltablib.js b/tests/ltablib.js
index 2ebf98c..c8a1e73 100644
--- a/tests/ltablib.js
+++ b/tests/ltablib.js
@@ -42,7 +42,7 @@ test('table.concat', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-table.concat");
+ lapi.lua_load(L, null, bc, "test-table.concat", "binary");
lapi.lua_call(L, 0, -1);
@@ -71,7 +71,7 @@ test('table.pack', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-table.pack");
+ lapi.lua_load(L, null, bc, "test-table.pack", "binary");
lapi.lua_call(L, 0, -1);
@@ -102,7 +102,7 @@ test('table.unpack', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-table.unpack");
+ lapi.lua_load(L, null, bc, "test-table.unpack", "binary");
lapi.lua_call(L, 0, -1);
@@ -146,7 +146,7 @@ test('table.insert', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-table.insert");
+ lapi.lua_load(L, null, bc, "test-table.insert", "binary");
lapi.lua_call(L, 0, -1);
@@ -180,7 +180,7 @@ test('table.remove', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-table.remove");
+ lapi.lua_load(L, null, bc, "test-table.remove", "binary");
lapi.lua_call(L, 0, -1);
@@ -213,7 +213,7 @@ test('table.move', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-table.move");
+ lapi.lua_load(L, null, bc, "test-table.move", "binary");
lapi.lua_call(L, 0, -1);
@@ -246,7 +246,7 @@ test('table.sort (<)', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-table.sort");
+ lapi.lua_load(L, null, bc, "test-table.sort", "binary");
lapi.lua_call(L, 0, -1);
@@ -279,7 +279,7 @@ test('table.sort with cmp function', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-table.sort");
+ lapi.lua_load(L, null, bc, "test-table.sort", "binary");
lapi.lua_call(L, 0, -1);