aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-23 15:02:16 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-23 15:06:01 +0100
commit6482d1ddc52f26d0a8e2e2a398276db73fbaa2bf (patch)
treeb1bddc73de8865e020add398cee358a250986385 /tests
parent2ffe44e84bfb72f44e4a2a598591cf0ec1c1c704 (diff)
downloadfengari-6482d1ddc52f26d0a8e2e2a398276db73fbaa2bf.tar.gz
fengari-6482d1ddc52f26d0a8e2e2a398276db73fbaa2bf.tar.bz2
fengari-6482d1ddc52f26d0a8e2e2a398276db73fbaa2bf.zip
coroutine.running, upvalue need to be attached to their thread
Diffstat (limited to 'tests')
-rw-r--r--tests/lcorolib.js48
1 files changed, 44 insertions, 4 deletions
diff --git a/tests/lcorolib.js b/tests/lcorolib.js
index 5f6d43d..dfecd71 100644
--- a/tests/lcorolib.js
+++ b/tests/lcorolib.js
@@ -14,6 +14,7 @@ const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
+const lstate = require('../src/lstate.js');
const CT = lua.constant_types;
@@ -130,15 +131,54 @@ test('coroutine.isyieldable', function (t) {
}, "JS Lua program ran without error");
- t.strictEqual(
+ t.ok(
lapi.lua_toboolean(L, -2),
- true,
"Correct element(s) on the stack"
);
- t.strictEqual(
+ t.notOk(
+ lapi.lua_toboolean(L, -1),
+ "Correct element(s) on the stack"
+ );
+});
+
+
+test('coroutine.running', function (t) {
+ let luaCode = `
+ local running, ismain
+
+ local co = coroutine.create(function ()
+ running, ismain = coroutine.running()
+ end)
+
+ coroutine.resume(co)
+
+ return running, ismain
+ `, 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.running");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.ok(
+ lapi.lua_tothread(L, -2) instanceof lstate.lua_State,
+ "Correct element(s) on the stack"
+ );
+
+ t.notOk(
lapi.lua_toboolean(L, -1),
- false,
"Correct element(s) on the stack"
);
}); \ No newline at end of file