diff options
author | daurnimator <quae@daurnimator.com> | 2018-04-20 21:16:24 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-04-20 21:16:24 +1000 |
commit | a260f381d30e036b39078fee0295e539067c10a3 (patch) | |
tree | 4f3b2ecb264ec8dd29cac74d23223d15d297eb8e /tests/load.js | |
parent | fe9b43374c2e8dc28df0ce460aefaf50b933aaa7 (diff) | |
parent | 9f5d4d35de0b88334bba7c11a9e960a19ee0740b (diff) | |
download | fengari-a260f381d30e036b39078fee0295e539067c10a3.tar.gz fengari-a260f381d30e036b39078fee0295e539067c10a3.tar.bz2 fengari-a260f381d30e036b39078fee0295e539067c10a3.zip |
Merge branch 'test-with-jest'
Diffstat (limited to 'tests/load.js')
-rw-r--r-- | tests/load.js | 203 |
1 files changed, 0 insertions, 203 deletions
diff --git a/tests/load.js b/tests/load.js deleted file mode 100644 index 0eb0ccf..0000000 --- a/tests/load.js +++ /dev/null @@ -1,203 +0,0 @@ -"use strict"; - -const test = require('tape'); - -const tests = require("./tests.js"); -const toByteCode = tests.toByteCode; - -const lua = require('../src/lua.js'); -const lauxlib = require('../src/lauxlib.js'); -const lualib = require('../src/lualib.js'); -const {to_luastring} = require("../src/fengaricore.js"); - -test('luaL_loadstring', function (t) { - let luaCode = ` - local a = "hello world" - return a - `, L; - - t.plan(3); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - - t.strictEqual( - lua.lua_tojsstring(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(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - - t.strictEqual( - lua.lua_tojsstring(L, -1), - "js running lua running lua", - "Correct element(s) on the stack" - ); -}); - - -test('luaL_loadbuffer', function (t) { - let luaCode = ` - local a = "hello world" - return a - `, L; - - t.plan(3); - - t.doesNotThrow(function () { - - let bc = toByteCode(luaCode); - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadbuffer(L, bc, null, to_luastring("test")); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - - t.strictEqual( - lua.lua_tojsstring(L, -1), - "hello world", - "Correct element(s) on the stack" - ); -}); - -// TODO: test stdin -test('loadfile', function (t) { - let luaCode = ` - local f = assert(loadfile("tests/loadfile-test.lua")) - return f() - `, L; - - t.plan(3); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - - t.strictEqual( - lua.lua_tojsstring(L, -1), - "hello world", - "Correct element(s) on the stack" - ); -}); - - -test('loadfile (binary)', function (t) { - let luaCode = ` - local f = assert(loadfile("tests/loadfile-test.bc")) - return f() - `, L; - - t.plan(3); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - - t.strictEqual( - lua.lua_tojsstring(L, -1), - "hello world", - "Correct element(s) on the stack" - ); -}); - - -test('dofile', function (t) { - let luaCode = ` - return dofile("tests/loadfile-test.lua") - `, L; - - t.plan(3); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - - t.strictEqual( - lua.lua_tojsstring(L, -1), - "hello world", - "Correct element(s) on the stack" - ); -}); |