diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-05-23 11:53:18 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-05-24 10:15:31 +0200 |
commit | 214d745949e33f869751214c0997bf02f63c88b4 (patch) | |
tree | 5273443f7ecf421749ef3115c76562b4738ba3b4 /tests/test-suite/inprogress | |
parent | 3f6f88a1948454562b4416b2f4d398dedac725cc (diff) | |
download | fengari-214d745949e33f869751214c0997bf02f63c88b4.tar.gz fengari-214d745949e33f869751214c0997bf02f63c88b4.tar.bz2 fengari-214d745949e33f869751214c0997bf02f63c88b4.zip |
ltests.js: fixed getstring
Diffstat (limited to 'tests/test-suite/inprogress')
-rw-r--r-- | tests/test-suite/inprogress/coroutine.js | 156 |
1 files changed, 101 insertions, 55 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"); }); |