diff options
author | Benoit Giannangeli <giann@users.noreply.github.com> | 2017-03-01 11:54:57 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-03-01 12:19:22 +0100 |
commit | 166b951b9d05eff654ef664124f17c8a37f418a6 (patch) | |
tree | a783d5f05cd640d06065c514b87bc7cf74f5e506 /tests/load.js | |
parent | 94a301a27a8a75c4684790a99a898262b8354f68 (diff) | |
parent | 444182dbbb18f44cf7cafc378f092c28006be365 (diff) | |
download | fengari-166b951b9d05eff654ef664124f17c8a37f418a6.tar.gz fengari-166b951b9d05eff654ef664124f17c8a37f418a6.tar.bz2 fengari-166b951b9d05eff654ef664124f17c8a37f418a6.zip |
Merge pull request #2 from giann/feature/lex-parse
Lexing & Parsing
Diffstat (limited to 'tests/load.js')
-rw-r--r-- | tests/load.js | 68 |
1 files changed, 68 insertions, 0 deletions
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 |