summaryrefslogtreecommitdiff
path: root/tests/test-suite/events.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-11 09:41:05 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-11 09:41:05 +0200
commit4d4782d890830d7730f0f9ada5638f9443e76047 (patch)
tree69df668f1bb9b3ff49fd2f0845a06b11ab49837f /tests/test-suite/events.js
parent022f7f974b6cb13b9a432986bce072f719fa60d6 (diff)
downloadfengari-4d4782d890830d7730f0f9ada5638f9443e76047.tar.gz
fengari-4d4782d890830d7730f0f9ada5638f9443e76047.tar.bz2
fengari-4d4782d890830d7730f0f9ada5638f9443e76047.zip
[test-suite] events.js (userdata)
Diffstat (limited to 'tests/test-suite/events.js')
-rw-r--r--tests/test-suite/events.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test-suite/events.js b/tests/test-suite/events.js
index c54a93c..8aa7aa7 100644
--- a/tests/test-suite/events.js
+++ b/tests/test-suite/events.js
@@ -8,6 +8,8 @@ const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const lualib = require('../../src/lualib.js');
+const ltests = require('./ltests.js');
+
test("[test-suite] events: testing metatable", function (t) {
let luaCode = `
@@ -381,3 +383,48 @@ test("[test-suite] events: test 'partial order'", function (t) {
}, "Lua program ran without error");
});
+
+
+test("[test-suite] events: __eq between userdata", function (t) {
+ let luaCode = `
+ T = require('T')
+
+ local u1 = T.newuserdata(0)
+ local u2 = T.newuserdata(0)
+ local u3 = T.newuserdata(0)
+ assert(u1 ~= u2 and u1 ~= u3)
+ debug.setuservalue(u1, 1);
+ debug.setuservalue(u2, 2);
+ debug.setuservalue(u3, 1);
+ debug.setmetatable(u1, {__eq = function (a, b)
+ return debug.getuservalue(a) == debug.getuservalue(b)
+ end})
+ debug.setmetatable(u2, {__eq = function (a, b)
+ return true
+ end})
+ assert(u1 == u3 and u3 == u1 and u1 ~= u2)
+ assert(u2 == u1 and u2 == u3 and u3 == u2)
+ assert(u2 ~= {}) -- different types cannot be equal
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ lualib.luaL_openlibs(L);
+
+ ltests.luaopen_tests(L);
+
+ lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lua.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+});