summaryrefslogtreecommitdiff
path: root/tests/lbaselib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-22 09:00:12 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-22 09:00:12 +0100
commita40719dc74b8dbb0d6c8fc0272c0d79ad8a7a9ea (patch)
treea87cbfa7d3e7620b64681f3f738320c58be0f469 /tests/lbaselib.js
parentdbe2a3bf2ef8c053e6c596c99e29eb27b6118f1b (diff)
downloadfengari-a40719dc74b8dbb0d6c8fc0272c0d79ad8a7a9ea.tar.gz
fengari-a40719dc74b8dbb0d6c8fc0272c0d79ad8a7a9ea.tar.bz2
fengari-a40719dc74b8dbb0d6c8fc0272c0d79ad8a7a9ea.zip
select
Diffstat (limited to 'tests/lbaselib.js')
-rw-r--r--tests/lbaselib.js53
1 files changed, 47 insertions, 6 deletions
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index 53191eb..73d13a3 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -289,7 +289,7 @@ test('error, protected', function (t) {
t.ok(
lapi.lua_tostring(L, -1).endsWith("you fucked up"),
"Error is on the stack"
- )
+ );
});
@@ -321,7 +321,7 @@ test('pcall', function (t) {
t.ok(
lapi.lua_tostring(L, -1).endsWith("you fucked up"),
"Error is on the stack"
- )
+ );
});
@@ -359,12 +359,12 @@ test('xpcall', function (t) {
t.ok(
lapi.lua_tostring(L, -1).startsWith("Something's wrong:"),
"msgh was called and modified the error"
- )
+ );
t.ok(
lapi.lua_tostring(L, -1).endsWith("you fucked up"),
"msgh was called and modified the error"
- )
+ );
});
@@ -390,7 +390,7 @@ test('ipairs', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-pcall");
+ lapi.lua_load(L, bc, "test-ipairs");
lapi.lua_call(L, 0, -1);
@@ -400,5 +400,46 @@ test('ipairs', function (t) {
lapi.lua_tointeger(L, -1),
15,
"Correct element(s) on the stack"
- )
+ );
+});
+
+
+test('select', function (t) {
+ let luaCode = `
+ return {select('#', 1, 2, 3)}, {select(2, 1, 2, 3)}, {select(-2, 1, 2, 3)}
+ `, L;
+
+ t.plan(4);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-select");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.deepEqual(
+ lapi.lua_topointer(L, -3).array.map(e => e.value),
+ [3],
+ "Correct element(s) on the stack"
+ );
+
+ t.deepEqual(
+ lapi.lua_topointer(L, -2).array.map(e => e.value),
+ [2, 3],
+ "Correct element(s) on the stack"
+ );
+
+ t.deepEqual(
+ lapi.lua_topointer(L, -1).array.map(e => e.value),
+ [2, 3],
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file