From 0ba3c5d516b1a0b67cff6d5f4b4583284086dd4b Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 2 Mar 2017 21:15:42 +0100 Subject: load, luaL_loadbuffer(x), luaL_loadstring, lua_replace, lua_isnone, lua_isnoneornil, lua_setupvalue --- tests/load.js | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/load.js (limited to 'tests') diff --git a/tests/load.js b/tests/load.js new file mode 100644 index 0000000..0f524f3 --- /dev/null +++ b/tests/load.js @@ -0,0 +1,82 @@ +"use strict"; + +const test = require('tape'); +const beautify = require('js-beautify').js_beautify; + +const tests = require("./tests.js"); +const getState = tests.getState; +const toByteCode = tests.toByteCode; + +const VM = require("../src/lvm.js"); +const ldo = require("../src/ldo.js"); +const lapi = require("../src/lapi.js"); +const lauxlib = require("../src/lauxlib.js"); +const lua = require('../src/lua.js'); +const linit = require('../src/linit.js'); +const CT = lua.constant_types; + + +test('luaL_loadstring', function (t) { + let luaCode = ` + local a = "hello world" + return a + `, L; + + t.plan(3); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, luaCode); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lapi.lua_call(L, 0, -1); + + }, "Lua program ran without error"); + + t.strictEqual( + lapi.lua_tostring(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(); + + linit.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, luaCode); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lapi.lua_call(L, 0, -1); + + }, "Lua program ran without error"); + + t.strictEqual( + lapi.lua_tostring(L, -1), + "js running lua running lua", + "Correct element(s) on the stack" + ); + +}); \ No newline at end of file -- cgit v1.2.3-70-g09d2