diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-03-02 15:47:19 +0100 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-03-02 20:45:06 +0100 |
commit | 319c40c4439a9eda7bd4a68769057cb12b04755a (patch) | |
tree | 76541920c3594e9a2e2f4c3a973f1815f9358ee1 /tests | |
parent | 2e83b8d2e3ac6c30a53e7919a1808b732aeff5a4 (diff) | |
download | fengari-319c40c4439a9eda7bd4a68769057cb12b04755a.tar.gz fengari-319c40c4439a9eda7bd4a68769057cb12b04755a.tar.bz2 fengari-319c40c4439a9eda7bd4a68769057cb12b04755a.zip |
lua_load use reader function
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lexparse.js | 216 | ||||
-rw-r--r-- | tests/llex.js | 97 | ||||
-rw-r--r-- | tests/load.js | 68 |
3 files changed, 189 insertions, 192 deletions
diff --git a/tests/lexparse.js b/tests/lexparse.js index 0226e92..cd80e43 100644 --- a/tests/lexparse.js +++ b/tests/lexparse.js @@ -27,7 +27,13 @@ test('LOADK, RETURN', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -61,7 +67,13 @@ test('MOVE', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -95,7 +107,13 @@ test('Binary op', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -129,7 +147,13 @@ test('Unary op, LOADBOOL', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -161,7 +185,13 @@ test('NEWTABLE', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -197,7 +227,13 @@ test('CALL', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -237,7 +273,13 @@ test('Multiple return', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -272,7 +314,13 @@ test('TAILCALL', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -307,7 +355,13 @@ test('VARARG', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -340,7 +394,13 @@ test('LE, JMP', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -373,7 +433,13 @@ test('LT', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -406,7 +472,13 @@ test('EQ', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -440,7 +512,13 @@ test('TESTSET (and)', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -474,7 +552,13 @@ test('TESTSET (or)', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -512,7 +596,13 @@ test('TEST (false)', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -549,7 +639,13 @@ test('FORPREP, FORLOOP (int)', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -586,7 +682,13 @@ test('FORPREP, FORLOOP (float)', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -622,7 +724,13 @@ test('SETTABLE, GETTABLE', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -667,7 +775,13 @@ test('SETUPVAL, GETUPVAL', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -703,7 +817,13 @@ test('SETTABUP, GETTABUP', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -747,7 +867,13 @@ test('SELF', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -780,7 +906,13 @@ test('SETLIST', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -817,7 +949,13 @@ test('Variable SETLIST', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -849,7 +987,13 @@ test('Long SETLIST', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -898,7 +1042,13 @@ test('TFORCALL, TFORLOOP', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -933,7 +1083,13 @@ test('LEN', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); @@ -976,7 +1132,13 @@ test('CONCAT', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test", "text"); + let reader = function(L, data) { + let code = luaCode; + luaCode = null; + return code; + }; + + lapi.lua_load(L, reader, luaCode, "test", "text"); }, "Lua program loaded without error"); diff --git a/tests/llex.js b/tests/llex.js deleted file mode 100644 index 8b69acc..0000000 --- a/tests/llex.js +++ /dev/null @@ -1,97 +0,0 @@ -"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/load.js b/tests/load.js deleted file mode 100644 index a71de6b..0000000 --- a/tests/load.js +++ /dev/null @@ -1,68 +0,0 @@ -"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 |