diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-05-10 15:45:05 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-05-11 08:44:58 +0200 |
commit | 762c1e3594a8c2eac03dd2a1a005d8712ce9635f (patch) | |
tree | 6ddda36b4e0d74c9e268c42a7ca98c04322a4274 | |
parent | 011c821b3a94c0d2fa8892696178c76aed4c2349 (diff) | |
download | fengari-762c1e3594a8c2eac03dd2a1a005d8712ce9635f.tar.gz fengari-762c1e3594a8c2eac03dd2a1a005d8712ce9635f.tar.bz2 fengari-762c1e3594a8c2eac03dd2a1a005d8712ce9635f.zip |
[test-suite] events.js
-rw-r--r-- | src/ltable.js | 2 | ||||
-rw-r--r-- | tests/test-suite/events.js | 84 |
2 files changed, 85 insertions, 1 deletions
diff --git a/src/ltable.js b/src/ltable.js index b1f48e8..ce3ba77 100644 --- a/src/ltable.js +++ b/src/ltable.js @@ -139,7 +139,7 @@ const luaH_next = function(L, table, keyI) { if (!table.strong.has(hash)) /* item not in table */ - return ldebug.luaG_runerror(L, "invalid key to 'next'"); + return ldebug.luaG_runerror(L, defs.to_luastring("invalid key to 'next'")) let indexes = table.strong.keys(); while (1) { diff --git a/tests/test-suite/events.js b/tests/test-suite/events.js index d7dfe15..c54a93c 100644 --- a/tests/test-suite/events.js +++ b/tests/test-suite/events.js @@ -297,3 +297,87 @@ test("[test-suite] events: test comparison", function (t) { }, "Lua program ran without error"); }); + + +// TODO: uncomment asserts when next is fixed for cleared table entries +test("[test-suite] events: test 'partial order'", function (t) { + let luaCode = ` + t = {} + + local function rawSet(x) + local y = {} + for _,k in pairs(x) do y[k] = 1 end + return y + end + + local function Set(x) + return setmetatable(rawSet(x), t) + end + + t.__lt = function (a,b) + for k in pairs(a) do + if not b[k] then return false end + b[k] = nil + end + return next(b) ~= nil + end + + t.__le = nil + + assert(Set{1,2,3} < Set{1,2,3,4}) + -- assert(not(Set{1,2,3,4} < Set{1,2,3,4})) + -- assert((Set{1,2,3,4} <= Set{1,2,3,4})) + -- assert((Set{1,2,3,4} >= Set{1,2,3,4})) + assert((Set{1,3} <= Set{3,5})) -- wrong!! model needs a 'le' method ;-) + + t.__le = function (a,b) + for k in pairs(a) do + if not b[k] then return false end + end + return true + end + + assert(not (Set{1,3} <= Set{3,5})) -- now its OK! + assert(not(Set{1,3} <= Set{3,5})) + assert(not(Set{1,3} >= Set{3,5})) + + t.__eq = function (a,b) + for k in pairs(a) do + if not b[k] then return false end + b[k] = nil + end + return next(b) == nil + end + + local s = Set{1,3,5} + -- assert(s == Set{3,5,1}) + assert(not rawequal(s, Set{3,5,1})) + assert(rawequal(s, s)) + -- assert(Set{1,3,5,1} == rawSet{3,5,1}) + -- assert(rawSet{1,3,5,1} == Set{3,5,1}) + assert(Set{1,3,5} ~= Set{3,5,1,6}) + + -- '__eq' is not used for table accesses + t[Set{1,3,5}] = 1 + assert(t[Set{1,3,5}] == nil) + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lualib.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"); + +}); |