aboutsummaryrefslogtreecommitdiff
path: root/tests/lbaselib.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lbaselib.js')
-rw-r--r--tests/lbaselib.js47
1 files changed, 44 insertions, 3 deletions
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index d71e3ab..d2f0e0e 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -426,19 +426,19 @@ test('select', function (t) {
}, "JS Lua program ran without error");
t.deepEqual(
- lapi.lua_topointer(L, -3).map(e => e.value),
+ [...lapi.lua_topointer(L, -3).entries()].map(e => e[1].value),
[3],
"Correct element(s) on the stack"
);
t.deepEqual(
- lapi.lua_topointer(L, -2).map(e => e.value),
+ [...lapi.lua_topointer(L, -2).entries()].map(e => e[1].value).sort(),
[2, 3],
"Correct element(s) on the stack"
);
t.deepEqual(
- lapi.lua_topointer(L, -1).map(e => e.value),
+ [...lapi.lua_topointer(L, -1).entries()].map(e => e[1].value).sort(),
[2, 3],
"Correct element(s) on the stack"
);
@@ -552,4 +552,45 @@ test('rawlen', function (t) {
5,
"Correct element(s) on the stack"
);
+});
+
+
+test('next', function (t) {
+ let luaCode = `
+ local total = 0
+ local t = {
+ 1,
+ two = 2,
+ 3,
+ four = 4
+ }
+
+ for k,v in next, t, nil do
+ total = total + v
+ end
+
+ return total
+ `, 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-next");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tonumber(L, -1),
+ 10,
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file