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
84 skip 'Not testing deprecated given/when on Perl 5.37.10 or later'
85 => 6 if "$]" >= 5.037010;
87 @res = eval <<'TESTCASE';
89 if ("$]" >= 5.017_011) {
91 warnings->unimport('experimental::smartmatch');
103 is_deeply \@res, [ 24, 27 ], 'yield() in given { }';
105 # Beware that calling yield() in when() in given() sends us directly at the
106 # end of the enclosing given block.
110 if ("$]" >= 5.017_011) {
112 warnings->unimport('experimental::smartmatch');
115 use feature 'switch';
126 is $@, '', 'yield() in when { } in given did not croak';
127 is_deeply \@res, [ 28, 30 ], 'yield() in when { } in given';
129 # But calling yield() in when() in for() sends us at the next iteration.
133 if ("$]" >= 5.017_011) {
135 warnings->unimport('experimental::smartmatch');
138 use feature 'switch';
157 is $@, '', 'yield() in for { } in given did not croak';
158 is $loop, 33, 'yield() exited for on the second iteration';
159 # A loop exited by last() evaluates to an empty list, but a loop that reached
160 # its natural end evaluates to false!
161 is_deeply \@res, [ 31, '', 37 ], 'yield() in when { }';