summaryrefslogtreecommitdiff
path: root/tests/test-suite/inprogress
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-23 11:30:45 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-24 10:15:31 +0200
commit3f6f88a1948454562b4416b2f4d398dedac725cc (patch)
tree979074e24387ef232f9b3b2c2b9ba5f11f93f760 /tests/test-suite/inprogress
parent98994b4140e9df0b7795c74f6debf0a4161aae5b (diff)
downloadfengari-3f6f88a1948454562b4416b2f4d398dedac725cc.tar.gz
fengari-3f6f88a1948454562b4416b2f4d398dedac725cc.tar.bz2
fengari-3f6f88a1948454562b4416b2f4d398dedac725cc.zip
ltests.js: resume, coroutine.js: yields inside hooks
Diffstat (limited to 'tests/test-suite/inprogress')
-rw-r--r--tests/test-suite/inprogress/coroutine.js55
1 files changed, 53 insertions, 2 deletions
diff --git a/tests/test-suite/inprogress/coroutine.js b/tests/test-suite/inprogress/coroutine.js
index 3161bf0..602e050 100644
--- a/tests/test-suite/inprogress/coroutine.js
+++ b/tests/test-suite/inprogress/coroutine.js
@@ -8,6 +8,7 @@ const lua = require('../../../src/lua.js');
const lauxlib = require('../../../src/lauxlib.js');
const lualib = require('../../../src/lualib.js');
+const ltests = require('../ltests.js');
const prefix = `
mt = {
@@ -656,8 +657,58 @@ test("[test-suite] coroutine: access to locals of erroneous coroutines", functio
});
-test("[test-suite] coroutine: JS Tests", { skip: true }, function (t) {
- t.comment("TODO");
+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");
});