aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-24 08:52:06 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-24 09:00:48 +0100
commitae4e53e2e7234a167058199085921a9182e8522a (patch)
treeedf216c29fd494397c8b27e8088298677db01046 /tests
parentf52c86ef0450dd03ef9f2cd01143d6ed9ac759d1 (diff)
downloadfengari-ae4e53e2e7234a167058199085921a9182e8522a.tar.gz
fengari-ae4e53e2e7234a167058199085921a9182e8522a.tar.bz2
fengari-ae4e53e2e7234a167058199085921a9182e8522a.zip
table.insert
Diffstat (limited to 'tests')
-rw-r--r--tests/ltablib.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/ltablib.js b/tests/ltablib.js
index 8221fe0..1a04e4c 100644
--- a/tests/ltablib.js
+++ b/tests/ltablib.js
@@ -116,4 +116,38 @@ test('table.unpack', function (t) {
4,
"Correct element(s) on the stack"
);
+});
+
+
+test('table.insert', function (t) {
+ let luaCode = `
+ local t = {1, 3, 4}
+ table.insert(t, 5)
+ table.insert(t, 2, 2)
+ return t
+ `, 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-table.insert");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.deepEqual(
+ [...lapi.lua_topointer(L, -1).entries()]
+ .filter(e => typeof e[0] === 'number') // Filter out the 'n' field
+ .map(e => e[1].value).sort(),
+ [1, 2, 3, 4, 5],
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file