summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-22 08:23:37 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-22 08:23:37 +0100
commitdbe2a3bf2ef8c053e6c596c99e29eb27b6118f1b (patch)
tree4920ab827f35d0305a951fde5d627cc8c767b4fe /tests
parentc1824a99035a231172f3c10ae3ee24a3e6330260 (diff)
downloadfengari-dbe2a3bf2ef8c053e6c596c99e29eb27b6118f1b.tar.gz
fengari-dbe2a3bf2ef8c053e6c596c99e29eb27b6118f1b.tar.bz2
fengari-dbe2a3bf2ef8c053e6c596c99e29eb27b6118f1b.zip
ipairs
Diffstat (limited to 'tests')
-rw-r--r--tests/lbaselib.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index 85563da..53191eb 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -365,4 +365,40 @@ test('xpcall', function (t) {
lapi.lua_tostring(L, -1).endsWith("you fucked up"),
"msgh was called and modified the error"
)
+});
+
+
+test('ipairs', function (t) {
+ let luaCode = `
+ local t = {1, 2, 3, 4, 5, ['yo'] = 'lo'}
+
+ local sum = 0
+ for i, v in ipairs(t) do
+ sum = sum + v
+ end
+
+ return sum
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-pcall");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tointeger(L, -1),
+ 15,
+ "Correct element(s) on the stack"
+ )
}); \ No newline at end of file