6 use Test::More tests => 33;
8 use Scope::Upper qw<yield HERE SCOPE SUB>;
12 # --- Void to void ------------------------------------------------------------
16 yield(qw<a b c> => HERE);
19 ok $res, 'yield in void context at sub to void';
24 yield(qw<d e f> => SCOPE(1));
28 ok $res, 'yield in void context at sub across eval to void';
33 yield qw<g h i> => SCOPE(1);
37 ok $res, 'yield in void context at sub across loop to void';
39 # --- Void to scalar ----------------------------------------------------------
42 yield(qw<a b c> => HERE);
45 is $res, 'c', 'yield in void context at sub to scalar';
49 yield qw<d e f> => SCOPE(1);
53 is $res, 'f', 'yield in void context at sub across eval to scalar';
57 yield qw<g h i> => SCOPE(1);
60 is $res, 'i', 'yield in void context at sub across loop to scalar';
63 for (6, yield qw<j k l> => SCOPE(0)) {
68 is $res, 'l', 'yield in void context at sub across loop iterator to scalar';
70 # --- Void to list ------------------------------------------------------------
73 yield qw<a b c> => HERE;
76 is_deeply \@res, [ qw<a b c> ], 'yield in void context at sub to list';
80 yield qw<d e f> => SCOPE(1);
84 is_deeply \@res, [ qw<d e f> ], 'yield in void context at sub across eval to list';
88 yield qw<g h i> => SCOPE(1);
91 is_deeply \@res, [ qw<g h i> ], 'yield in void context at sub across loop to list';
93 # --- Scalar to void ----------------------------------------------------------
97 my $temp = yield(qw<a b c> => HERE);
100 ok $res, 'yield in scalar context at sub to void';
105 yield(qw<d e f> => SCOPE(1));
109 ok $res, 'yield in scalar context at sub across eval to void';
114 my $temp = (yield qw<g h i> => SCOPE(1));
118 ok $res, 'yield in scalar context at sub across loop to void';
122 if (yield qw<m n o> => SCOPE(0)) {
127 ok $res, 'yield in scalar context at sub across test to void';
129 # --- Scalar to scalar --------------------------------------------------------
132 1, yield(qw<a b c> => HERE);
134 is $res, 'c', 'yield in scalar context at sub to scalar';
138 8, yield qw<d e f> => SCOPE(1);
141 is $res, 'f', 'yield in scalar context at sub across eval to scalar';
144 if (yield qw<m n o> => SCOPE(0)) {
148 is $res, 'o', 'yield in scalar context at sub across test to scalar';
150 # --- Scalar to list ----------------------------------------------------------
153 if (yield qw<m n o> => SCOPE(0)) {
157 is_deeply \@res, [ qw<m n o> ], 'yield in scalar context at sub across test to list';
159 # --- List to void ------------------------------------------------------------
163 my @temp = yield(qw<a b c> => HERE);
166 ok $res, 'yield in list context at sub to void';
171 yield(qw<d e f> => SCOPE(1));
175 ok $res, 'yield in list context at sub across eval to void';
180 my @temp = (yield qw<g h i> => SCOPE(1));
184 ok $res, 'yield in list context at sub across loop to void';
188 for (6, yield qw<j k l> => SCOPE(0)) {
193 ok $res, 'yield in list context at sub across test to void';
195 # --- List to scalar ----------------------------------------------------------
198 my @temp = (1, yield(qw<a b c> => HERE));
201 is $res, 'c', 'yield in list context at sub to scalar';
205 8, yield qw<d e f> => SCOPE(1);
209 is $res, 'f', 'yield in list context at sub across eval to scalar';
213 my @temp = (7, yield qw<g h i> => SCOPE(1));
217 is $res, 'i', 'yield in list context at sub across loop to scalar';
220 for (6, yield qw<j k l> => SCOPE(0)) {
224 is $res, 'l', 'yield in list context at sub across loop iterator to scalar';
226 # --- List to list ------------------------------------------------------------
229 2, yield qw<a b c> => HERE;
231 is_deeply \@res, [ qw<a b c> ], 'yield in list context at sub to list';
235 8, yield qw<d e f> => SCOPE(1);
238 is_deeply \@res, [ qw<d e f> ], 'yield in list context at sub across eval to list';
241 for (6, yield qw<j k l> => SCOPE(0)) {
245 is_deeply \@res, [ qw<j k l> ], 'yield in list context at sub across loop iterator to list';
247 # --- Prototypes --------------------------------------------------------------
249 sub pie { 7, yield qw<pie good>, $_[0] => SUB }
251 sub wlist (@) { return @_ }
254 is $res, 3, 'yield to list prototype to scalar';
257 is_deeply \@res, [ qw<pie good 2> ], 'yield to list prototype to list';
259 sub wscalar ($$) { return @_ }
261 $res = wscalar pie(6), pie(7);
262 is $res, 2, 'yield to scalar prototype to scalar';
264 @res = wscalar pie(8), pie(9);
265 is_deeply \@res, [ 8, 9 ], 'yield to scalar prototype to list';