aboutsummaryrefslogtreecommitdiff
path: root/tests/lbaselib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-20 12:09:05 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-20 12:09:05 +0100
commit5860ec2bde3b220eff01b3bd1462e60905ef2fe9 (patch)
tree7002ef7a3417388c1077b6df34f14b8acb0bd34d /tests/lbaselib.js
parent6d3d22b3938a811bdde9a311753837003df42d08 (diff)
downloadfengari-5860ec2bde3b220eff01b3bd1462e60905ef2fe9.tar.gz
fengari-5860ec2bde3b220eff01b3bd1462e60905ef2fe9.tar.bz2
fengari-5860ec2bde3b220eff01b3bd1462e60905ef2fe9.zip
type
Diffstat (limited to 'tests/lbaselib.js')
-rw-r--r--tests/lbaselib.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index b3af927..87009ca 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -186,4 +186,57 @@ test('rawset, rawget', function (t) {
"bye",
"Correct element(s) on the stack"
);
+});
+
+
+test('type', function (t) {
+ let luaCode = `
+ return type(1), type(true), type("hello"), type({}), type(nil)
+ `, L;
+
+ t.plan(6);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-type");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -5),
+ "number",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -4),
+ "boolean",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -3),
+ "string",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -2),
+ "table",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -1),
+ "nil",
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file