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