summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-02-18 16:07:47 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-20 08:56:33 +0100
commitb62bcdfa67d6b0359bf45930ab392953d69eb399 (patch)
treeca4cc55bce206e8924f4099e1b19b6eab30234ed /tests
parent6316cab500cdaa944c6d2ef886138e7e9da0cc7c (diff)
downloadfengari-b62bcdfa67d6b0359bf45930ab392953d69eb399.tar.gz
fengari-b62bcdfa67d6b0359bf45930ab392953d69eb399.tar.bz2
fengari-b62bcdfa67d6b0359bf45930ab392953d69eb399.zip
setmetatable, getmetatable
Diffstat (limited to 'tests')
-rw-r--r--tests/lapi.js23
-rw-r--r--tests/lbaselib.js85
2 files changed, 85 insertions, 23 deletions
diff --git a/tests/lapi.js b/tests/lapi.js
index 561b774..30366d5 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -490,27 +490,4 @@ test('lua_settable, lua_gettable', function (t) {
"value",
"Correct element(s) on the stack"
);
-});
-
-
-test('print', function (t) {
- let luaCode = `
- print("hello", "world", 123)
- `, L;
-
- t.plan(1);
-
- t.doesNotThrow(function () {
-
- let bc = toByteCode(luaCode).dataView;
-
- L = lauxlib.luaL_newstate();
-
- linit.luaL_openlibs(L);
-
- lapi.lua_load(L, bc, "test-lua_load")
-
- lapi.lua_call(L, 0, 1);
-
- }, "JS Lua program ran without error");
}); \ No newline at end of file
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
new file mode 100644
index 0000000..3ddec2d
--- /dev/null
+++ b/tests/lbaselib.js
@@ -0,0 +1,85 @@
+/*jshint esversion: 6 */
+"use strict";
+
+const test = require('tape');
+const beautify = require('js-beautify').js_beautify;
+
+const tests = require("./tests.js");
+const getState = tests.getState;
+const toByteCode = tests.toByteCode;
+
+const VM = require("../src/lvm.js");
+const ldo = require("../src/ldo.js");
+const lapi = require("../src/lapi.js");
+const lauxlib = require("../src/lauxlib.js");
+const lua = require('../src/lua.js');
+const linit = require('../src/linit.js');
+const CT = lua.constant_types;
+
+
+test('print', function (t) {
+ let luaCode = `
+ print("hello", "world", 123)
+ `, L;
+
+ t.plan(1);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-print");
+
+ lapi.lua_call(L, 0, 1);
+
+ }, "JS Lua program ran without error");
+});
+
+
+test('setmetatable, getmetatable', function (t) {
+ let luaCode = `
+ local mt = {
+ __index = function ()
+ print("hello")
+ return "hello"
+ end
+ }
+
+ local t = {}
+
+ setmetatable(t, mt);
+
+ return t[1], getmetatable(t)
+ `, L;
+
+ t.plan(3);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-setmetatable-getmetatable");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -2),
+ "hello",
+ "Correct element(s) on the stack"
+ );
+
+ t.ok(
+ lapi.lua_istable(L, -1),
+ "Correct element(s) on the stack"
+ );
+}); \ No newline at end of file