summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-23 12:40:46 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-23 12:47:12 +0100
commit2ffe44e84bfb72f44e4a2a598591cf0ec1c1c704 (patch)
tree3ef6287240366503951d72cb79ee0717e7f740f7 /tests
parent6d88293ea029a2372250297bd014b78d40507aa7 (diff)
downloadfengari-2ffe44e84bfb72f44e4a2a598591cf0ec1c1c704.tar.gz
fengari-2ffe44e84bfb72f44e4a2a598591cf0ec1c1c704.tar.bz2
fengari-2ffe44e84bfb72f44e4a2a598591cf0ec1c1c704.zip
Fixed bad lua_gettop
Diffstat (limited to 'tests')
-rw-r--r--tests/lcorolib.js51
1 files changed, 46 insertions, 5 deletions
diff --git a/tests/lcorolib.js b/tests/lcorolib.js
index 400e721..5f6d43d 100644
--- a/tests/lcorolib.js
+++ b/tests/lcorolib.js
@@ -17,7 +17,7 @@ const linit = require('../src/linit.js');
const CT = lua.constant_types;
-test('simple coroutine', function (t) {
+test('coroutine.create, coroutine.yield, coroutine.resume', function (t) {
let luaCode = `
local co = coroutine.create(function (start)
local b = coroutine.yield(start * start);
@@ -54,7 +54,7 @@ test('simple coroutine', function (t) {
});
-test('simple coroutine', function (t) {
+test('coroutine.status', function (t) {
let luaCode = `
local co = coroutine.create(function (start)
local b = coroutine.yield(start * start);
@@ -75,7 +75,7 @@ test('simple coroutine', function (t) {
t.plan(3);
- // t.doesNotThrow(function () {
+ t.doesNotThrow(function () {
let bc = toByteCode(luaCode).dataView;
@@ -83,11 +83,11 @@ test('simple coroutine', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-coroutine");
+ lapi.lua_load(L, bc, "test-coroutine.status");
lapi.lua_call(L, 0, -1);
- // }, "JS Lua program ran without error");
+ }, "JS Lua program ran without error");
t.strictEqual(
lapi.lua_tostring(L, -2),
@@ -100,4 +100,45 @@ test('simple coroutine', function (t) {
"dead",
"Correct element(s) on the stack"
);
+});
+
+
+test('coroutine.isyieldable', function (t) {
+ let luaCode = `
+ local co = coroutine.create(function ()
+ coroutine.yield(coroutine.isyieldable());
+ end)
+
+ local succes, yieldable = coroutine.resume(co)
+
+ return yieldable, coroutine.isyieldable()
+ `, 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.isyieldable");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_toboolean(L, -2),
+ true,
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_toboolean(L, -1),
+ false,
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file