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 () { ... }';
67 skip '"eval { $str =~ s/./die q[foo]/e }" breaks havoc on perl 5.8 and below'
72 $s =~ s/./yield; die 'not reached'/e;
75 my $line = __LINE__-3;
77 qr/^yield\(\) can't target a substitution context at \Q$0\E line $line/,
78 'yield() cannot exit subst';
82 skip 'perl 5.10 is required to test interaction with given/when' => 6
85 @res = eval <<'TESTCASE';
87 if ("$]" >= 5.017_011) {
89 warnings->unimport('experimental::smartmatch');
101 is_deeply \@res, [ 24, 27 ], 'yield() in given { }';
103 # Beware that calling yield() in when() in given() sends us directly at the
104 # end of the enclosing given block.
108 if ("$]" >= 5.017_011) {
110 warnings->unimport('experimental::smartmatch');
113 use feature 'switch';
124 is $@, '', 'yield() in when { } in given did not croak';
125 is_deeply \@res, [ 28, 30 ], 'yield() in when { } in given';
127 # But calling yield() in when() in for() sends us at the next iteration.
131 if ("$]" >= 5.017_011) {
133 warnings->unimport('experimental::smartmatch');
136 use feature 'switch';
155 is $@, '', 'yield() in for { } in given did not croak';
156 is $loop, 33, 'yield() exited for on the second iteration';
157 # A loop exited by last() evaluates to an empty list, but a loop that reached
158 # its natural end evaluates to false!
159 is_deeply \@res, [ 31, '', 37 ], 'yield() in when { }';