Skip to content

Commit c59a44a

Browse files
committed
Add some tests for running continuations with nqp::continuationreset.
1 parent b2b8c93 commit c59a44a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

t/moar/01-continuations.t

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# continuations.
44

5-
plan(19);
5+
plan(24);
66

77
{
88
# unique objects
@@ -130,6 +130,31 @@ plan(19);
130130
ok($B_in_invoke == 20, 'invoke also sees the invocation context');
131131
}
132132

133+
{
134+
my $log := '';
135+
136+
my $next;
137+
nqp::continuationreset(nqp::null(), {
138+
$log := $log ~ 1;
139+
nqp::continuationcontrol(0, nqp::null(), -> $cont { $next := $cont });
140+
$log := $log ~ 2;
141+
nqp::continuationcontrol(0, nqp::null(), -> $cont { $next := $cont });
142+
$log := $log ~ 3;
143+
nqp::continuationcontrol(0, nqp::null(), -> $cont { $next := $cont });
144+
$log := $log ~ 4;
145+
777;
146+
});
147+
148+
is($log, '1', 'passing a continuation to nqp::continuationreset 1/4');
149+
nqp::continuationreset(nqp::null(), $next);
150+
is($log, '12', 'passing a continuation to nqp::continuationreset 2/4');
151+
nqp::continuationreset(nqp::null(), $next);
152+
is($log, '123', 'passing a continuation to nqp::continuationreset 3/4');
153+
my $ret := nqp::continuationreset(nqp::null(), $next);
154+
is($log, '1234', 'passing a continuation to nqp::continuationreset 4/4');
155+
is($ret, 777, 'passing a continuation to nqp::continuationreset - correct return value');
156+
}
157+
133158
# gather/take example
134159
{
135160
my $SENTINEL := [];

0 commit comments

Comments
 (0)