6 use Test::More tests => 18;
8 use Scope::Upper qw<yield leave>;
16 is $@, '', 'yield() does not croak';
17 is_deeply \@res, [ 0, 2 ], 'yield() in eval { ... }';
23 is $@, '', 'yield() does not croak';
24 is_deeply \@res, [ 3, 5 ], 'yield() in eval "..."';
30 is_deeply \@res, [ 6, 8 ], 'yield() in sub { ... }';
36 is_deeply \@res, [ 9, 11 ], 'yield() in do { ... }';
42 is_deeply \@res, [ 12, 14 ], 'yield() in map { ... }';
52 is $loop, 16, 'yield() exited for';
53 is_deeply \@res, [ 15, 19 ], 'yield() in for () { ... }';
63 is $loop, 21, 'yield() exited while';
64 is_deeply \@res, [ 20, 23 ], 'yield() in while () { ... }';
70 $s =~ s/./yield; die 'not reached'/e;
73 my $line = __LINE__-3;
75 qr/^yield\(\) can't target a substitution context at \Q$0\E line $line/,
76 'yield() cannot exit subst';
80 skip 'perl 5.10 is required to test interaction with given/when' => 6
83 @res = eval <<'TESTCASE';
93 is_deeply \@res, [ 24, 27 ], 'yield() in given { }';
95 # Beware that calling yield() in when() in given() sends us directly at the
96 # end of the enclosing given block.
110 is $@, '', 'yield() in when { } in given did not croak';
111 is_deeply \@res, [ 28, 30 ], 'yield() in when { } in given';
113 # But calling yield() in when() in for() sends us at the next iteration.
116 use feature 'switch';
135 is $@, '', 'yield() in for { } in given did not croak';
136 is $loop, 33, 'yield() exited for on the second iteration';
137 # A loop exited by last() evaluates to an empty list, but a loop that reached
138 # its natural end evaluates to false!
139 is_deeply \@res, [ 31, '', 37 ], 'yield() in when { }';