11 no warnings 'experimental::smartmatch';
15 # The behaviour of the feature pragma should be tested by lib/feature.t
16 # using the tests in t/lib/feature/*. This file tests the behaviour of
17 # the switch ops themselves.
20 # Before loading feature, test the switch ops with CORE::
22 CORE::when(3) { pass "CORE::given and CORE::when"; continue }
23 CORE::default { pass "continue (without feature) and CORE::default" }
30 like($@, qr/^Can't "continue" outside/, "continue outside");
33 like($@, qr/^Can't "break" outside/, "break outside");
39 given(my $x = "bar") {
40 is($x, "bar", "given scope starts");
42 is($x, "foo", "given scope ends");
47 given(my $x = "foo") {
48 when(be_true(my $x = "bar")) {
49 is($x, "bar", "given scope starts");
51 is($x, "foo", "given scope ends");
55 given("inside") { check_outside1() }
56 sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
59 no warnings 'experimental::lexical_topic';
61 given("inside") { check_outside2() }
63 is($_, "outside", "\$_ lexically scoped (lexical \$_)")
67 # Basic string/numeric comparisons and control flow
72 when(2) { $ok = 'two'; }
73 when(3) { $ok = 'three'; }
74 when(4) { $ok = 'four'; }
75 default { $ok = 'd'; }
77 is($ok, 'three', "numeric comparison");
84 when(2) { $ok = 'two'; }
85 when(3) { $ok = 'three'; }
86 when(4) { $ok = 'four'; }
87 default { $ok = 'd'; }
89 is($ok, 'three', "integer comparison");
95 when(3.1) { $ok1 = 'n'; }
96 when(3.0) { $ok1 = 'y'; continue }
97 when("3.0") { $ok2 = 'y'; }
98 default { $ok2 = 'n'; }
100 is($ok1, 'y', "more numeric (pt. 1)");
101 is($ok2, 'y', "more numeric (pt. 2)");
107 when("b") { $ok = 'B'; }
108 when("c") { $ok = 'C'; }
109 when("d") { $ok = 'D'; }
110 default { $ok = 'def'; }
112 is($ok, 'C', "string comparison");
118 when("b") { $ok = 'B'; }
119 when("c") { $ok = 'C'; continue }
120 when("c") { $ok = 'CC'; }
121 default { $ok = 'D'; }
123 is($ok, 'CC', "simple continue");
129 given (0) { when(undef) {$ok = 0} }
130 is($ok, 1, "Given(0) when(undef)");
135 given (0) { when($undef) {$ok = 0} }
136 is($ok, 1, 'Given(0) when($undef)');
141 given (0) { when($undef++) {$ok = 1} }
142 is($ok, 1, "Given(0) when($undef++)");
145 no warnings "uninitialized";
147 given (undef) { when(0) {$ok = 0} }
148 is($ok, 1, "Given(undef) when(0)");
151 no warnings "uninitialized";
154 given ($undef) { when(0) {$ok = 0} }
155 is($ok, 1, 'Given($undef) when(0)');
160 given ("") { when(undef) {$ok = 0} }
161 is($ok, 1, 'Given("") when(undef)');
166 given ("") { when($undef) {$ok = 0} }
167 is($ok, 1, 'Given("") when($undef)');
170 no warnings "uninitialized";
172 given (undef) { when("") {$ok = 0} }
173 is($ok, 1, 'Given(undef) when("")');
176 no warnings "uninitialized";
179 given ($undef) { when("") {$ok = 0} }
180 is($ok, 1, 'Given($undef) when("")');
185 given (undef) { when(undef) {$ok = 1} }
186 is($ok, 1, "Given(undef) when(undef)");
191 given (undef) { when($undef) {$ok = 1} }
192 is($ok, 1, 'Given(undef) when($undef)');
197 given ($undef) { when(undef) {$ok = 1} }
198 is($ok, 1, 'Given($undef) when(undef)');
203 given ($undef) { when($undef) {$ok = 1} }
204 is($ok, 1, 'Given($undef) when($undef)');
208 # Regular expressions
211 given("Hello, world!") {
213 { $ok1 = 'y'; continue}
215 { $ok1 = 'n'; continue}
216 when(/^(Hello,|Goodbye cruel) world[!.?]/)
217 { $ok2 = 'Y'; continue}
218 when(/^(Hello cruel|Goodbye,) world[!.?]/)
219 { $ok2 = 'n'; continue}
221 is($ok1, 'y', "regex 1");
222 is($ok2, 'Y', "regex 2");
227 my $test = "explicit numeric comparison (<)";
228 my $twenty_five = 25;
230 given($twenty_five) {
231 when ($_ < 10) { $ok = "ten" }
232 when ($_ < 20) { $ok = "twenty" }
233 when ($_ < 30) { $ok = "thirty" }
234 when ($_ < 40) { $ok = "forty" }
235 default { $ok = "default" }
237 is($ok, "thirty", $test);
242 my $test = "explicit numeric comparison (integer <)";
243 my $twenty_five = 25;
245 given($twenty_five) {
246 when ($_ < 10) { $ok = "ten" }
247 when ($_ < 20) { $ok = "twenty" }
248 when ($_ < 30) { $ok = "thirty" }
249 when ($_ < 40) { $ok = "forty" }
250 default { $ok = "default" }
252 is($ok, "thirty", $test);
256 my $test = "explicit numeric comparison (<=)";
257 my $twenty_five = 25;
259 given($twenty_five) {
260 when ($_ <= 10) { $ok = "ten" }
261 when ($_ <= 20) { $ok = "twenty" }
262 when ($_ <= 30) { $ok = "thirty" }
263 when ($_ <= 40) { $ok = "forty" }
264 default { $ok = "default" }
266 is($ok, "thirty", $test);
271 my $test = "explicit numeric comparison (integer <=)";
272 my $twenty_five = 25;
274 given($twenty_five) {
275 when ($_ <= 10) { $ok = "ten" }
276 when ($_ <= 20) { $ok = "twenty" }
277 when ($_ <= 30) { $ok = "thirty" }
278 when ($_ <= 40) { $ok = "forty" }
279 default { $ok = "default" }
281 is($ok, "thirty", $test);
286 my $test = "explicit numeric comparison (>)";
287 my $twenty_five = 25;
289 given($twenty_five) {
290 when ($_ > 40) { $ok = "forty" }
291 when ($_ > 30) { $ok = "thirty" }
292 when ($_ > 20) { $ok = "twenty" }
293 when ($_ > 10) { $ok = "ten" }
294 default { $ok = "default" }
296 is($ok, "twenty", $test);
300 my $test = "explicit numeric comparison (>=)";
301 my $twenty_five = 25;
303 given($twenty_five) {
304 when ($_ >= 40) { $ok = "forty" }
305 when ($_ >= 30) { $ok = "thirty" }
306 when ($_ >= 20) { $ok = "twenty" }
307 when ($_ >= 10) { $ok = "ten" }
308 default { $ok = "default" }
310 is($ok, "twenty", $test);
315 my $test = "explicit numeric comparison (integer >)";
316 my $twenty_five = 25;
318 given($twenty_five) {
319 when ($_ > 40) { $ok = "forty" }
320 when ($_ > 30) { $ok = "thirty" }
321 when ($_ > 20) { $ok = "twenty" }
322 when ($_ > 10) { $ok = "ten" }
323 default { $ok = "default" }
325 is($ok, "twenty", $test);
330 my $test = "explicit numeric comparison (integer >=)";
331 my $twenty_five = 25;
333 given($twenty_five) {
334 when ($_ >= 40) { $ok = "forty" }
335 when ($_ >= 30) { $ok = "thirty" }
336 when ($_ >= 20) { $ok = "twenty" }
337 when ($_ >= 10) { $ok = "ten" }
338 default { $ok = "default" }
340 is($ok, "twenty", $test);
345 my $test = "explicit string comparison (lt)";
346 my $twenty_five = "25";
348 given($twenty_five) {
349 when ($_ lt "10") { $ok = "ten" }
350 when ($_ lt "20") { $ok = "twenty" }
351 when ($_ lt "30") { $ok = "thirty" }
352 when ($_ lt "40") { $ok = "forty" }
353 default { $ok = "default" }
355 is($ok, "thirty", $test);
359 my $test = "explicit string comparison (le)";
360 my $twenty_five = "25";
362 given($twenty_five) {
363 when ($_ le "10") { $ok = "ten" }
364 when ($_ le "20") { $ok = "twenty" }
365 when ($_ le "30") { $ok = "thirty" }
366 when ($_ le "40") { $ok = "forty" }
367 default { $ok = "default" }
369 is($ok, "thirty", $test);
373 my $test = "explicit string comparison (gt)";
374 my $twenty_five = 25;
376 given($twenty_five) {
377 when ($_ ge "40") { $ok = "forty" }
378 when ($_ ge "30") { $ok = "thirty" }
379 when ($_ ge "20") { $ok = "twenty" }
380 when ($_ ge "10") { $ok = "ten" }
381 default { $ok = "default" }
383 is($ok, "twenty", $test);
387 my $test = "explicit string comparison (ge)";
388 my $twenty_five = 25;
390 given($twenty_five) {
391 when ($_ ge "40") { $ok = "forty" }
392 when ($_ ge "30") { $ok = "thirty" }
393 when ($_ ge "20") { $ok = "twenty" }
394 when ($_ ge "10") { $ok = "ten" }
395 default { $ok = "default" }
397 is($ok, "twenty", $test);
400 # Make sure it still works with a lexical $_:
402 no warnings 'experimental::lexical_topic';
404 my $test = "explicit comparison with lexical \$_";
405 my $twenty_five = 25;
407 given($twenty_five) {
408 when ($_ ge "40") { $ok = "forty" }
409 when ($_ ge "30") { $ok = "thirty" }
410 when ($_ ge "20") { $ok = "twenty" }
411 when ($_ ge "10") { $ok = "ten" }
412 default { $ok = "default" }
414 is($ok, "twenty", $test);
417 # Optimized-away comparisons
421 when (2 + 2 == 4) { $ok = 'y'; continue }
422 when (2 + 2 == 5) { $ok = 'n' }
424 is($ok, 'y', "Optimized-away comparison");
430 when (scalar 24) { $ok = 'n'; continue }
431 default { $ok = 'y' }
433 is($ok,'y','scalar()');
437 # (How to be both thorough and portable? Pinch a few ideas
438 # from t/op/filetest.t. We err on the side of portability for
442 my ($ok_d, $ok_f, $ok_r);
444 when(-d) {$ok_d = 1; continue}
445 when(!-f) {$ok_f = 1; continue}
446 when(-r) {$ok_r = 1; continue}
448 ok($ok_d, "Filetest -d");
449 ok($ok_f, "Filetest -f");
450 ok($ok_r, "Filetest -r");
453 # Sub and method calls
458 when(notfoo()) {$ok = 1}
460 ok($ok, "Sub call acts as boolean")
466 when(main->notfoo()) {$ok = 1}
468 ok($ok, "Class-method call acts as boolean")
475 when($obj->notfoo()) {$ok = 1}
477 ok($ok, "Object-method call acts as boolean")
480 # Other things that should not be smart matched
484 when( /(\d+)/ and ( 1 <= $1 and $1 <= 12 ) ) {
488 ok($ok, "bool not smartmatches");
498 ok($ok, "eof() not smartmatched");
503 my %foo = ("bar", 0);
505 when(exists $foo{bar}) {
509 ok($ok, "exists() not smartmatched");
519 ok($ok, "defined() not smartmatched");
525 when((1 == 1) && "bar") {
528 when((1 == 1) && $_ eq "foo") {
532 is($ok, 2, "((1 == 1) && \"bar\") not smartmatched");
537 for my $l (qw(a b c d)) {
539 when ($_ eq "b" .. $_ eq "c") { $n = 1 }
542 ok(($n xor $l =~ /[ad]/), 'when(E1..E2) evaluates in boolean context');
548 for my $l (qw(a b c d)) {
550 when ($_ eq "b" ... $_ eq "c") { $n = 1 }
553 ok(($n xor $l =~ /[ad]/), 'when(E1...E2) evaluates in boolean context');
560 when((1 == $ok) || "foo") {
564 ok($ok, '((1 == $ok) || "foo") smartmatched');
570 when((1 == $ok || undef) // "foo") {
574 ok($ok, '((1 == $ok || undef) // "foo") smartmatched');
577 # Make sure we aren't invoking the get-magic more than once
579 { # A helper class to count the number of accesses.
580 package FetchCounter;
583 bless {value => undef, count => 0}, $class;
586 my ($self, $val) = @_;
588 $self->{value} = $val;
592 # Avoid pre/post increment here
593 $self->{count} = 1 + $self->{count};
602 my $f = tie my $v, "FetchCounter";
604 { my $test_name = "Multiple FETCHes in given, due to aliasing";
614 is($ok, 1, "precheck: $test_name");
615 is($f->count(), 4, $test_name);
618 { my $test_name = "Only one FETCH (numeric when)";
621 is($f->count(), 0, "Sanity check: $test_name");
630 is($ok, 1, "precheck: $test_name");
631 is($f->count(), 1, $test_name);
634 { my $test_name = "Only one FETCH (string when)";
637 is($f->count(), 0, "Sanity check: $test_name");
646 is($ok, 1, "precheck: $test_name");
647 is($f->count(), 1, $test_name);
650 { my $test_name = "Only one FETCH (undef)";
653 is($f->count(), 0, "Sanity check: $test_name");
654 no warnings "uninitialized";
660 when(undef) {$ok = 0}
662 is($ok, 1, "precheck: $test_name");
663 is($f->count(), 1, $test_name);
671 is($first, 0, "Loop: second");
673 like($@, qr/^Can't "break" in a loop topicalizer/,
674 q{Can't "break" in a loop topicalizer});
677 is($first, 1, "Loop: first");
679 # Implicit break is okay
688 is($first, 0, "Explicit \$_: second");
690 like($@, qr/^Can't "break" in a loop topicalizer/,
691 q{Can't "break" in a loop topicalizer});
694 is($first, 1, "Explicit \$_: first");
696 # Implicit break is okay
703 no warnings 'experimental::lexical_topic';
707 is($first, 0, "Implicitly lexical loop: second");
709 like($@, qr/^Can't "break" in a loop topicalizer/,
710 q{Can't "break" in a loop topicalizer});
713 is($first, 1, "Implicitly lexical loop: first");
715 # Implicit break is okay
722 no warnings 'experimental::lexical_topic';
726 is($first, 0, "Implicitly lexical, explicit \$_: second");
728 like($@, qr/^Can't "break" in a loop topicalizer/,
729 q{Can't "break" in a loop topicalizer});
732 is($first, 1, "Implicitly lexical, explicit \$_: first");
734 # Implicit break is okay
741 no warnings 'experimental::lexical_topic';
742 for my $_ (1, "two") {
744 is($first, 0, "Lexical loop: second");
746 like($@, qr/^Can't "break" in a loop topicalizer/,
747 q{Can't "break" in a loop topicalizer});
750 is($first, 1, "Lexical loop: first");
752 # Implicit break is okay
761 sub foo {$called_foo = 1; "@_" eq "foo"}
763 sub bar {$called_bar = 1; "@_" eq "bar"}
764 my ($matched_foo, $matched_bar) = (0, 0);
766 when(\&bar) {$matched_bar = 1}
767 when(\&foo) {$matched_foo = 1}
769 is($called_foo, 1, "foo() was called");
770 is($called_bar, 1, "bar() was called");
771 is($matched_bar, 0, "bar didn't match");
772 is($matched_foo, 1, "foo did match");
780 my ($ok1, $ok2) = (0,0);
783 { $ok1 = 1; continue }
785 { $ok2 = 1; continue }
787 is($ok1, 1, "Calling sub directly (true)");
788 is($ok2, 1, "Calling sub indirectly (true)");
792 { $ok1 = 2; continue }
794 { $ok2 = 2; continue }
796 is($ok1, 1, "Calling sub directly (false)");
797 is($ok2, 1, "Calling sub indirectly (false)");
801 skip_if_miniperl("no dynamic loading on miniperl, no Scalar::Util", 14);
803 { package OverloadTest;
805 use overload '""' => sub{"string value of obj"};
806 use overload 'eq' => sub{"$_[0]" eq "$_[1]"};
808 use overload "~~" => sub {
809 my ($self, $other, $reversed) = @_;
811 $self->{left} = $other;
812 $self->{right} = $self;
813 $self->{reversed} = 1;
815 $self->{left} = $self;
816 $self->{right} = $other;
817 $self->{reversed} = 0;
820 return $self->{retval};
824 my ($pkg, $retval) = @_;
833 my $test = "Overloaded obj in given (true)";
834 my $obj = OverloadTest->new(1);
837 when ("other arg") {$matched = 1}
838 default {$matched = 0}
841 is($obj->{called}, 1, "$test: called");
842 ok($matched, "$test: matched");
846 my $test = "Overloaded obj in given (false)";
847 my $obj = OverloadTest->new(0);
850 when ("other arg") {$matched = 1}
853 is($obj->{called}, 1, "$test: called");
854 ok(!$matched, "$test: not matched");
858 my $test = "Overloaded obj in when (true)";
859 my $obj = OverloadTest->new(1);
862 when ($obj) {$matched = 1}
863 default {$matched = 0}
866 is($obj->{called}, 1, "$test: called");
867 ok($matched, "$test: matched");
868 is($obj->{left}, "topic", "$test: left");
869 is($obj->{right}, "string value of obj", "$test: right");
870 ok($obj->{reversed}, "$test: reversed");
874 my $test = "Overloaded obj in when (false)";
875 my $obj = OverloadTest->new(0);
878 when ($obj) {$matched = 1}
879 default {$matched = 0}
882 is($obj->{called}, 1, "$test: called");
883 ok(!$matched, "$test: not matched");
884 is($obj->{left}, "topic", "$test: left");
885 is($obj->{right}, "string value of obj", "$test: right");
886 ok($obj->{reversed}, "$test: reversed");
896 is($ok, 1, "postfix undef");
902 $ok += 2 when 9.1685;
903 $ok += 4 when $_ > 4;
904 $ok += 8 when $_ < 2.5;
906 is($ok, 8, "postfix numeric");
911 $ok = 1, continue when $_ eq "apple";
913 $ok = 0 when "banana";
915 is($ok, 3, "postfix string");
920 do { $ok = 1; continue } when /pea/;
926 is($ok, 7, "postfix regex");
928 # be_true is defined at the beginning of the file
931 given(my $x = "foo") {
933 is($x, "foo", "scope inside ... when my \$x = ...");
935 } when be_true(my $x = "bar");
936 is($x, "bar", "scope after ... when my \$x = ...");
942 my $x = 2, continue when be_true();
943 is($x, undef, "scope after my \$x = ... when ...");
947 # Tests for last and next in when clauses
958 is($letter, "b", "last in when");
961 LETTER1: for ("a".."e") {
964 when ("b") { last LETTER1 }
968 is($letter, "b", "last LABEL in when");
973 when (/b|d/) { next }
978 is($letter, "a,c,e,", "next in when");
981 LETTER2: for ("a".."e") {
983 when (/b|d/) { next LETTER2 }
988 is($letter, "a,c,e,", "next LABEL in when");
990 # Test goto with given/when
995 GIVEN1: given ($flag) {
999 is($flag, 0, "goto GIVEN1");
1004 when (0) { $flag = 1; }
1009 is($flag, 1, "goto inside given");
1014 when (0) { $flag = 1; goto GIVEN3; $flag = 2; }
1018 is($flag, 1, "goto inside given and when");
1023 when (0) { $flag = 1; goto GIVEN4; $flag = 2; }
1027 is($flag, 1, "goto inside for and when");
1033 when (0) { $flag = 1; goto GIVEN5; $flag = 2; }
1037 is($flag, 1, "goto inside given and when to the given stmt");
1040 # test with unreified @_ in smart match [perl #71078]
1041 sub unreified_check { ok([@_] ~~ \@_) } # should always match
1042 unreified_check(1,2,"lala");
1043 unreified_check(1,2,undef);
1044 unreified_check(undef);
1045 unreified_check(undef,"");
1047 # Test do { given } as a rvalue
1052 my @things = (11 .. 26); # 16 elements
1053 my @exp = (5, 16, 9);
1056 my $scalar = do { given ($_) {
1057 when (0) { $lexical }
1058 when (2) { 'void'; 8, 9 }
1061 is($scalar, shift(@exp), "rvalue given - simple scalar [$_]");
1067 my @exp = (5, 7, 9);
1070 my $scalar = do { given ($_) {
1075 is($scalar, shift(@exp), "rvalue given - postfix scalar [$_]");
1080 my @exp = (5, 9, 9);
1082 my $scalar = do { given ($_) {
1088 is($scalar, shift(@exp), "rvalue given - default scalar [$_]");
1093 my @things = (11 .. 13);
1094 my @exp = ('3 4 5', '11 12 13', '8 9');
1096 my @list = do { given ($_) {
1098 when (2) { my $fake = 'void'; 8, 9 }
1101 is("@list", shift(@exp), "rvalue given - simple list [$_]");
1107 my @exp = ('3 4 5', '6 7', '12');
1109 my @list = do { given ($_) {
1114 is("@list", shift(@exp), "rvalue given - postfix list [$_]");
1119 my @things = (11 .. 20); # 10 elements
1120 my @exp = ('m o o', '8 10', '8 10');
1122 my @list = do { given ($_) {
1123 when (0) { "moo" =~ /(.)/g }
1124 default { 8, scalar(@things) }
1127 is("@list", shift(@exp), "rvalue given - default list [$_]");
1132 my @exp = ('6 7', '', '6 7');
1134 my @list = do { given ($_) {
1135 continue when $_ <= 1;
1140 is("@list", shift(@exp), "rvalue given - default list [$_]");
1144 # Context propagation
1145 my $smart_hash = sub {
1146 do { given ($_[0]) {
1148 when ([ 1 .. 3 ]) { 1 .. 3 }
1149 when (4) { my $fake; do { 4, 5 } }
1155 $scalar = $smart_hash->();
1156 is($scalar, 'undef', "rvalue given - scalar context propagation [undef]");
1158 $scalar = $smart_hash->(4);
1159 is($scalar, 5, "rvalue given - scalar context propagation [4]");
1161 $scalar = $smart_hash->(999);
1162 is($scalar, undef, "rvalue given - scalar context propagation [999]");
1166 @list = $smart_hash->();
1167 is("@list", 'undef', "rvalue given - list context propagation [undef]");
1169 @list = $smart_hash->(2);
1170 is("@list", '1 2 3', "rvalue given - list context propagation [2]");
1172 @list = $smart_hash->(4);
1173 is("@list", '4 5', "rvalue given - list context propagation [4]");
1175 @list = $smart_hash->(999);
1176 is("@list", '', "rvalue given - list context propagation [999]");
1180 my @list = 10 .. 15;
1189 when (@list[0..2]) {
1194 is("@in_list", "10 15", "when(array)");
1195 is("@in_slice", "10", "when(array slice)");
1199 my %list = map { $_ => $_ } "a" .. "f";
1202 for ("a", "e", "i") {
1208 when (@list{"a".."c"}) {
1213 is("@in_list", "a e", "when(hash)");
1214 is("@in_slice", "a", "when(hash slice)");
1217 { # RT#84526 - Handle magical TARG
1218 my $x = my $y = "aaa";
1221 is(pos, undef, "handle magical TARG");
1227 # Test that returned values are correctly propagated through several context
1228 # levels (see RT #93548).
1235 our ($when_loc, $given_loc, $ext_loc);
1243 our $given_glob = 5;
1244 local $given_loc = 6;
1248 when (1) { my $when_lex = 1 }
1249 when (2) { our $when_glob = 2 }
1250 when (3) { local $when_loc = 3 }
1252 when (4) { $given_lex }
1253 when (5) { $given_glob }
1254 when (6) { $given_loc }
1256 when (7) { $ext_lex }
1257 when (8) { $ext_glob }
1258 when (9) { $ext_loc }
1264 my @descriptions = qw<
1280 for my $id (0 .. 9) {
1281 my $desc = $descriptions[$id];
1283 my $res = $tester->($id);
1284 is $res, $id, "plain call - $desc";
1287 my $id_plus_1 = $id + 1;
1288 given ($id_plus_1) {
1297 $tester->($id_plus_1);
1302 is $res, $id, "across continue and default - $desc";
1306 # Check that values returned from given/when are destroyed at the right time.
1323 my @descriptions = qw<
1330 for my $id (0 .. 3) {
1331 my $desc = $descriptions[$id];
1340 when (0) { Fmurrr->new($destroyed, 0) }
1341 when (1) { my $y = Fmurrr->new($destroyed, 1); break }
1342 when (2) { $x = Fmurrr->new($destroyed, 2); continue }
1344 default { Fmurrr->new($destroyed, 3) }
1347 $res_id = $res->{id};
1349 $res_id = $id if $id == 1; # break doesn't return anything
1351 is $res_id, $id, "given/when returns the right object - $desc";
1352 is $destroyed, 1, "given/when does not leak - $desc";
1356 # break() must reset the stack
1367 is "@res", "1", "break resets the stack";
1371 # must ensure $_ is initialised and cleared at start/end of given block
1375 no warnings 'experimental::lexical_topic';
1378 return sub { $_ } # close over lexical $_
1381 is(f1()->(), 3, 'closed over $_');
1386 sub DESTROY { $d++ };
1389 no warnings 'experimental::lexical_topic';
1392 ::is($_->[0], 7, "is [7]");
1394 ::is($_, 5, "is 5");
1395 ::is($d, 1, "DESTROY called once");
1402 # Okay, that'll do for now. The intricacies of the smartmatch
1403 # semantics are tested in t/op/smartmatch.t. Taintedness of
1404 # returned values is checked in t/op/taint.t.