summaryrefslogtreecommitdiff
path: root/tests/test-suite
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-10 08:43:50 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-10 08:43:50 +0200
commitbb7bd48b2ee90472a1353f996b355559f78a197a (patch)
tree0a7c9cee09fc0b0ebee58c0511817e6980a36924 /tests/test-suite
parent8f34baffb57d45adeb45ee11412d57690658ec57 (diff)
downloadfengari-bb7bd48b2ee90472a1353f996b355559f78a197a.tar.gz
fengari-bb7bd48b2ee90472a1353f996b355559f78a197a.tar.bz2
fengari-bb7bd48b2ee90472a1353f996b355559f78a197a.zip
[test-suite] events.js
Diffstat (limited to 'tests/test-suite')
-rw-r--r--tests/test-suite/events.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test-suite/events.js b/tests/test-suite/events.js
index 40dc30d..8e160f8 100644
--- a/tests/test-suite/events.js
+++ b/tests/test-suite/events.js
@@ -62,6 +62,68 @@ test("[test-suite] events: testing metatable", function (t) {
t.__newindex = f
a[1] = 30; a.x = "101"; a[5] = 200
assert(a[1] == 27 and a.x == 98 and a[5] == 197)
+
+ do -- bug in Lua 5.3.2
+ local mt = {}
+ mt.__newindex = mt
+ local t = setmetatable({}, mt)
+ t[1] = 10 -- will segfault on some machines
+ assert(mt[1] == 10)
+ end
+
+ local c = {}
+ a = setmetatable({}, t)
+ t.__newindex = c
+ a[1] = 10; a[2] = 20; a[3] = 90
+ assert(c[1] == 10 and c[2] == 20 and c[3] == 90)
+
+ do
+ local a;
+ a = setmetatable({}, {__index = setmetatable({},
+ {__index = setmetatable({},
+ {__index = function (_,n) return a[n-3]+4, "lixo" end})})})
+ a[0] = 20
+ for i=0,10 do
+ assert(a[i*3] == 20 + i*4)
+ end
+ end
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ lauxlib.luaL_openlibs(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");
+
+});
+
+
+test("[test-suite] events: new index", function (t) {
+ let luaCode = `
+ do -- newindex
+ local foi
+ local a = {}
+ for i=1,10 do a[i] = 0; a['a'..i] = 0; end
+ setmetatable(a, {__newindex = function (t,k,v) foi=true; rawset(t,k,v) end})
+ foi = false; a[1]=0; assert(not foi)
+ foi = false; a['a1']=0; assert(not foi)
+ foi = false; a['a11']=0; assert(foi)
+ foi = false; a[11]=0; assert(foi)
+ foi = false; a[1]=nil; assert(not foi)
+ foi = false; a[1]=nil; assert(foi)
+ end
`, L;
t.plan(2);