summaryrefslogtreecommitdiff
path: root/tests/test-suite
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-suite')
-rw-r--r--tests/test-suite/constructs.js152
-rw-r--r--tests/test-suite/db.js16
-rw-r--r--tests/test-suite/ltests.js743
-rw-r--r--tests/test-suite/strings.js116
4 files changed, 511 insertions, 516 deletions
diff --git a/tests/test-suite/constructs.js b/tests/test-suite/constructs.js
index f180195..89bcce7 100644
--- a/tests/test-suite/constructs.js
+++ b/tests/test-suite/constructs.js
@@ -19,7 +19,7 @@ test('[test-suite] constructs: testing semicolons', function (t) {
; do ; a = 3; assert(a == 3) end;
;
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -45,7 +45,7 @@ test('[test-suite] constructs: invalid operations should not raise errors when n
let luaCode = `
if false then a = 3 // 0; a = 0 % 0 end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -110,7 +110,7 @@ test('[test-suite] constructs: testing priorities', function (t) {
assert(1234567890 == tonumber('1234567890') and 1234567890+1 == 1234567891)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -296,7 +296,7 @@ test('[test-suite] constructs: silly loops', function (t) {
a,b = F(1)~=nil; assert(a == true and b == nil);
a,b = F(nil)==nil; assert(a == true and b == nil)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -317,94 +317,92 @@ test('[test-suite] constructs: silly loops', function (t) {
});
-if (false) {
- test('[test-suite] constructs: huge loops, upvalue', function (t) {
- let luaCode = `
- -- sometimes will be 0, sometimes will not...
- _ENV.GLOB1 = math.floor(os.time()) % 2
-
- -- basic expressions with their respective values
- local basiccases = {
- {"nil", nil},
- {"false", false},
- {"true", true},
- {"10", 10},
- {"(0==_ENV.GLOB1)", 0 == _ENV.GLOB1},
- }
-
- print('testing short-circuit optimizations (' .. _ENV.GLOB1 .. ')')
-
-
- -- operators with their respective values
- local binops = {
- {" and ", function (a,b) if not a then return a else return b end end},
- {" or ", function (a,b) if a then return a else return b end end},
- }
-
- local cases = {}
-
- -- creates all combinations of '(cases[i] op cases[n-i])' plus
- -- 'not(cases[i] op cases[n-i])' (syntax + value)
- local function createcases (n)
- local res = {}
- for i = 1, n - 1 do
- for _, v1 in ipairs(cases[i]) do
- for _, v2 in ipairs(cases[n - i]) do
- for _, op in ipairs(binops) do
- local t = {
- "(" .. v1[1] .. op[1] .. v2[1] .. ")",
- op[2](v1[2], v2[2])
- }
- res[#res + 1] = t
- res[#res + 1] = {"not" .. t[1], not t[2]}
- end
- end
+test.skip('[test-suite] constructs: huge loops, upvalue', function (t) {
+ let luaCode = `
+ -- sometimes will be 0, sometimes will not...
+ _ENV.GLOB1 = math.floor(os.time()) % 2
+
+ -- basic expressions with their respective values
+ local basiccases = {
+ {"nil", nil},
+ {"false", false},
+ {"true", true},
+ {"10", 10},
+ {"(0==_ENV.GLOB1)", 0 == _ENV.GLOB1},
+ }
+
+ print('testing short-circuit optimizations (' .. _ENV.GLOB1 .. ')')
+
+
+ -- operators with their respective values
+ local binops = {
+ {" and ", function (a,b) if not a then return a else return b end end},
+ {" or ", function (a,b) if a then return a else return b end end},
+ }
+
+ local cases = {}
+
+ -- creates all combinations of '(cases[i] op cases[n-i])' plus
+ -- 'not(cases[i] op cases[n-i])' (syntax + value)
+ local function createcases (n)
+ local res = {}
+ for i = 1, n - 1 do
+ for _, v1 in ipairs(cases[i]) do
+ for _, v2 in ipairs(cases[n - i]) do
+ for _, op in ipairs(binops) do
+ local t = {
+ "(" .. v1[1] .. op[1] .. v2[1] .. ")",
+ op[2](v1[2], v2[2])
+ }
+ res[#res + 1] = t
+ res[#res + 1] = {"not" .. t[1], not t[2]}
end
end
- return res
end
+ end
+ return res
+ end
- -- do not do too many combinations for soft tests
- local level = _soft and 3 or 4
+ -- do not do too many combinations for soft tests
+ local level = _soft and 3 or 4
- cases[1] = basiccases
- for i = 2, level do cases[i] = createcases(i) end
+ cases[1] = basiccases
+ for i = 2, level do cases[i] = createcases(i) end
- local prog = [[if %s then IX = true end; return %s]]
+ local prog = [[if %s then IX = true end; return %s]]
- local i = 0
- for n = 1, level do
- for _, v in pairs(cases[n]) do
- local s = v[1]
- local p = load(string.format(prog, s, s), "")
- IX = false
- assert(p() == v[2] and IX == not not v[2])
- i = i + 1
- if i % 60000 == 0 then print('+') end
- end
- end
- `, L;
-
- t.plan(2);
+ local i = 0
+ for n = 1, level do
+ for _, v in pairs(cases[n]) do
+ local s = v[1]
+ local p = load(string.format(prog, s, s), "")
+ IX = false
+ assert(p() == v[2] and IX == not not v[2])
+ i = i + 1
+ if i % 60000 == 0 then print('+') end
+ end
+ end
+ `, L;
- t.doesNotThrow(function () {
+ t.plan(2);
+
+ t.doesNotThrow(function () {
- L = lauxlib.luaL_newstate();
+ L = lauxlib.luaL_newstate();
- lualib.luaL_openlibs(L);
+ lualib.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkload + luaCode));
+ lauxlib.luaL_loadstring(L, lua.to_luastring(checkload + luaCode));
- }, "Lua program loaded without error");
+ }, "Lua program loaded without error");
- t.doesNotThrow(function () {
+ t.doesNotThrow(function () {
- lua.lua_call(L, 0, -1);
+ lua.lua_call(L, 0, -1);
- }, "Lua program ran without error");
+ }, "Lua program ran without error");
- });
-}
+});
test("[test-suite] constructs: testing some syntax errors (chosen through 'gcov')", function (t) {
@@ -421,7 +419,7 @@ test("[test-suite] constructs: testing some syntax errors (chosen through 'gcov'
checkload(s, "too long")
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
diff --git a/tests/test-suite/db.js b/tests/test-suite/db.js
index 6d85a5f..a2e3ce6 100644
--- a/tests/test-suite/db.js
+++ b/tests/test-suite/db.js
@@ -515,7 +515,7 @@ test("[test-suite] db: tests for manipulating non-registered locals (C and Lua t
function g(a,b) return (a+1) + f() end
assert(g(0,0) == 30)
-
+
debug.sethook(nil);
assert(debug.gethook() == nil)
@@ -565,7 +565,7 @@ test("[test-suite] db: testing access to function arguments", function (t) {
dostring("XX = 12") -- test dostring inside hooks
-- testing errors inside hooks
assert(not pcall(load("a='joao'+1")))
- debug.sethook(function (e, l)
+ debug.sethook(function (e, l)
assert(debug.getinfo(2, "l").currentline == l)
local f,m,c = debug.gethook()
assert(e == "line")
@@ -690,7 +690,7 @@ test("[test-suite] db: testing upvalue access", function (t) {
assert(debug.setupvalue(foo1, 1, "xuxu") == "b")
assert(({debug.getupvalue(foo2, 3)})[2] == "xuxu")
-- upvalues of C functions are allways "called" "" (the empty string)
- assert(debug.getupvalue(string.gmatch("x", "x"), 1) == "")
+ assert(debug.getupvalue(string.gmatch("x", "x"), 1) == "")
`, L;
t.plan(2);
@@ -1030,7 +1030,7 @@ test("[test-suite] db: testing debugging of coroutines", function (t) {
let b = lua.to_luastring(luaCode);
if (lauxlib.luaL_loadbuffer(L, b, b.length, lua.to_luastring("@db.lua")) !== lua.LUA_OK)
- throw Error(lua.lua_tojsstring(L, -1));
+ throw Error(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -1304,7 +1304,7 @@ test("[test-suite] db: testing traceback sizes", function (t) {
let b = lua.to_luastring(luaCode);
if (lauxlib.luaL_loadbuffer(L, b, b.length, lua.to_luastring("@db.lua")) !== lua.LUA_OK)
- throw Error(lua.lua_tojsstring(L, -1));
+ throw Error(lua.lua_tojsstring(L, -1));
}, "Lua program loaded without error");
@@ -1389,7 +1389,7 @@ test("[test-suite] db: tests for 'source' in binary dumps", function (t) {
do
local prog = [[
return function (x)
- return function (y)
+ return function (y)
return x + y
end
end
@@ -1404,7 +1404,7 @@ test("[test-suite] db: tests for 'source' in binary dumps", function (t) {
local h = g(3)
assert(h(5) == 8)
assert(debug.getinfo(f).source == name and -- all functions have 'source'
- debug.getinfo(g).source == name and
+ debug.getinfo(g).source == name and
debug.getinfo(h).source == name)
-- again, without debug info
local c = string.dump(p, true)
@@ -1414,7 +1414,7 @@ test("[test-suite] db: tests for 'source' in binary dumps", function (t) {
local h = g(30)
assert(h(50) == 80)
assert(debug.getinfo(f).source == '=?' and -- no function has 'source'
- debug.getinfo(g).source == '=?' and
+ debug.getinfo(g).source == '=?' and
debug.getinfo(h).source == '=?')
end
`, L;
diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js
index 67ab87d..8d89102 100644
--- a/tests/test-suite/ltests.js
+++ b/tests/test-suite/ltests.js
@@ -58,7 +58,7 @@ const getstring = function(L, buff, pc) {
pc.offset++;
} else {
while (pc.script[pc.offset] !== 0 && pc.offset < pc.script.length && delimits.indexOf(pc.script[pc.offset]) < 0)
- buff[i++] = pc.script[pc.offset++];
+ buff[i++] = pc.script[pc.offset++];
}
buff.length = i;
return buff;
@@ -107,379 +107,378 @@ const runJS = function(L, L1, pc) {
let inst = lua.to_jsstring(getstring(L, buff, pc));
if (inst.length === 0) return 0;
switch (inst) {
- case "absindex": {
- lua.lua_pushnumber(L1, lua.lua_absindex(L1, getindex(L, L1, pc)));
- break;
- }
- case "append": {
- let t = getindex(L, L1, pc);
- let i = lua.lua_rawlen(L1, t);
- lua.lua_rawseti(L1, t, i + 1);
- break;
- }
- case "arith": {
- let op;
- skip(pc);
- op = ops.indexOf(pc.script[pc.offset++]);
- lua.lua_arith(L1, op);
- break;
- }
- case "call": {
- let narg = getnum(L, L1, pc);
- let nres = getnum(L, L1, pc);
- lua.lua_call(L1, narg, nres);
- break;
- }
- case "callk": {
- let narg = getnum(L, L1, pc);
- let nres = getnum(L, L1, pc);
- let i = getindex(L, L1, pc);
- lua.lua_callk(L1, narg, nres, i, Cfunck);
- break;
- }
- case "checkstack": {
- let sz = getnum(L, L1, pc);
- let msg = getstring(L, buff, pc);
- if (msg.length === 0)
- msg = null; /* to test 'luaL_checkstack' with no message */
- lauxlib.luaL_checkstack(L1, sz, msg);
- break;
- }
- case "compare": {
- let opt = getstring(L, buff, pc); /* EQ, LT, or LE */
- let op = (opt[0] === 'E'.charCodeAt(0)) ? lua.LUA_OPEQ
- : (opt[1] === 'T'.charCodeAt(0)) ? lua.LUA_OPLT : lua.LUA_OPLE;
- let a = getindex(L, L1, pc);
- let b = getindex(L, L1, pc);
- lua.lua_pushboolean(L1, lua.lua_compare(L1, a, b, op));
- break;
- }
- case "concat": {
- lua.lua_concat(L1, getnum(L, L1, pc));
- break;
- }
- case "copy": {
- let f = getindex(L, L1, pc);
- lua.lua_copy(L1, f, getindex(L, L1, pc));
- break;
- }
- case "func2num": {
- let func = lua.lua_tocfunction(L1, getindex(L, L1, pc));
- if (func === null) func = 0;
- else if (func.id) func = func.id;
- lua.lua_pushnumber(L1, func);
- break;
- }
- case "getfield": {
- let t = getindex(L, L1, pc);
- lua.lua_getfield(L1, t, getstring(L, buff, pc));
- break;
- }
- case "getglobal": {
- lua.lua_getglobal(L1, getstring(L, buff, pc));
- break;
- }
- case "getmetatable": {
- if (lua.lua_getmetatable(L1, getindex(L, L1, pc)) === 0)
+ case "absindex": {
+ lua.lua_pushnumber(L1, lua.lua_absindex(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "append": {
+ let t = getindex(L, L1, pc);
+ let i = lua.lua_rawlen(L1, t);
+ lua.lua_rawseti(L1, t, i + 1);
+ break;
+ }
+ case "arith": {
+ let op;
+ skip(pc);
+ op = ops.indexOf(pc.script[pc.offset++]);
+ lua.lua_arith(L1, op);
+ break;
+ }
+ case "call": {
+ let narg = getnum(L, L1, pc);
+ let nres = getnum(L, L1, pc);
+ lua.lua_call(L1, narg, nres);
+ break;
+ }
+ case "callk": {
+ let narg = getnum(L, L1, pc);
+ let nres = getnum(L, L1, pc);
+ let i = getindex(L, L1, pc);
+ lua.lua_callk(L1, narg, nres, i, Cfunck);
+ break;
+ }
+ case "checkstack": {
+ let sz = getnum(L, L1, pc);
+ let msg = getstring(L, buff, pc);
+ if (msg.length === 0)
+ msg = null; /* to test 'luaL_checkstack' with no message */
+ lauxlib.luaL_checkstack(L1, sz, msg);
+ break;
+ }
+ case "compare": {
+ let opt = getstring(L, buff, pc); /* EQ, LT, or LE */
+ let op = (opt[0] === 'E'.charCodeAt(0))
+ ? lua.LUA_OPEQ
+ : (opt[1] === 'T'.charCodeAt(0)) ? lua.LUA_OPLT : lua.LUA_OPLE;
+ let a = getindex(L, L1, pc);
+ let b = getindex(L, L1, pc);
+ lua.lua_pushboolean(L1, lua.lua_compare(L1, a, b, op));
+ break;
+ }
+ case "concat": {
+ lua.lua_concat(L1, getnum(L, L1, pc));
+ break;
+ }
+ case "copy": {
+ let f = getindex(L, L1, pc);
+ lua.lua_copy(L1, f, getindex(L, L1, pc));
+ break;
+ }
+ case "func2num": {
+ let func = lua.lua_tocfunction(L1, getindex(L, L1, pc));
+ if (func === null) func = 0;
+ else if (func.id) func = func.id;
+ lua.lua_pushnumber(L1, func);
+ break;
+ }
+ case "getfield": {
+ let t = getindex(L, L1, pc);
+ lua.lua_getfield(L1, t, getstring(L, buff, pc));
+ break;
+ }
+ case "getglobal": {
+ lua.lua_getglobal(L1, getstring(L, buff, pc));
+ break;
+ }
+ case "getmetatable": {
+ if (lua.lua_getmetatable(L1, getindex(L, L1, pc)) === 0)
+ lua.lua_pushnil(L1);
+ break;
+ }
+ case "gettable": {
+ lua.lua_gettable(L1, getindex(L, L1, pc));
+ break;
+ }
+ case "gettop": {
+ lua.lua_pushinteger(L1, lua.lua_gettop(L1));
+ break;
+ }
+ case "gsub": {
+ let a = getnum(L, L1, pc);
+ let b = getnum(L, L1, pc);
+ let c = getnum(L, L1, pc);
+ lauxlib.luaL_gsub(L1, lua.lua_tostring(L1, a), lua.lua_tostring(L1, b), lua.lua_tostring(L1, c));
+ break;
+ }
+ case "insert": {
+ lua.lua_insert(L1, getnum(L, L1, pc));
+ break;
+ }
+ case "iscfunction": {
+ lua.lua_pushboolean(L1, lua.lua_iscfunction(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "isfunction": {
+ lua.lua_pushboolean(L1, lua.lua_isfunction(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "isnil": {
+ lua.lua_pushboolean(L1, lua.lua_isnil(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "isnull": {
+ lua.lua_pushboolean(L1, lua.lua_isnone(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "isnumber": {
+ lua.lua_pushboolean(L1, lua.lua_isnumber(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "isstring": {
+ lua.lua_pushboolean(L1, lua.lua_isstring(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "istable": {
+ lua.lua_pushboolean(L1, lua.lua_istable(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "isudataval": {
+ lua.lua_pushboolean(L1, lua.lua_islightuserdata(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "isuserdata": {
+ lua.lua_pushboolean(L1, lua.lua_isuserdata(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "len": {
+ lua.lua_len(L1, getindex(L, L1, pc));
+ break;
+ }
+ case "Llen": {
+ lua.lua_pushinteger(L1, lauxlib.luaL_len(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "loadfile": {
+ lauxlib.luaL_loadfile(L1, lauxlib.luaL_checkstring(L1, getnum(L, L1, pc)));
+ break;
+ }
+ case "loadstring": {
+ let s = lauxlib.luaL_checkstring(L1, getnum(L, L1, pc));
+ lauxlib.luaL_loadstring(L1, s);
+ break;
+ }
+ case "newmetatable": {
+ lua.lua_pushboolean(L1, lauxlib.luaL_newmetatable(L1, getstring(L, buff, pc)));
+ break;
+ }
+ case "newtable": {
+ lua.lua_newtable(L1);
+ break;
+ }
+ case "newthread": {
+ lua.lua_newthread(L1);
+ break;
+ }
+ case "newuserdata": {
+ lua.lua_newuserdata(L1, getnum(L, L1, pc));
+ break;
+ }
+ case "next": {
+ lua.lua_next(L1, -2);
+ break;
+ }
+ case "objsize": {
+ lua.lua_pushinteger(L1, lua.lua_rawlen(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "pcall": {
+ let narg = getnum(L, L1, pc);
+ let nres = getnum(L, L1, pc);
+ status = lua.lua_pcall(L1, narg, nres, getnum(L, L1, pc));
+ break;
+ }
+ case "pcallk": {
+ let narg = getnum(L, L1, pc);
+ let nres = getnum(L, L1, pc);
+ let i = getindex(L, L1, pc);
+ status = lua.lua_pcallk(L1, narg, nres, 0, i, Cfunck);
+ break;
+ }
+ case "pop": {
+ lua.lua_pop(L1, getnum(L, L1, pc));
+ break;
+ }
+ case "print": {
+ let n = getnum(L, L1, pc);
+ if (n !== 0) {
+ console.log(`${lauxlib.luaL_tojsstring(L1, n, null)}\n`);
+ lua.lua_pop(L1, 1);
+ }
+ else printstack(L1);
+ break;
+ }
+ case "pushbool": {
+ lua.lua_pushboolean(L1, getnum(L, L1, pc));
+ break;
+ }
+ case "pushcclosure": {
+ lua.lua_pushcclosure(L1, testJS, getnum(L, L1, pc));
+ break;
+ }
+ case "pushint": {
+ lua.lua_pushinteger(L1, getnum(L, L1, pc));
+ break;
+ }
+ case "pushnil": {
lua.lua_pushnil(L1);
- break;
- }
- case "gettable": {
- lua.lua_gettable(L1, getindex(L, L1, pc));
- break;
- }
- case "gettop": {
- lua.lua_pushinteger(L1, lua.lua_gettop(L1));
- break;
- }
- case "gsub": {
- let a = getnum(L, L1, pc);
- let b = getnum(L, L1, pc);
- let c = getnum(L, L1, pc);
- lauxlib.luaL_gsub(L1, lua.lua_tostring(L1, a), lua.lua_tostring(L1, b), lua.lua_tostring(L1, c));
- break;
- }
- case "insert": {
- lua.lua_insert(L1, getnum(L, L1, pc));
- break;
- }
- case "iscfunction": {
- lua.lua_pushboolean(L1, lua.lua_iscfunction(L1, getindex(L, L1, pc)));
- break;
- }
- case "isfunction": {
- lua.lua_pushboolean(L1, lua.lua_isfunction(L1, getindex(L, L1, pc)));
- break;
- }
- case "isnil": {
- lua.lua_pushboolean(L1, lua.lua_isnil(L1, getindex(L, L1, pc)));
- break;
- }
- case "isnull": {
- lua.lua_pushboolean(L1, lua.lua_isnone(L1, getindex(L, L1, pc)));
- break;
- }
- case "isnumber": {
- lua.lua_pushboolean(L1, lua.lua_isnumber(L1, getindex(L, L1, pc)));
- break;
- }
- case "isstring": {
- lua.lua_pushboolean(L1, lua.lua_isstring(L1, getindex(L, L1, pc)));
- break;
- }
- case "istable": {
- lua.lua_pushboolean(L1, lua.lua_istable(L1, getindex(L, L1, pc)));
- break;
- }
- case "isudataval": {
- lua.lua_pushboolean(L1, lua.lua_islightuserdata(L1, getindex(L, L1, pc)));
- break;
- }
- case "isuserdata": {
- lua.lua_pushboolean(L1, lua.lua_isuserdata(L1, getindex(L, L1, pc)));
- break;
- }
- case "len": {
- lua.lua_len(L1, getindex(L, L1, pc));
- break;
- }
- case "Llen": {
- lua.lua_pushinteger(L1, lauxlib.luaL_len(L1, getindex(L, L1, pc)));
- break;
- }
- case "loadfile": {
- lauxlib.luaL_loadfile(L1, lauxlib.luaL_checkstring(L1, getnum(L, L1, pc)));
- break;
- }
- case "loadstring": {
- let s = lauxlib.luaL_checkstring(L1, getnum(L, L1, pc));
- lauxlib.luaL_loadstring(L1, s);
- break;
- }
- case "newmetatable": {
- lua.lua_pushboolean(L1, lauxlib.luaL_newmetatable(L1, getstring(L, buff, pc)));
- break;
- }
- case "newtable": {
- lua.lua_newtable(L1);
- break;
- }
- case "newthread": {
- lua.lua_newthread(L1);
- break;
- }
- case "newuserdata": {
- lua.lua_newuserdata(L1, getnum(L, L1, pc));
- break;
- }
- case "next": {
- lua.lua_next(L1, -2);
- break;
- }
- case "objsize": {
- lua.lua_pushinteger(L1, lua.lua_rawlen(L1, getindex(L, L1, pc)));
- break;
- }
- case "pcall": {
- let narg = getnum(L, L1, pc);
- let nres = getnum(L, L1, pc);
- status = lua.lua_pcall(L1, narg, nres, getnum(L, L1, pc));
- break;
- }
- case "pcallk": {
- let narg = getnum(L, L1, pc);
- let nres = getnum(L, L1, pc);
- let i = getindex(L, L1, pc);
- status = lua.lua_pcallk(L1, narg, nres, 0, i, Cfunck);
- break;
- }
- case "pop": {
- lua.lua_pop(L1, getnum(L, L1, pc));
- break;
- }
- case "print": {
- let n = getnum(L, L1, pc);
- if (n !== 0) {
- console.log(`${lauxlib.luaL_tojsstring(L1, n, null)}\n`);
- lua.lua_pop(L1, 1);
+ break;
}
- else printstack(L1);
- break;
- }
- case "pushbool": {
- lua.lua_pushboolean(L1, getnum(L, L1, pc));
- break;
- }
- case "pushcclosure": {
- lua.lua_pushcclosure(L1, testJS, getnum(L, L1, pc));
- break;
- }
- case "pushint": {
- lua.lua_pushinteger(L1, getnum(L, L1, pc));
- break;
- }
- case "pushnil": {
- lua.lua_pushnil(L1);
- break;
- }
- case "pushnum": {
- lua.lua_pushnumber(L1, getnum(L, L1, pc));
- break;
- }
- case "pushstatus": {
- pushcode(L1, status);
- break;
- }
- case "pushstring": {
- lua.lua_pushstring(L1, getstring(L, buff, pc));
- break;
- }
- case "pushupvalueindex": {
- lua.lua_pushinteger(L1, lua.lua_upvalueindex(getnum(L, L1, pc)));
- break;
- }
- case "pushvalue": {
- lua.lua_pushvalue(L1, getindex(L, L1, pc));
- break;
- }
- case "rawgeti": {
- let t = getindex(L, L1, pc);
- lua.lua_rawgeti(L1, t, getnum(L, L1, pc));
- break;
- }
- case "rawgetp": {
- let t = getindex(L, L1, pc);
- lua.lua_rawgetp(L1, t, getnum(L, L1, pc));
- break;
- }
- case "rawsetp": {
- let t = getindex(L, L1, pc);
- lua.lua_rawsetp(L1, t, getnum(L, L1, pc));
- break;
- }
- case "remove": {
- lua.lua_remove(L1, getnum(L, L1, pc));
- break;
- }
- case "replace": {
- lua.lua_replace(L1, getindex(L, L1, pc));
- break;
- }
- case "resume": {
- let i = getindex(L, L1, pc);
- status = lua.lua_resume(lua.lua_tothread(L1, i), L, getnum(L, L1, pc));
- break;
- }
- case "return": {
- let n = getnum(L, L1, pc);
- if (L1 != L) {
- let i;
- for (i = 0; i < n; i++)
- lua.lua_pushstring(L, lua.lua_tostring(L1, -(n - i)));
- }
- return n;
- }
- case "rotate": {
- let i = getindex(L, L1, pc);
- lua.lua_rotate(L1, i, getnum(L, L1, pc));
- break;
- }
- case "setfield": {
- let t = getindex(L, L1, pc);
- lua.lua_setfield(L1, t, getstring(L, buff, pc));
- break;
- }
- case "setglobal": {
- lua.lua_setglobal(L1, getstring(L, buff, pc));
- break;
- }
- case "sethook": {
- let mask = getnum(L, L1, pc);
- let count = getnum(L, L1, pc);
- sethookaux(L1, mask, count, getstring(L, buff, pc));
- break;
- }
- case "setmetatable": {
- lua.lua_setmetatable(L1, getindex(L, L1, pc));
- break;
- }
- case "settable": {
- lua.lua_settable(L1, getindex(L, L1, pc));
- break;
- }
- case "settop": {
- lua.lua_settop(L1, getnum(L, L1, pc));
- break;
- }
- case "testudata": {
- let i = getindex(L, L1, pc);
- lua.lua_pushboolean(L1, lauxlib.luaL_testudata(L1, i, getstring(L, buff, pc)) !== null);
- break;
- }
- case "error": {
- lua.lua_error(L1);
- break;
- }
- case "throw": {
- throw new Error();
- break;
- }
- case "tobool": {
- lua.lua_pushboolean(L1, lua.lua_toboolean(L1, getindex(L, L1, pc)));
- break;
- }
- case "tocfunction": {
- lua.lua_pushcfunction(L1, lua.lua_tocfunction(L1, getindex(L, L1, pc)));
- break;
- }
- case "tointeger": {
- lua.lua_pushinteger(L1, lua.lua_tointeger(L1, getindex(L, L1, pc)));
- break;
- }
- case "tonumber": {
- lua.lua_pushnumber(L1, lua.lua_tonumber(L1, getindex(L, L1, pc)));
- break;
- }
- case "topointer": {
- let p = lua.lua_topointer(L1, getindex(L, L1, pc));
- if (p === null) p = 0;
- else if (p.id) p = p.id;
- lua.lua_pushnumber(L1, p); /* in ltests.c, p is casted to a size_t so NULL gives 0 */
- break;
- }
- case "tostring": {
- let s = lua.lua_tostring(L1, getindex(L, L1, pc));
- let s1 = lua.lua_pushstring(L1, s);
- assert((s === null && s1 === null) || s.join('|') === s1.join('|'));
- break;
- }
- case "type": {
- lua.lua_pushstring(L1, lauxlib.luaL_typename(L1, getnum(L, L1, pc)));
- break;
- }
- case "xmove": {
- let f = getindex(L, L1, pc);
- let t = getindex(L, L1, pc);
- let fs = (f === 0) ? L1 : lua.lua_tothread(L1, f);
- let ts = (t === 0) ? L1 : lua.lua_tothread(L1, t);
- let n = getnum(L, L1, pc);
- if (n === 0) n = lua.lua_gettop(fs);
- lua.lua_xmove(fs, ts, n);
- break;
- }
- case "yield": {
- return lua.lua_yield(L1, getnum(L, L1, pc));
- }
- case "yieldk": {
- let nres = getnum(L, L1, pc);
- let i = getindex(L, L1, pc);
- return lua.lua_yieldk(L1, nres, i, Cfunck);
- }
- default:
- lauxlib.luaL_error(L, lua.to_luastring("unknown instruction %s"), buff);
+ case "pushnum": {
+ lua.lua_pushnumber(L1, getnum(L, L1, pc));
+ break;
+ }
+ case "pushstatus": {
+ pushcode(L1, status);
+ break;
+ }
+ case "pushstring": {
+ lua.lua_pushstring(L1, getstring(L, buff, pc));
+ break;
+ }
+ case "pushupvalueindex": {
+ lua.lua_pushinteger(L1, lua.lua_upvalueindex(getnum(L, L1, pc)));
+ break;
+ }
+ case "pushvalue": {
+ lua.lua_pushvalue(L1, getindex(L, L1, pc));
+ break;
+ }
+ case "rawgeti": {
+ let t = getindex(L, L1, pc);
+ lua.lua_rawgeti(L1, t, getnum(L, L1, pc));
+ break;
+ }
+ case "rawgetp": {
+ let t = getindex(L, L1, pc);
+ lua.lua_rawgetp(L1, t, getnum(L, L1, pc));
+ break;
+ }
+ case "rawsetp": {
+ let t = getindex(L, L1, pc);
+ lua.lua_rawsetp(L1, t, getnum(L, L1, pc));
+ break;
+ }
+ case "remove": {
+ lua.lua_remove(L1, getnum(L, L1, pc));
+ break;
+ }
+ case "replace": {
+ lua.lua_replace(L1, getindex(L, L1, pc));
+ break;
+ }
+ case "resume": {
+ let i = getindex(L, L1, pc);
+ status = lua.lua_resume(lua.lua_tothread(L1, i), L, getnum(L, L1, pc));
+ break;
+ }
+ case "return": {
+ let n = getnum(L, L1, pc);
+ if (L1 != L) {
+ let i;
+ for (i = 0; i < n; i++)
+ lua.lua_pushstring(L, lua.lua_tostring(L1, -(n - i)));
+ }
+ return n;
+ }
+ case "rotate": {
+ let i = getindex(L, L1, pc);
+ lua.lua_rotate(L1, i, getnum(L, L1, pc));
+ break;
+ }
+ case "setfield": {
+ let t = getindex(L, L1, pc);
+ lua.lua_setfield(L1, t, getstring(L, buff, pc));
+ break;
+ }
+ case "setglobal": {
+ lua.lua_setglobal(L1, getstring(L, buff, pc));
+ break;
+ }
+ case "sethook": {
+ let mask = getnum(L, L1, pc);
+ let count = getnum(L, L1, pc);
+ sethookaux(L1, mask, count, getstring(L, buff, pc));
+ break;
+ }
+ case "setmetatable": {
+ lua.lua_setmetatable(L1, getindex(L, L1, pc));
+ break;
+ }
+ case "settable": {
+ lua.lua_settable(L1, getindex(L, L1, pc));
+ break;
+ }
+ case "settop": {
+ lua.lua_settop(L1, getnum(L, L1, pc));
+ break;
+ }
+ case "testudata": {
+ let i = getindex(L, L1, pc);
+ lua.lua_pushboolean(L1, lauxlib.luaL_testudata(L1, i, getstring(L, buff, pc)) !== null);
+ break;
+ }
+ case "error": {
+ lua.lua_error(L1);
+ break;
+ }
+ case "throw": {
+ throw new Error();
+ }
+ case "tobool": {
+ lua.lua_pushboolean(L1, lua.lua_toboolean(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "tocfunction": {
+ lua.lua_pushcfunction(L1, lua.lua_tocfunction(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "tointeger": {
+ lua.lua_pushinteger(L1, lua.lua_tointeger(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "tonumber": {
+ lua.lua_pushnumber(L1, lua.lua_tonumber(L1, getindex(L, L1, pc)));
+ break;
+ }
+ case "topointer": {
+ let p = lua.lua_topointer(L1, getindex(L, L1, pc));
+ if (p === null) p = 0;
+ else if (p.id) p = p.id;
+ lua.lua_pushnumber(L1, p); /* in ltests.c, p is casted to a size_t so NULL gives 0 */
+ break;
+ }
+ case "tostring": {
+ let s = lua.lua_tostring(L1, getindex(L, L1, pc));
+ let s1 = lua.lua_pushstring(L1, s);
+ assert((s === null && s1 === null) || s.join('|') === s1.join('|'));
+ break;
+ }
+ case "type": {
+ lua.lua_pushstring(L1, lauxlib.luaL_typename(L1, getnum(L, L1, pc)));
+ break;
+ }
+ case "xmove": {
+ let f = getindex(L, L1, pc);
+ let t = getindex(L, L1, pc);
+ let fs = (f === 0) ? L1 : lua.lua_tothread(L1, f);
+ let ts = (t === 0) ? L1 : lua.lua_tothread(L1, t);
+ let n = getnum(L, L1, pc);
+ if (n === 0) n = lua.lua_gettop(fs);
+ lua.lua_xmove(fs, ts, n);
+ break;
+ }
+ case "yield": {
+ return lua.lua_yield(L1, getnum(L, L1, pc));
+ }
+ case "yieldk": {
+ let nres = getnum(L, L1, pc);
+ let i = getindex(L, L1, pc);
+ return lua.lua_yieldk(L1, nres, i, Cfunck);
+ }
+ default:
+ lauxlib.luaL_error(L, lua.to_luastring("unknown instruction %s"), buff);
}
- }
- return 0;
+ }
};
@@ -817,7 +816,7 @@ const buildop = function(p, pc) {
const listcode = function(L) {
lauxlib.luaL_argcheck(L, lua.lua_isfunction(L, 1) && !lua.lua_iscfunction(L, 1),
- 1, lua.to_luastring("Lua function expected", true));
+ 1, lua.to_luastring("Lua function expected", true));
let p = obj_at(L, 1);
lua.lua_newtable(L);
setnameval(L, lua.to_luastring("maxstack", true), p.maxstacksize);
diff --git a/tests/test-suite/strings.js b/tests/test-suite/strings.js
index 50873e5..0efedcb 100644
--- a/tests/test-suite/strings.js
+++ b/tests/test-suite/strings.js
@@ -36,7 +36,7 @@ test('[test-suite] strings: string comparisons', function (t) {
assert('\\0\\0\\0' >= '\\0\\0\\0')
assert(not ('\\0\\0b' < '\\0\\0a\\0'))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -78,7 +78,7 @@ test('[test-suite] strings: string.sub', function (t) {
assert('\\0\\0\\0' >= '\\0\\0\\0')
assert(not ('\\0\\0b' < '\\0\\0a\\0'))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -116,7 +116,7 @@ test('[test-suite] strings: string.find', function (t) {
assert(string.find('', 'aaa', 1) == nil)
assert(('alo(.)alo'):find('(.)', 1, 1) == 4)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -148,7 +148,7 @@ test('[test-suite] strings: string.len and #', function (t) {
assert(#"\\0\\0\\0" == 3)
assert(#"1234567890" == 10)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -205,7 +205,7 @@ test('[test-suite] strings: string.byte/string.char', function (t) {
checkerror("too large", string.rep, 'a', (1 << 30), ',')
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -242,7 +242,7 @@ test('[test-suite] strings: repetitions with separator', function (t) {
for i=0,30 do assert(string.len(string.rep('a', i)) == i) end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -294,7 +294,7 @@ test('[test-suite] strings: tostring', function (t) {
assert(tostring(-1203 + 0.0) == "-1203")
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -341,7 +341,7 @@ test('[test-suite] strings: string.format', function (t) {
assert(string.format('"-%20s.20s"', string.rep("%", 2000)) ==
string.format("%q", "-"..string.rep("%", 2000)..".20s"))
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -382,7 +382,7 @@ test('[test-suite] strings: %q', function (t) {
checkerror("no literal", string.format, "%q", {})
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -409,7 +409,7 @@ test('[test-suite] strings: embedded zeros error', function (t) {
assert(string.format("\\0%s\\0", "\\0\\0\\1") == "\\0\\0\\0\\1\\0")
checkerror("contains zeros", string.format, "%10s", "\\0")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -452,7 +452,7 @@ test('[test-suite] strings: format x tostring', function (t) {
assert(string.format("%+08d", 31501) == "+0031501")
assert(string.format("%+08d", -30927) == "-0030927")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -489,7 +489,7 @@ test('[test-suite] strings: longest number that can be formatted', function (t)
assert(tonumber(s) == -(10^i))
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -538,7 +538,7 @@ test('[test-suite] strings: large numbers for format', function (t) {
end
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -586,7 +586,7 @@ test("[test-suite] strings: 'format %a %A'", function (t) {
assert(string.find(string.format("%a", 0/0), "^%-?nan"))
assert(string.find(string.format("%a", -0.0), "^%-0x0"))
end
-
+
if not pcall(string.format, "%.3a", 0) then
(Message or print)("\\n >>> modifiers for format '%a' not available <<<\\n")
else
@@ -595,7 +595,7 @@ test("[test-suite] strings: 'format %a %A'", function (t) {
end
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -635,7 +635,7 @@ test("[test-suite] strings: errors in format", function (t) {
assert(load("return 1\\n--comment without ending EOL")() == 1)
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -686,7 +686,7 @@ test("[test-suite] strings: table.concat", function (t) {
assert(table.concat(a, ",", 3) == "c")
assert(table.concat(a, ",", 4) == "")
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {
@@ -709,61 +709,59 @@ test("[test-suite] strings: table.concat", function (t) {
// TODO: os.setlocale NYI
-if (false) {
- test("[test-suite] strings: locale", function (t) {
- let luaCode = `
- if not _port then
-
- local locales = { "ptb", "pt_BR.iso88591", "ISO-8859-1" }
- local function trylocale (w)
- for i = 1, #locales do
- if os.setlocale(locales[i], w) then
- print(string.format("'%s' locale set to '%s'", w, locales[i]))
- return locales[i]
- end
- end
- print(string.format("'%s' locale not found", w))
- return false
+test.skip("[test-suite] strings: locale", function (t) {
+ let luaCode = `
+ if not _port then
+
+ local locales = { "ptb", "pt_BR.iso88591", "ISO-8859-1" }
+ local function trylocale (w)
+ for i = 1, #locales do
+ if os.setlocale(locales[i], w) then
+ print(string.format("'%s' locale set to '%s'", w, locales[i]))
+ return locales[i]
end
+ end
+ print(string.format("'%s' locale not found", w))
+ return false
+ end
- if trylocale("collate") then
- assert("alo" < "álo" and "álo" < "amo")
- end
+ if trylocale("collate") then
+ assert("alo" < "álo" and "álo" < "amo")
+ end
- if trylocale("ctype") then
- assert(string.gsub("áéíóú", "%a", "x") == "xxxxx")
- assert(string.gsub("áÁéÉ", "%l", "x") == "xÁxÉ")
- assert(string.gsub("áÁéÉ", "%u", "x") == "áxéx")
- assert(string.upper"áÁé{xuxu}ção" == "ÁÁÉ{XUXU}ÇÃO")
- end
+ if trylocale("ctype") then
+ assert(string.gsub("áéíóú", "%a", "x") == "xxxxx")
+ assert(string.gsub("áÁéÉ", "%l", "x") == "xÁxÉ")
+ assert(string.gsub("áÁéÉ", "%u", "x") == "áxéx")
+ assert(string.upper"áÁé{xuxu}ção" == "ÁÁÉ{XUXU}ÇÃO")
+ end
- os.setlocale("C")
- assert(os.setlocale() == 'C')
- assert(os.setlocale(nil, "numeric") == 'C')
+ os.setlocale("C")
+ assert(os.setlocale() == 'C')
+ assert(os.setlocale(nil, "numeric") == 'C')
- end
- `, L;
-
- t.plan(2);
+ end
+ `, L;
- t.doesNotThrow(function () {
+ t.plan(2);
- L = lauxlib.luaL_newstate();
+ t.doesNotThrow(function () {
- lualib.luaL_openlibs(L);
+ L = lauxlib.luaL_newstate();
- lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
+ lualib.luaL_openlibs(L);
- }, "Lua program loaded without error");
+ lauxlib.luaL_loadstring(L, lua.to_luastring(checkerror + luaCode));
- t.doesNotThrow(function () {
+ }, "Lua program loaded without error");
- lua.lua_call(L, 0, -1);
+ t.doesNotThrow(function () {
- }, "Lua program ran without error");
+ lua.lua_call(L, 0, -1);
- });
-}
+ }, "Lua program ran without error");
+
+});
test("[test-suite] strings: bug in Lua 5.3.2: 'gmatch' iterator does not work across coroutines", function (t) {
@@ -775,7 +773,7 @@ test("[test-suite] strings: bug in Lua 5.3.2: 'gmatch' iterator does not work ac
assert(co() == "2")
end
`, L;
-
+
t.plan(2);
t.doesNotThrow(function () {