From be3f9810115cbaded69be37ebc3d088ee252a225 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 10 May 2017 15:30:33 +0200 Subject: Fixed bad order when trying __lt TM in luaV_lessequal --- tests/test-suite/events.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'tests') diff --git a/tests/test-suite/events.js b/tests/test-suite/events.js index 49576ef..3c9a590 100644 --- a/tests/test-suite/events.js +++ b/tests/test-suite/events.js @@ -201,3 +201,98 @@ test("[test-suite] events: testing metatable", function (t) { }, "Lua program ran without error"); }); + + +test("[test-suite] events: test for rawlen", function (t) { + let luaCode = ` + t = setmetatable({1,2,3}, {__len = function () return 10 end}) + assert(#t == 10 and rawlen(t) == 3) + assert(rawlen"abc" == 3) + assert(not pcall(rawlen, io.stdin)) + assert(not pcall(rawlen, 34)) + assert(not pcall(rawlen)) + + -- rawlen for long strings + assert(rawlen(string.rep('a', 1000)) == 1000) + `, 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: test comparison", function (t) { + let luaCode = ` + t = {} + t.__lt = function (a,b,c) + collectgarbage() + assert(c == nil) + if type(a) == 'table' then a = a.x end + if type(b) == 'table' then b = b.x end + return aOp(1)) and not(Op(1)>Op(2)) and (Op(2)>Op(1))) + assert(not(Op('a')>Op('a')) and not(Op('a')>Op('b')) and (Op('b')>Op('a'))) + assert((Op(1)>=Op(1)) and not(Op(1)>=Op(2)) and (Op(2)>=Op(1))) + assert((1 >= Op(1)) and not(1 >= Op(2)) and (Op(2) >= 1)) + assert((Op('a')>=Op('a')) and not(Op('a')>=Op('b')) and (Op('b')>=Op('a'))) + assert(('a' >= Op('a')) and not(Op('a') >= 'b') and (Op('b') >= Op('a'))) + end + + test() + + t.__le = function (a,b,c) + assert(c == nil) + if type(a) == 'table' then a = a.x end + if type(b) == 'table' then b = b.x end + return a<=b, "dummy" + end + + test() -- retest comparisons, now using both 'lt' and 'le' + `, 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"); + +}); -- cgit v1.2.3-70-g09d2