summaryrefslogtreecommitdiff
path: root/tests/lcorolib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-23 15:14:11 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-23 15:14:11 +0100
commite8a12210e0a5a0d86b5bacfd10e673b36d56fb38 (patch)
tree0f27dc78240054558a1621d804a66f445abf4954 /tests/lcorolib.js
parent6482d1ddc52f26d0a8e2e2a398276db73fbaa2bf (diff)
downloadfengari-e8a12210e0a5a0d86b5bacfd10e673b36d56fb38.tar.gz
fengari-e8a12210e0a5a0d86b5bacfd10e673b36d56fb38.tar.bz2
fengari-e8a12210e0a5a0d86b5bacfd10e673b36d56fb38.zip
coroutine.wrap
Diffstat (limited to 'tests/lcorolib.js')
-rw-r--r--tests/lcorolib.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/lcorolib.js b/tests/lcorolib.js
index dfecd71..78024dd 100644
--- a/tests/lcorolib.js
+++ b/tests/lcorolib.js
@@ -181,4 +181,41 @@ test('coroutine.running', function (t) {
lapi.lua_toboolean(L, -1),
"Correct element(s) on the stack"
);
+});
+
+
+test('coroutine.wrap', function (t) {
+ let luaCode = `
+ local co = coroutine.wrap(function (start)
+ local b = coroutine.yield(start * start);
+ coroutine.yield(b * b)
+ end)
+
+ pow = co(5)
+ pow = co(pow)
+
+ return pow
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-coroutine.wrap");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tonumber(L, -1),
+ 625,
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file