This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Correct a bug in the previous commit (bb35dd48)
[perl5.git] / dist / B-Deparse / t / deparse.t
CommitLineData
87a42246
MS
1#!./perl
2
3BEGIN {
62a6bb71 4 unshift @INC, 't';
9cd8f857
NC
5 require Config;
6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
8 exit 0;
9 }
87a42246
MS
10}
11
87a42246
MS
12use warnings;
13use strict;
e9c69003 14BEGIN {
c4a6f826 15 # BEGIN block is actually a subroutine :-)
e9c69003
NC
16 return unless $] > 5.009;
17 require feature;
18 feature->import(':5.10');
19}
507a68aa 20use Test::More;
1bb3cfc5 21use Config ();
87a42246
MS
22
23use B::Deparse;
09d856fb 24my $deparse = B::Deparse->new();
507a68aa 25isa_ok($deparse, 'B::Deparse', 'instantiate a B::Deparse object');
87a42246
MS
26
27# Tell B::Deparse about our ambient pragmas
0ced6c29
RGS
28{ my ($hint_bits, $warning_bits, $hinthash);
29 BEGIN { ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H); }
87a42246
MS
30 $deparse->ambient_pragmas (
31 hint_bits => $hint_bits,
32 warning_bits => $warning_bits,
0ced6c29 33 '%^H' => $hinthash,
87a42246
MS
34 );
35}
36
ad46c0be
RH
37$/ = "\n####\n";
38while (<DATA>) {
39 chomp;
e9c69003
NC
40 # This code is pinched from the t/lib/common.pl for TODO.
41 # It's not clear how to avoid duplication
b871937f
NC
42 # Now tweaked a bit to do skip or todo
43 my %reason;
44 foreach my $what (qw(skip todo)) {
45 s/^#\s*\U$what\E\s*(.*)\n//m and $reason{$what} = $1;
46 # If the SKIP reason starts ? then it's taken as a code snippet to
47 # evaluate. This provides the flexibility to have conditional SKIPs
48 if ($reason{$what} && $reason{$what} =~ s/^\?//) {
49 my $temp = eval $reason{$what};
50 if ($@) {
51 die "# In \U$what\E code reason:\n# $reason{$what}\n$@";
52 }
53 $reason{$what} = $temp;
e9c69003 54 }
e9c69003
NC
55 }
56
4a4b8592 57 s/^\s*#\s*(.*)$//mg;
507a68aa
NC
58 my $desc = $1;
59 die "Missing name in test $_" unless defined $desc;
e9c69003 60
b871937f 61 if ($reason{skip}) {
e9c69003 62 # Like this to avoid needing a label SKIP:
b871937f 63 Test::More->builder->skip($reason{skip});
e9c69003
NC
64 next;
65 }
66
ad46c0be
RH
67 my ($input, $expected);
68 if (/(.*)\n>>>>\n(.*)/s) {
69 ($input, $expected) = ($1, $2);
70 }
71 else {
72 ($input, $expected) = ($_, $_);
73 }
87a42246 74
ad46c0be 75 my $coderef = eval "sub {$input}";
87a42246 76
ad46c0be 77 if ($@) {
507a68aa 78 is($@, "", "compilation of $desc");
ad46c0be
RH
79 }
80 else {
81 my $deparsed = $deparse->coderef2text( $coderef );
31c6271a
RD
82 my $regex = $expected;
83 $regex =~ s/(\S+)/\Q$1/g;
84 $regex =~ s/\s+/\\s+/g;
85 $regex = '^\{\s*' . $regex . '\s*\}$';
b871937f 86
4a4b8592 87 local $::TODO = $reason{todo};
507a68aa 88 like($deparsed, qr/$regex/, $desc);
87a42246 89 }
87a42246
MS
90}
91
87a42246 92use constant 'c', 'stuff';
507a68aa
NC
93is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
94 'the subroutine generated by use constant deparses');
87a42246 95
09d856fb 96my $a = 0;
507a68aa
NC
97is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
98 'anon sub capturing an external lexical');
87a42246 99
d989cdac
SM
100use constant cr => ['hello'];
101my $string = "sub " . $deparse->coderef2text(\&cr);
0707d6cc 102my $val = (eval $string)->() or diag $string;
507a68aa
NC
103is(ref($val), 'ARRAY', 'constant array references deparse');
104is($val->[0], 'hello', 'and return the correct value');
87a42246 105
87a42246 106my $path = join " ", map { qq["-I$_"] } @INC;
87a42246 107
7cde0a5f 108$a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
e69a2255 109$a =~ s/-e syntax OK\n//g;
d2bc402e 110$a =~ s/.*possible typo.*\n//; # Remove warning line
87a42246
MS
111$a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037
112$a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc'
113$b = <<'EOF';
d2bc402e
RGS
114BEGIN { $^I = ".bak"; }
115BEGIN { $^W = 1; }
116BEGIN { $/ = "\n"; $\ = "\n"; }
87a42246
MS
117LINE: while (defined($_ = <ARGV>)) {
118 chomp $_;
f86ea535 119 our(@F) = split(' ', $_, 0);
87a42246
MS
120 '???';
121}
87a42246 122EOF
507a68aa
NC
123is($a, $b,
124 'command line flags deparse as BEGIN blocks setting control variables');
87a42246 125
5b4ee549
NC
126$a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
127$a =~ s/-e syntax OK\n//g;
128is($a, "use constant ('PI', 4);\n",
129 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
130
579a54dc 131#Re: perlbug #35857, patch #24505
b3980c39
YO
132#handle warnings::register-ed packages properly.
133package B::Deparse::Wrapper;
134use strict;
135use warnings;
136use warnings::register;
137sub getcode {
579a54dc 138 my $deparser = B::Deparse->new();
b3980c39
YO
139 return $deparser->coderef2text(shift);
140}
141
2990415a
FR
142package Moo;
143use overload '0+' => sub { 42 };
144
b3980c39
YO
145package main;
146use strict;
147use warnings;
71c4dbc3 148use constant GLIPP => 'glipp';
2990415a
FR
149use constant PI => 4;
150use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
3779476a 151use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
aaf9c2b2 152BEGIN { delete $::Fcntl::{O_APPEND}; }
2990415a 153use POSIX qw/O_CREAT/;
b3980c39 154sub test {
579a54dc
RGS
155 my $val = shift;
156 my $res = B::Deparse::Wrapper::getcode($val);
507a68aa
NC
157 like($res, qr/use warnings/,
158 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
b3980c39
YO
159}
160my ($q,$p);
161my $x=sub { ++$q,++$p };
162test($x);
163eval <<EOFCODE and test($x);
164 package bar;
165 use strict;
166 use warnings;
167 use warnings::register;
168 package main;
169 1
170EOFCODE
171
d1dc589d
FC
172# Exotic sub declarations
173$a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
174$a =~ s/-e syntax OK\n//g;
175is($a, <<'EOCODG', "sub :::: and sub ::::::");
176sub :::: {
177
178}
179sub :::::: {
180
181}
182EOCODG
183
640d5d41
FC
184# [perl #33752]
185{
186 my $code = <<"EOCODE";
187{
188 our \$\x{1e1f}\x{14d}\x{14d};
189}
190EOCODE
191 my $deparsed
192 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
193 s/$ \n//x for $deparsed, $code;
194 is $deparsed, $code, 'our $funny_Unicode_chars';
195}
196
bdabb2d5
FC
197# [perl #62500]
198$a =
199 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
200$a =~ s/-e syntax OK\n//g;
201is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
202sub BEGIN {
203 *CORE::GLOBAL::require = sub {
204 1;
205 }
206 ;
207}
208EOCODF
209
bb8996b8 210# [perl #93990]
5c19ffe6 211@* = ();
bb8996b8
HY
212is($deparse->coderef2text(sub{ print "@{*}" }),
213q<{
214 print "@{*}";
215}>, 'curly around to interpolate "@{*}"');
216is($deparse->coderef2text(sub{ print "@{-}" }),
217q<{
218 print "@-";
219}>, 'no need to curly around to interpolate "@-"');
220
507a68aa
NC
221done_testing();
222
ad46c0be 223__DATA__
507a68aa 224# A constant
ad46c0be
RH
2251;
226####
507a68aa 227# Constants in a block
ad46c0be
RH
228{
229 no warnings;
230 '???';
231 2;
232}
233####
507a68aa 234# Lexical and simple arithmetic
ad46c0be
RH
235my $test;
236++$test and $test /= 2;
237>>>>
238my $test;
239$test /= 2 if ++$test;
240####
507a68aa 241# list x
ad46c0be
RH
242-((1, 2) x 2);
243####
507a68aa 244# lvalue sub
ad46c0be
RH
245{
246 my $test = sub : lvalue {
247 my $x;
248 }
249 ;
250}
251####
507a68aa 252# method
ad46c0be
RH
253{
254 my $test = sub : method {
255 my $x;
256 }
257 ;
258}
259####
507a68aa 260# block with continue
87a42246 261{
ad46c0be 262 234;
f99a63a2 263}
ad46c0be
RH
264continue {
265 123;
87a42246 266}
ce4e655d 267####
507a68aa 268# lexical and package scalars
ce4e655d
RH
269my $x;
270print $main::x;
271####
507a68aa 272# lexical and package arrays
ce4e655d
RH
273my @x;
274print $main::x[1];
14a55f98 275####
507a68aa 276# lexical and package hashes
14a55f98
RH
277my %x;
278$x{warn()};
ad8caead 279####
507a68aa 280# <>
ad8caead
RGS
281my $foo;
282$_ .= <ARGV> . <$foo>;
cef22867 283####
507a68aa 284# \x{}
11454c59 285my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
4ae52e81 286####
507a68aa 287# s///e
4ae52e81 288s/x/'y';/e;
241416b8 289####
507a68aa 290# block
241416b8
DM
291{ my $x; }
292####
507a68aa 293# while 1
241416b8
DM
294while (1) { my $k; }
295####
507a68aa 296# trailing for
241416b8
DM
297my ($x,@a);
298$x=1 for @a;
299>>>>
300my($x, @a);
0bb5f065 301$x = 1 foreach (@a);
241416b8 302####
507a68aa 303# 2 arguments in a 3 argument for
241416b8
DM
304for (my $i = 0; $i < 2;) {
305 my $z = 1;
306}
307####
507a68aa 308# 3 argument for
241416b8
DM
309for (my $i = 0; $i < 2; ++$i) {
310 my $z = 1;
311}
312####
507a68aa 313# 3 argument for again
241416b8
DM
314for (my $i = 0; $i < 2; ++$i) {
315 my $z = 1;
316}
317####
507a68aa 318# while/continue
241416b8
DM
319my $i;
320while ($i) { my $z = 1; } continue { $i = 99; }
321####
507a68aa 322# foreach with my
09d856fb 323foreach my $i (1, 2) {
241416b8
DM
324 my $z = 1;
325}
326####
507a68aa 327# foreach
241416b8
DM
328my $i;
329foreach $i (1, 2) {
330 my $z = 1;
331}
332####
507a68aa 333# foreach, 2 mys
241416b8
DM
334my $i;
335foreach my $i (1, 2) {
336 my $z = 1;
337}
338####
507a68aa 339# foreach
241416b8
DM
340foreach my $i (1, 2) {
341 my $z = 1;
342}
343####
507a68aa 344# foreach with our
241416b8
DM
345foreach our $i (1, 2) {
346 my $z = 1;
347}
348####
507a68aa 349# foreach with my and our
241416b8
DM
350my $i;
351foreach our $i (1, 2) {
352 my $z = 1;
353}
3ac6e0f9 354####
507a68aa 355# reverse sort
3ac6e0f9
RGS
356my @x;
357print reverse sort(@x);
358####
507a68aa 359# sort with cmp
3ac6e0f9
RGS
360my @x;
361print((sort {$b cmp $a} @x));
362####
507a68aa 363# reverse sort with block
3ac6e0f9
RGS
364my @x;
365print((reverse sort {$b <=> $a} @x));
36d57d93 366####
507a68aa 367# foreach reverse
36d57d93
RGS
368our @a;
369print $_ foreach (reverse @a);
aae53c41 370####
507a68aa 371# foreach reverse (not inplace)
aae53c41
RGS
372our @a;
373print $_ foreach (reverse 1, 2..5);
f86ea535 374####
507a68aa 375# bug #38684
f86ea535
SM
376our @ary;
377@ary = split(' ', 'foo', 0);
31c6271a 378####
507a68aa 379# bug #40055
31c6271a
RD
380do { () };
381####
507a68aa 382# bug #40055
31c6271a 383do { my $x = 1; $x };
d9002312 384####
507a68aa 385# <20061012113037.GJ25805@c4.convolution.nl>
d9002312
SM
386my $f = sub {
387 +{[]};
388} ;
8b2d6640 389####
507a68aa 390# bug #43010
8b2d6640
FC
391'!@$%'->();
392####
507a68aa 393# bug #43010
8b2d6640
FC
394::();
395####
507a68aa 396# bug #43010
8b2d6640
FC
397'::::'->();
398####
507a68aa 399# bug #43010
8b2d6640 400&::::;
09d856fb 401####
507a68aa 402# variables as method names
09d856fb
CK
403my $bar;
404'Foo'->$bar('orz');
35a99a08 405'Foo'->$bar('orz') = 'a stranger stranger than before';
09d856fb 406####
507a68aa 407# constants as method names
09d856fb
CK
408'Foo'->bar('orz');
409####
507a68aa 410# constants as method names without ()
09d856fb 411'Foo'->bar;
0ced6c29 412####
1bf8bbb0
FC
413# "indirect" method call notation
414our @bar;
415foo{@bar}+1,->foo;
416(foo{@bar}+1),foo();
417foo{@bar}1 xor foo();
418>>>>
419our @bar;
420(foo { @bar } 1)->foo;
421(foo { @bar } 1), foo();
422foo { @bar } 1 xor foo();
423####
e9c69003 424# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
507a68aa 425# say
7ddd1a01
NC
426say 'foo';
427####
e9c69003 428# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
507a68aa 429# state vars
0ced6c29
RGS
430state $x = 42;
431####
e9c69003 432# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
507a68aa 433# state var assignment
7ddd1a01
NC
434{
435 my $y = (state $x = 42);
436}
437####
e9c69003 438# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
c4a6f826 439# state vars in anonymous subroutines
7ddd1a01
NC
440$a = sub {
441 state $x;
442 return $x++;
443}
444;
644741fd
NC
445####
446# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 447# each @array;
644741fd
NC
448each @ARGV;
449each @$a;
450####
451# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 452# keys @array; values @array
644741fd
NC
453keys @$a if keys @ARGV;
454values @ARGV if values @$a;
35925e80 455####
507a68aa 456# Anonymous arrays and hashes, and references to them
35925e80
RGS
457my $a = {};
458my $b = \{};
459my $c = [];
460my $d = \[];
9210de83
FR
461####
462# SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
507a68aa 463# implicit smartmatch in given/when
9210de83
FR
464given ('foo') {
465 when ('bar') { continue; }
466 when ($_ ~~ 'quux') { continue; }
467 default { 0; }
468}
7ecdd211 469####
507a68aa 470# conditions in elsifs (regression in change #33710 which fixed bug #37302)
7ecdd211
PJ
471if ($a) { x(); }
472elsif ($b) { x(); }
473elsif ($a and $b) { x(); }
474elsif ($a or $b) { x(); }
475else { x(); }
03b22f1b 476####
507a68aa 477# interpolation in regexps
03b22f1b
RGS
478my($y, $t);
479/x${y}z$t/;
227375e1 480####
4a4b8592 481# TODO new undocumented cpan-bug #33708
507a68aa 482# cpan-bug #33708
227375e1
RU
483%{$_ || {}}
484####
4a4b8592 485# TODO hash constants not yet fixed
507a68aa 486# cpan-bug #33708
227375e1
RU
487use constant H => { "#" => 1 }; H->{"#"}
488####
4a4b8592 489# TODO optimized away 0 not yet fixed
507a68aa 490# cpan-bug #33708
227375e1 491foreach my $i (@_) { 0 }
edbe35ea 492####
507a68aa 493# tests with not, not optimized
07f3cdf5 494my $c;
edbe35ea
VP
495x() unless $a;
496x() if not $a and $b;
497x() if $a and not $b;
498x() unless not $a and $b;
499x() unless $a and not $b;
500x() if not $a or $b;
501x() if $a or not $b;
502x() unless not $a or $b;
503x() unless $a or not $b;
07f3cdf5
VP
504x() if $a and not $b and $c;
505x() if not $a and $b and not $c;
506x() unless $a and not $b and $c;
507x() unless not $a and $b and not $c;
508x() if $a or not $b or $c;
509x() if not $a or $b or not $c;
510x() unless $a or not $b or $c;
511x() unless not $a or $b or not $c;
edbe35ea 512####
507a68aa 513# tests with not, optimized
07f3cdf5 514my $c;
edbe35ea
VP
515x() if not $a;
516x() unless not $a;
517x() if not $a and not $b;
518x() unless not $a and not $b;
519x() if not $a or not $b;
520x() unless not $a or not $b;
07f3cdf5
VP
521x() if not $a and not $b and $c;
522x() unless not $a and not $b and $c;
523x() if not $a or not $b or $c;
524x() unless not $a or not $b or $c;
525x() if not $a and not $b and not $c;
526x() unless not $a and not $b and not $c;
527x() if not $a or not $b or not $c;
528x() unless not $a or not $b or not $c;
529x() unless not $a or not $b or not $c;
edbe35ea 530>>>>
07f3cdf5 531my $c;
edbe35ea
VP
532x() unless $a;
533x() if $a;
534x() unless $a or $b;
535x() if $a or $b;
536x() unless $a and $b;
07f3cdf5
VP
537x() if $a and $b;
538x() if not $a || $b and $c;
539x() unless not $a || $b and $c;
540x() if not $a && $b or $c;
541x() unless not $a && $b or $c;
542x() unless $a or $b or $c;
543x() if $a or $b or $c;
544x() unless $a and $b and $c;
545x() if $a and $b and $c;
546x() unless not $a && $b && $c;
71c4dbc3 547####
507a68aa 548# tests that should be constant folded
71c4dbc3
VP
549x() if 1;
550x() if GLIPP;
551x() if !GLIPP;
552x() if GLIPP && GLIPP;
553x() if !GLIPP || GLIPP;
554x() if do { GLIPP };
555x() if do { no warnings 'void'; 5; GLIPP };
556x() if do { !GLIPP };
557if (GLIPP) { x() } else { z() }
558if (!GLIPP) { x() } else { z() }
559if (GLIPP) { x() } elsif (GLIPP) { z() }
560if (!GLIPP) { x() } elsif (GLIPP) { z() }
561if (GLIPP) { x() } elsif (!GLIPP) { z() }
562if (!GLIPP) { x() } elsif (!GLIPP) { z() }
563if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
564if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
565if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
566>>>>
567x();
568x();
569'???';
570x();
571x();
572x();
573x();
574do {
575 '???'
576};
577do {
578 x()
579};
580do {
581 z()
582};
583do {
584 x()
585};
586do {
587 z()
588};
589do {
590 x()
591};
592'???';
593do {
594 t()
595};
596'???';
597!1;
598####
719c50dc
RGS
599# TODO constant deparsing has been backed out for 5.12
600# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 601# tests that shouldn't be constant folded
ac0f1413
NC
602# It might be fundamentally impossible to make this work on ithreads, in which
603# case the TODO should become a SKIP
71c4dbc3
VP
604x() if $a;
605if ($a == 1) { x() } elsif ($b == 2) { z() }
606if (do { foo(); GLIPP }) { x() }
607if (do { $a++; GLIPP }) { x() }
608>>>>
609x() if $a;
610if ($a == 1) { x(); } elsif ($b == 2) { z(); }
2990415a
FR
611if (do { foo(); GLIPP }) { x(); }
612if (do { ++$a; GLIPP }) { x(); }
613####
0fa4a265 614# TODO constant deparsing has been backed out for 5.12
507a68aa 615# tests for deparsing constants
2990415a
FR
616warn PI;
617####
0fa4a265 618# TODO constant deparsing has been backed out for 5.12
507a68aa 619# tests for deparsing imported constants
3779476a 620warn O_TRUNC;
2990415a 621####
0fa4a265 622# TODO constant deparsing has been backed out for 5.12
507a68aa 623# tests for deparsing re-exported constants
2990415a
FR
624warn O_CREAT;
625####
0fa4a265 626# TODO constant deparsing has been backed out for 5.12
507a68aa 627# tests for deparsing imported constants that got deleted from the original namespace
aaf9c2b2 628warn O_APPEND;
2990415a 629####
0fa4a265
DM
630# TODO constant deparsing has been backed out for 5.12
631# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 632# tests for deparsing constants which got turned into full typeglobs
ac0f1413
NC
633# It might be fundamentally impossible to make this work on ithreads, in which
634# case the TODO should become a SKIP
2990415a
FR
635warn O_EXCL;
636eval '@Fcntl::O_EXCL = qw/affe tiger/;';
637warn O_EXCL;
638####
0fa4a265 639# TODO constant deparsing has been backed out for 5.12
507a68aa 640# tests for deparsing of blessed constant with overloaded numification
2990415a 641warn OVERLOADED_NUMIFICATION;
79289e05
NC
642####
643# TODO Only strict 'refs' currently supported
507a68aa 644# strict
79289e05
NC
645no strict;
646$x;
647####
648# TODO Subsets of warnings could be encoded textually, rather than as bitflips.
507a68aa 649# subsets of warnings
79289e05
NC
650no warnings 'deprecated';
651my $x;
652####
653# TODO Better test for CPAN #33708 - the deparsed code has different behaviour
507a68aa 654# CPAN #33708
79289e05
NC
655use strict;
656no warnings;
657
658foreach (0..3) {
659 my $x = 2;
660 {
661 my $x if 0;
662 print ++$x, "\n";
663 }
664}
d83f38d8 665####
507a68aa 666# no attribute list
d83f38d8
NC
667my $pi = 4;
668####
2dc78664
NC
669# SKIP ?$] > 5.013006 && ":= is now a syntax error"
670# := treated as an empty attribute list
d83f38d8
NC
671no warnings;
672my $pi := 4;
673>>>>
674no warnings;
675my $pi = 4;
676####
507a68aa 677# : = empty attribute list
d83f38d8
NC
678my $pi : = 4;
679>>>>
680my $pi = 4;
689e417f 681####
507a68aa 682# in place sort
689e417f
VP
683our @a;
684my @b;
685@a = sort @a;
686@b = sort @b;
687();
688####
507a68aa 689# in place reverse
689e417f
VP
690our @a;
691my @b;
692@a = reverse @a;
693@b = reverse @b;
694();
06fc6867 695####
507a68aa 696# #71870 Use of uninitialized value in bitwise and B::Deparse
06fc6867
VP
697my($r, $s, @a);
698@a = split(/foo/, $s, 0);
699$r = qr/foo/;
700@a = split(/$r/, $s, 0);
701();
98a1a137 702####
507a68aa 703# package declaration before label
98a1a137
Z
704{
705 package Foo;
706 label: print 123;
707}
538f5756 708####
507a68aa 709# shift optimisation
538f5756
RZ
710shift;
711>>>>
712shift();
713####
507a68aa 714# shift optimisation
538f5756
RZ
715shift @_;
716####
507a68aa 717# shift optimisation
538f5756
RZ
718pop;
719>>>>
720pop();
721####
507a68aa 722# shift optimisation
538f5756 723pop @_;
a539498a 724####
507a68aa 725#[perl #20444]
a539498a
FC
726"foo" =~ (1 ? /foo/ : /bar/);
727"foo" =~ (1 ? y/foo// : /bar/);
728"foo" =~ (1 ? s/foo// : /bar/);
729>>>>
730'foo' =~ ($_ =~ /foo/);
731'foo' =~ ($_ =~ tr/fo//);
732'foo' =~ ($_ =~ s/foo//);
e0ab66ad
NC
733####
734# Test @threadsv_names under 5005threads
735foreach $' (1, 2) {
736 sleep $';
737}
e7afc405
FC
738####
739# y///r
740tr/a/b/r;
cb8157e3
FC
741####
742# y/uni/code/
743tr/\x{345}/\x{370}/;
cb8578ff
FC
744####
745# [perl #90898]
f4002a4b 746<a,>;
09dcfa7d
FC
747####
748# [perl #91008]
749each $@;
750keys $~;
751values $!;
5d8c42c2
FC
752####
753# readpipe with complex expression
754readpipe $a + $b;
93bad3fd
NC
755####
756# aelemfast
757$b::a[0] = 1;
758####
759# aelemfast for a lexical
760my @a;
761$a[0] = 1;
80e3f4ad
FC
762####
763# feature features without feature
764BEGIN {
765 delete $^H{'feature_say'};
766 delete $^H{'feature_state'};
767 delete $^H{'feature_switch'};
768}
769CORE::state $x;
770CORE::say $x;
771CORE::given ($x) {
772 CORE::when (3) {
773 continue;
774 }
775 CORE::default {
e36901c8 776 CORE::break;
80e3f4ad
FC
777 }
778}
7d789282 779CORE::evalbytes '';
84ed0108 780() = CORE::__SUB__;
6ec73527
FC
781####
782# $#- $#+ $#{%} etc.
783my @x;
784@x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
785@x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
786@x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
787@x = ($#{;}, $#{:});
61154ac0
FC
788####
789# ${#} interpolated (the first line magically disables the warning)
790() = *#;
791() = "${#}a";
958ed56b
FC
792####
793# ()[...]
794my(@a) = ()[()];
521795fe
FC
795####
796# sort(foo(bar))
797# sort(foo(bar)) is interpreted as sort &foo(bar)
798# sort foo(bar) is interpreted as sort foo bar
799# parentheses are not optional in this case
800print sort(foo('bar'));
801>>>>
802print sort(foo('bar'));
24fcb59f
FC
803####
804# substr assignment
805substr(my $a, 0, 0) = (foo(), bar());
806$a++;
04be0204
FC
807####
808# hint hash
809BEGIN { $^H{'foo'} = undef; }
810{
811 BEGIN { $^H{'bar'} = undef; }
812 {
813 BEGIN { $^H{'baz'} = undef; }
814 {
815 print $_;
816 }
817 print $_;
818 }
819 print $_;
820}
035146a3
FC
821BEGIN { $^H{q[']} = '('; }
822print $_;
c306e834
FC
823####
824# hint hash changes that serialise the same way with sort %hh
825BEGIN { $^H{'a'} = 'b'; }
826{
827 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
828 print $_;
829}
830print $_;