aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-23 11:19:59 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-23 11:19:59 +0100
commit6d88293ea029a2372250297bd014b78d40507aa7 (patch)
treefdb0511531838f30e72cd580897a54a00b1bf015 /tests
parent567e12ce3f1ef413afa510cb583d6ac8442a7a4a (diff)
downloadfengari-6d88293ea029a2372250297bd014b78d40507aa7.tar.gz
fengari-6d88293ea029a2372250297bd014b78d40507aa7.tar.bz2
fengari-6d88293ea029a2372250297bd014b78d40507aa7.zip
coroutine.status, coroutine.wrap, coroutine.running, coroutine.isyieldable
Diffstat (limited to 'tests')
-rw-r--r--tests/lcorolib.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/lcorolib.js b/tests/lcorolib.js
index 6b48912..400e721 100644
--- a/tests/lcorolib.js
+++ b/tests/lcorolib.js
@@ -16,6 +16,7 @@ const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
const CT = lua.constant_types;
+
test('simple coroutine', function (t) {
let luaCode = `
local co = coroutine.create(function (start)
@@ -50,4 +51,53 @@ test('simple coroutine', function (t) {
625,
"Correct element(s) on the stack"
);
+});
+
+
+test('simple coroutine', function (t) {
+ let luaCode = `
+ local co = coroutine.create(function (start)
+ local b = coroutine.yield(start * start);
+ coroutine.yield(b * b)
+ end)
+
+ local s1 = coroutine.status(co)
+
+ local success, pow = coroutine.resume(co, 5)
+ success, pow = coroutine.resume(co, pow)
+
+ coroutine.resume(co, pow)
+
+ local s2 = coroutine.status(co)
+
+ return s1, s2
+ `, L;
+
+ t.plan(3);
+
+ // t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-coroutine");
+
+ lapi.lua_call(L, 0, -1);
+
+ // }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -2),
+ "suspended",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -1),
+ "dead",
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file