11 plan tests => 11 + 1 * 2 + 5 * 3;
14 my $desc = 'peephole optimization of conditionals';
18 my $code = eval <<' TESTCASE';
24 } elsif ($_[1] || $_[2]) {
27 } elsif ($_[3] && $_[4]) {
30 } elsif ($_[5] ? $_[6] : 0) {
40 is $@, '', "$desc compiled fine";
43 is_deeply $x, undef, "$desc : first branch did not autovivify";
44 is $ret, 1, "$desc : first branch returned 1";
47 is_deeply $x, undef, "$desc : second branch did not autovivify";
48 is $ret, 2, "$desc : second branch returned 2";
50 $ret = $code->(0, 0, 0, 1, 1);
51 is_deeply $x, undef, "$desc : third branch did not autovivify";
52 is $ret, 3, "$desc : third branch returned 3";
54 $ret = $code->(0, 0, 0, 0, 0, 1, 1);
55 is_deeply $x, undef, "$desc : fourth branch did not autovivify";
56 is $ret, 4, "$desc : fourth branch returned 4";
59 is_deeply $x, undef, "$desc : fifth branch did not autovivify";
60 is $ret, 5, "$desc : fifth branch returned 5";
64 my $desc = 'peephole optimization of C-style loops';
68 my $code = eval <<' TESTCASE';
73 my ($z, $i) = ($x->[100], 0)
75 do { my $z = $x->[200]; $i < 4 }
77 do { my $z = $x->[300]; ++$i }
85 is $@, '', "$desc compiled fine";
88 is_deeply $x, undef, "$desc did not autovivify";
89 is $ret, 6, "$desc returned 0+1+2+3";
93 my $desc = 'peephole optimization of range loops';
97 my $code = eval <<' TESTCASE';
101 for ((do { my $z = $x->[100]; 0 }) .. (do { my $z = $x->[200]; 3 })) {
108 is $@, '', "$desc compiled fine";
111 is_deeply $x, undef, "$desc did not autovivify";
112 is $ret, 6, "$desc returned 0+1+2+3";
116 my %infinite_tests = (
117 'peephole optimization of infinite for loops (RT #64435)' => <<' TESTCASE',
128 for my $desc (keys %infinite_tests) {
129 my $code = $infinite_tests{$desc};
130 my $ret = run_perl $code;
131 my $stat = $ret & 255;
133 is $stat, 0, "$desc testcase did not crash";
134 is $ret, 1, "$desc compiled fine";
139 my $desc = 'peephole optimization of map';
143 my $code = eval <<' TESTCASE';
152 is $@, '', "$desc compiled fine";
154 my $ret = $code->(1, 2);
155 is_deeply $x, undef, "$desc did not autovivify";
156 is $ret, 'x1y:x2y', "$desc returned the right value";
160 my $desc = 'peephole optimization of grep';
164 my $code = eval <<' TESTCASE';
173 is $@, '', "$desc compiled fine";
175 my $ret = $code->(1 .. 5);
176 is_deeply $x, undef, "$desc did not autovivify";
177 is $ret, '1:2:3', "$desc returned the right value";
181 my $desc = 'peephole optimization of substitutions';
185 my $code = eval <<' TESTCASE';
198 is $@, '', "$desc compiled fine";
200 my $ret = $code->('0123456789');
201 is_deeply $x, undef, "$desc did not autovivify";
202 is $ret, '9876543210', "$desc returned the right value";