diff options
Diffstat (limited to 'unit_tests/scripts/coro/resume_basics.lua')
-rw-r--r-- | unit_tests/scripts/coro/resume_basics.lua | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/unit_tests/scripts/coro/resume_basics.lua b/unit_tests/scripts/coro/resume_basics.lua new file mode 100644 index 0000000..5b124f5 --- /dev/null +++ b/unit_tests/scripts/coro/resume_basics.lua | |||
@@ -0,0 +1,40 @@ | |||
1 | local lanes = require "lanes" | ||
2 | |||
3 | local fixture = require "fixture" | ||
4 | lanes.finally(fixture.throwing_finalizer) | ||
5 | |||
6 | local utils = lanes.require "_utils" | ||
7 | local PRINT = utils.MAKE_PRINT() | ||
8 | |||
9 | -- the coroutine generator | ||
10 | local coro_g = lanes.coro("*", {name = "auto"}, utils.yield_one_by_one) | ||
11 | |||
12 | ------------------------------------------------------------------------------------------------- | ||
13 | -- TEST: we can resume as many times as the lane yields, then read the returned value on indexing | ||
14 | ------------------------------------------------------------------------------------------------- | ||
15 | if true then | ||
16 | -- launch coroutine lane | ||
17 | local h = coro_g("hello", "world", "!") | ||
18 | -- read the yielded values, sending back the expected index | ||
19 | assert(h:resume(1) == "hello") | ||
20 | assert(h:resume(2) == "world") | ||
21 | assert(h:resume(3) == "!") | ||
22 | -- the lane return value is available as usual | ||
23 | local r = h[1] | ||
24 | assert(r == "bye!") | ||
25 | end | ||
26 | |||
27 | --------------------------------------------------------------------------------------------- | ||
28 | -- TEST: we can resume as many times as the lane yields, then read the returned value on join | ||
29 | --------------------------------------------------------------------------------------------- | ||
30 | if true then | ||
31 | -- launch coroutine lane | ||
32 | local h = coro_g("hello", "world", "!") | ||
33 | -- read the yielded values, sending back the expected index | ||
34 | assert(h:resume(1) == "hello") | ||
35 | assert(h:resume(2) == "world") | ||
36 | assert(h:resume(3) == "!") | ||
37 | -- the lane return value is available as usual | ||
38 | local s, r = h:join() | ||
39 | assert(h.status == "done" and s == true and r == "bye!") | ||
40 | end | ||