summaryrefslogtreecommitdiff
path: root/tests/lexparse.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-02 14:27:33 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-02 15:08:57 +0100
commit2e83b8d2e3ac6c30a53e7919a1808b732aeff5a4 (patch)
treeb3f97c5148bebdec4356e6e25e59f0f49a7461fe /tests/lexparse.js
parent005223711f4e11da5c8f24d19d6e8a6b64f603a8 (diff)
downloadfengari-2e83b8d2e3ac6c30a53e7919a1808b732aeff5a4.tar.gz
fengari-2e83b8d2e3ac6c30a53e7919a1808b732aeff5a4.tar.bz2
fengari-2e83b8d2e3ac6c30a53e7919a1808b732aeff5a4.zip
[Parsing tests] LEN, CONCAT
Diffstat (limited to 'tests/lexparse.js')
-rw-r--r--tests/lexparse.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/lexparse.js b/tests/lexparse.js
index b661d6d..0226e92 100644
--- a/tests/lexparse.js
+++ b/tests/lexparse.js
@@ -913,4 +913,82 @@ test('TFORCALL, TFORLOOP', function (t) {
6,
"Program output is correct"
);
+});
+
+
+test('LEN', function (t) {
+ let luaCode = `
+ local t = {[10000] = "foo"}
+ local t2 = {1, 2, 3}
+ local s = "hello"
+
+ return #t, #t2, #s
+ `, L;
+
+ t.plan(5);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, null, luaCode, "test", "text");
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tonumber(L, -1),
+ 5,
+ "Program output is correct"
+ );
+
+ t.strictEqual(
+ lapi.lua_tonumber(L, -2),
+ 3,
+ "Program output is correct"
+ );
+
+ t.strictEqual(
+ lapi.lua_tonumber(L, -3),
+ 0,
+ "Program output is correct"
+ );
+});
+
+
+test('CONCAT', function (t) {
+ let luaCode = `
+ return "hello " .. 2 .. " you"
+ `, L;
+
+ t.plan(3);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, null, luaCode, "test", "text");
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.strictEqual(
+ L.stack[L.top - 1].value,
+ "hello 2 you",
+ "Program output is correct"
+ );
}); \ No newline at end of file