diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lstrlib.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/lstrlib.js b/tests/lstrlib.js new file mode 100644 index 0000000..494b881 --- /dev/null +++ b/tests/lstrlib.js @@ -0,0 +1,81 @@ +"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('string.len', function (t) { + let luaCode = ` + local a = "world" + return string.len("hello"), a:len() + `, L; + + t.plan(4); + + 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_tointeger(L, -2), + 5, + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tointeger(L, -1), + 5, + "Correct element(s) on the stack" + ); + +}); + + +test('string.char', function (t) { + let luaCode = ` + return string.char(104, 101, 108, 108, 111) + `, 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", + "Correct element(s) on the stack" + ); +});
\ No newline at end of file |