summaryrefslogtreecommitdiff
path: root/tests/lstrlib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-06 07:34:00 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-06 08:07:34 +0100
commitd792a7dad54039074890d9d379eec8676cb9fa5a (patch)
tree3bb2391b1a48f4fa460ab5f20f9f439b533c9e65 /tests/lstrlib.js
parent2ac8543dfd87f4c227385d6890bfcb011fc341f1 (diff)
downloadfengari-d792a7dad54039074890d9d379eec8676cb9fa5a.tar.gz
fengari-d792a7dad54039074890d9d379eec8676cb9fa5a.tar.bz2
fengari-d792a7dad54039074890d9d379eec8676cb9fa5a.zip
string.char
Diffstat (limited to 'tests/lstrlib.js')
-rw-r--r--tests/lstrlib.js81
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