aboutsummaryrefslogtreecommitdiff
path: root/tests/test-suite
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-23 11:53:18 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-24 10:15:31 +0200
commit214d745949e33f869751214c0997bf02f63c88b4 (patch)
tree5273443f7ecf421749ef3115c76562b4738ba3b4 /tests/test-suite
parent3f6f88a1948454562b4416b2f4d398dedac725cc (diff)
downloadfengari-214d745949e33f869751214c0997bf02f63c88b4.tar.gz
fengari-214d745949e33f869751214c0997bf02f63c88b4.tar.bz2
fengari-214d745949e33f869751214c0997bf02f63c88b4.zip
ltests.js: fixed getstring
Diffstat (limited to 'tests/test-suite')
-rw-r--r--tests/test-suite/inprogress/coroutine.js156
-rw-r--r--tests/test-suite/ltests.js4
2 files changed, 103 insertions, 57 deletions
diff --git a/tests/test-suite/inprogress/coroutine.js b/tests/test-suite/inprogress/coroutine.js
index 602e050..b026bb6 100644
--- a/tests/test-suite/inprogress/coroutine.js
+++ b/tests/test-suite/inprogress/coroutine.js
@@ -657,61 +657,6 @@ test("[test-suite] coroutine: access to locals of erroneous coroutines", functio
});
-const jsprefix = `
- T = require('T')
-
- function fact (t, x)
- assert(turn == t)
- if x == 0 then return 1
- else return x*fact(t, x-1)
- end
- end
-`;
-
-test("[test-suite] coroutine: testing yields inside hooks", function (t) {
- let luaCode = `
- local A, B = 0, 0
-
- local x = coroutine.create(function ()
- T.sethook("yield 0", "", 2)
- A = fact("A", 6)
- end)
-
- local y = coroutine.create(function ()
- T.sethook("yield 0", "", 3)
- B = fact("B", 7)
- end)
-
- while A==0 or B==0 do -- A ~= 0 when 'x' finishes (similar for 'B','y')
- if A==0 then turn = "A"; assert(T.resume(x)) end
- if B==0 then turn = "B"; assert(T.resume(y)) end
- end
-
- assert(B // A == 7) -- fact(7) // fact(6)
- `, 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(jsprefix + luaCode));
-
- }, "Lua program loaded without error");
-
- t.doesNotThrow(function () {
-
- lua.lua_call(L, 0, -1);
-
- }, "Lua program ran without error");
-});
-
-
test("[test-suite] coroutine: leaving a pending coroutine open", function (t) {
let luaCode = `
_X = coroutine.wrap(function ()
@@ -975,6 +920,107 @@ test("[test-suite] coroutine: testing yields inside 'for' iterators", function (
});
+const jsprefix = `
+ T = require('T')
+
+ function fact (t, x)
+ assert(turn == t)
+ if x == 0 then return 1
+ else return x*fact(t, x-1)
+ end
+ end
+`;
+
+test("[test-suite] coroutine: testing yields inside hooks", function (t) {
+ let luaCode = `
+ local A, B = 0, 0
+
+ local x = coroutine.create(function ()
+ T.sethook("yield 0", "", 2)
+ A = fact("A", 6)
+ end)
+
+ local y = coroutine.create(function ()
+ T.sethook("yield 0", "", 3)
+ B = fact("B", 7)
+ end)
+
+ while A==0 or B==0 do -- A ~= 0 when 'x' finishes (similar for 'B','y')
+ if A==0 then turn = "A"; assert(T.resume(x)) end
+ if B==0 then turn = "B"; assert(T.resume(y)) end
+ end
+
+ assert(B // A == 7) -- fact(7) // fact(6)
+ `, 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(jsprefix + luaCode));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lua.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+});
+
+
+test("[test-suite] coroutine: testing yields inside line hook", function (t) {
+ let luaCode = `
+ local line = debug.getinfo(1, "l").currentline + 2 -- get line number
+ local function foo ()
+ local x = 10 --<< this line is 'line'
+ x = x + 10
+ _G.XX = x
+ end
+
+ -- testing yields in line hook
+ local co = coroutine.wrap(function ()
+ T.sethook("setglobal X; yield 0", "l", 0)
+ foo()
+ return 10
+ end)
+
+ _G.XX = nil;
+ _G.X = nil; co(); assert(_G.X == line)
+ _G.X = nil; co(); assert(_G.X == line + 1)
+ _G.X = nil; co(); assert(_G.X == line + 2 and _G.XX == nil)
+ _G.X = nil; co(); assert(_G.X == line + 3 and _G.XX == 20)
+ assert(co() == 10)
+ `, 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(jsprefix + luaCode));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lua.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+});
+
+
test("[test-suite] coroutine: tests for coroutine API", { skip: true }, function (t) {
t.comment("TODO");
});
diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js
index dcc8cec..685f530 100644
--- a/tests/test-suite/ltests.js
+++ b/tests/test-suite/ltests.js
@@ -58,7 +58,7 @@ const getstring = function(L, buff, pc) {
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] = 0;
+ buff.length = i;
return buff;
};
@@ -102,7 +102,7 @@ const runJS = function(L, L1, pc) {
let status = 0;
if (!pc || pc.length === 0) return lauxlib.luaL_error(L, "attempt to runJS empty script");
for (;;) {
- let inst = lua.to_jsstring(getstring(L, buff, pc).slice(0, -1));
+ let inst = lua.to_jsstring(getstring(L, buff, pc));
if (inst.length === 0) return 0;
else if (inst === "absindex") {
lua.lua_pushnumber(1, lua.lua_absindex(1, getindex(L, L1, pc)));