summaryrefslogtreecommitdiff
path: root/tests/test-suite/inprogress/coroutine.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-25 15:36:09 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-25 15:36:09 +0200
commit106a349f6a33c1ccbe2e0aa5dcf9b7a1b3771eac (patch)
treee0c753c9e7c8755a8354c347dc3c503c4fa13cad /tests/test-suite/inprogress/coroutine.js
parente6217e63be392351e491eb292d26da533f408d7d (diff)
downloadfengari-106a349f6a33c1ccbe2e0aa5dcf9b7a1b3771eac.tar.gz
fengari-106a349f6a33c1ccbe2e0aa5dcf9b7a1b3771eac.tar.bz2
fengari-106a349f6a33c1ccbe2e0aa5dcf9b7a1b3771eac.zip
ltests.js: newstate, loadlib, doremote, closestate
Diffstat (limited to 'tests/test-suite/inprogress/coroutine.js')
-rw-r--r--tests/test-suite/inprogress/coroutine.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test-suite/inprogress/coroutine.js b/tests/test-suite/inprogress/coroutine.js
index 29461d3..2aece7d 100644
--- a/tests/test-suite/inprogress/coroutine.js
+++ b/tests/test-suite/inprogress/coroutine.js
@@ -1291,6 +1291,62 @@ test("[test-suite] coroutine: resuming running coroutine", function (t) {
}, "Lua program ran without error");
});
+test("[test-suite] coroutine: using a main thread as a coroutine", function (t) {
+ let luaCode = `
+ local state = T.newstate()
+ T.loadlib(state)
+
+ assert(T.doremote(state, [[
+ coroutine = require'coroutine';
+ X = function (x) coroutine.yield(x, 'BB'); return 'CC' end;
+ return 'ok']]))
+
+ t = table.pack(T.testC(state, [[
+ rawgeti R 1 # get main thread
+ pushstring 'XX'
+ getglobal X # get function for body
+ pushstring AA # arg
+ resume 1 1 # 'resume' shadows previous stack!
+ gettop
+ setglobal T # top
+ setglobal B # second yielded value
+ setglobal A # fist yielded value
+ rawgeti R 1 # get main thread
+ pushnum 5 # arg (noise)
+ resume 1 1 # after coroutine ends, previous stack is back
+ pushstatus
+ return *
+ ]]))
+ assert(t.n == 4 and t[2] == 'XX' and t[3] == 'CC' and t[4] == 'OK')
+ assert(T.doremote(state, "return T") == '2')
+ assert(T.doremote(state, "return A") == 'AA')
+ assert(T.doremote(state, "return B") == 'BB')
+
+ T.closestate(state)
+ `, 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(luaCode));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lua.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+});
+
+
test("[test-suite] coroutine: tests for coroutine API", { skip: true }, function (t) {
t.comment("TODO");
});