summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lapi.js7
-rw-r--r--tests/lbaselib.js35
-rw-r--r--tests/lcorolib.js11
-rw-r--r--tests/ldebug.js15
-rw-r--r--tests/lexparse.js40
-rw-r--r--tests/llex.js97
-rw-r--r--tests/lmathlib.js27
-rw-r--r--tests/load.js68
-rw-r--r--tests/ltablib.js17
-rw-r--r--tests/ltm.js1
-rw-r--r--tests/lvm.js3
-rw-r--r--tests/tests.js1
12 files changed, 259 insertions, 63 deletions
diff --git a/tests/lapi.js b/tests/lapi.js
index 30366d5..c422ada 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -1,4 +1,3 @@
-/*jshint esversion: 6 */
"use strict";
const test = require('tape');
@@ -330,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();
@@ -383,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);
@@ -410,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 be5cdad..be741dc 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -1,4 +1,3 @@
-/*jshint esversion: 6 */
"use strict";
const test = require('tape');
@@ -32,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);
@@ -66,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);
@@ -111,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);
@@ -157,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);
@@ -204,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);
@@ -257,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);
@@ -280,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);
@@ -312,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);
@@ -348,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);
@@ -390,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);
@@ -419,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);
@@ -460,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);
@@ -507,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);
@@ -535,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);
@@ -582,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);
@@ -623,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);
@@ -673,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 78024dd..9c1d9b1 100644
--- a/tests/lcorolib.js
+++ b/tests/lcorolib.js
@@ -1,4 +1,3 @@
-/*jshint esversion: 6 */
"use strict";
const test = require('tape');
@@ -41,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);
@@ -84,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);
@@ -125,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);
@@ -166,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);
@@ -207,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 491b8ba..472c66b 100644
--- a/tests/ldebug.js
+++ b/tests/ldebug.js
@@ -1,4 +1,3 @@
-/*jshint esversion: 6 */
"use strict";
const test = require('tape');
@@ -31,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);
@@ -61,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);
@@ -90,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);
@@ -119,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);
@@ -147,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);
@@ -175,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);
@@ -203,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..0d9c51d
--- /dev/null
+++ b/tests/lexparse.js
@@ -0,0 +1,40 @@
+"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('LOADK, RETURN', function (t) {
+ let luaCode = `
+ local a = "hello world"
+ return a
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, null, luaCode, "test", "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/llex.js b/tests/llex.js
new file mode 100644
index 0000000..8b69acc
--- /dev/null
+++ b/tests/llex.js
@@ -0,0 +1,97 @@
+"use strict";
+
+const test = require('tape');
+const beautify = require('js-beautify').js_beautify;
+
+const tests = require("./tests.js");
+
+const lapi = require("../src/lapi.js");
+const lauxlib = require("../src/lauxlib.js");
+const llex = require("../src/llex.js");
+const lua = require('../src/lua.js');
+const R = llex.RESERVED;
+
+
+test('basic lexing: TK_RETURN, TK_STRING', function (t) {
+ let luaCode = `
+ return "hello lex !"
+ `, L;
+
+ t.plan(2);
+
+ let readTokens = [];
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ let ls = new llex.LexState();
+ llex.luaX_setinput(L, ls, new llex.MBuffer(luaCode), luaCode, luaCode.charAt(0));
+
+ llex.luaX_next(ls);
+
+ while (ls.t.token !== R.TK_EOS) {
+ // console.log(llex.luaX_tokens[ls.t.token - llex.FIRST_RESERVED]);
+
+ readTokens.push(ls.t.token);
+ llex.luaX_next(ls);
+ }
+
+
+ }, "JS Lua program ran without error");
+
+ t.deepEqual(
+ readTokens,
+ [R.TK_RETURN, R.TK_STRING],
+ "Correct tokens found"
+ );
+
+});
+
+
+test('TK_LOCAL, TK_NAME, TK_INT', function (t) {
+ let luaCode = `
+ local f = testing(aBunch)
+ return "of"
+ end
+
+ return f("things") + 12
+ `, L;
+
+ t.plan(2);
+
+ let readTokens = [];
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ let ls = new llex.LexState();
+ llex.luaX_setinput(L, ls, new llex.MBuffer(luaCode), luaCode, luaCode.charAt(0));
+
+ llex.luaX_next(ls);
+
+ while (ls.t.token !== R.TK_EOS) {
+ // console.log(ls.t.token >= llex.FIRST_RESERVED ?
+ // llex.luaX_tokens[ls.t.token - llex.FIRST_RESERVED]
+ // : ls.t.token);
+
+ readTokens.push(ls.t.token);
+ llex.luaX_next(ls);
+ }
+
+
+ }, "JS Lua program ran without error");
+
+ t.deepEqual(
+ readTokens,
+ [
+ R.TK_LOCAL, R.TK_NAME, '=', R.TK_NAME, '(', R.TK_NAME, ')',
+ R.TK_RETURN, R.TK_STRING,
+ R.TK_END,
+ R.TK_RETURN, R.TK_NAME, '(', R.TK_STRING, ')', '+', R.TK_INT
+ ],
+ "Correct tokens found"
+ );
+
+}); \ No newline at end of file
diff --git a/tests/lmathlib.js b/tests/lmathlib.js
index ba6853c..ae0c40b 100644
--- a/tests/lmathlib.js
+++ b/tests/lmathlib.js
@@ -1,4 +1,3 @@
-/*jshint esversion: 6 */
"use strict";
const test = require('tape');
@@ -34,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);
@@ -99,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);
@@ -135,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);
@@ -171,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);
@@ -213,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);
@@ -243,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);
@@ -279,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);
@@ -313,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);
@@ -343,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);
@@ -373,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);
@@ -415,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);
@@ -445,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);
@@ -475,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
new file mode 100644
index 0000000..a71de6b
--- /dev/null
+++ b/tests/load.js
@@ -0,0 +1,68 @@
+"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('lua_load, binary mode', function (t) {
+ let luaCode = `
+ return "hello world"
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, null, bc, "test-load", "binary");
+
+ 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"
+ );
+
+});
+
+
+test('lua_load, text mode', 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/ltablib.js b/tests/ltablib.js
index fa15d6a..c8a1e73 100644
--- a/tests/ltablib.js
+++ b/tests/ltablib.js
@@ -1,4 +1,3 @@
-/*jshint esversion: 6 */
"use strict";
const test = require('tape');
@@ -43,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);
@@ -72,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);
@@ -103,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);
@@ -147,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);
@@ -181,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);
@@ -214,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);
@@ -247,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);
@@ -280,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);
diff --git a/tests/ltm.js b/tests/ltm.js
index a05d2b5..d749d7b 100644
--- a/tests/ltm.js
+++ b/tests/ltm.js
@@ -1,4 +1,3 @@
-/*jshint esversion: 6 */
"use strict";
const test = require('tape');
diff --git a/tests/lvm.js b/tests/lvm.js
index 4f02ed5..5b5deac 100644
--- a/tests/lvm.js
+++ b/tests/lvm.js
@@ -1,4 +1,3 @@
-/*jshint esversion: 6 */
"use strict";
const test = require('tape');
@@ -7,7 +6,7 @@ const beautify = require('js-beautify').js_beautify;
const lua_State = require("../src/lstate.js").lua_State;
const VM = require("../src/lvm.js");
const lapi = require("../src/lapi.js");
-const Table = require("../src/lobject.js").Table;;
+const Table = require("../src/lobject.js").Table;
const getState = require("./tests.js").getState;
diff --git a/tests/tests.js b/tests/tests.js
index 0963159..a47aee5 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -1,4 +1,3 @@
-/*jshint esversion: 6 */
"use strict";
const fs = require('fs');