From d792a7dad54039074890d9d379eec8676cb9fa5a Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 6 Mar 2017 07:34:00 +0100 Subject: string.char --- tests/lstrlib.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/lstrlib.js (limited to 'tests') 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 -- cgit v1.2.3-70-g09d2