summaryrefslogtreecommitdiff
path: root/tests/lapi.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lapi.js')
-rw-r--r--tests/lapi.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/lapi.js b/tests/lapi.js
index 6c5d7a4..8dd2680 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -168,4 +168,51 @@ test('lua_pushboolean', function (t) {
true,
"top is correct"
);
+});
+
+
+test('lua_pushvalue', function (t) {
+ let L;
+
+ t.plan(6);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ lapi.lua_pushstring(L, "hello");
+
+ lapi.lua_pushvalue(L, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_gettop(L),
+ 2,
+ "top is correct"
+ );
+
+ t.strictEqual(
+ lauxlib.luaL_typename(L, -1),
+ "string",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lauxlib.luaL_typename(L, -2),
+ "string",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ L.stack[lapi.lua_gettop(L)].value,
+ "hello",
+ "top is correct"
+ );
+
+ t.strictEqual(
+ L.stack[lapi.lua_gettop(L) - 1].value,
+ "hello",
+ "top is correct"
+ );
}); \ No newline at end of file