This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
deparse.t: Automatically count __DATA__ tests
[perl5.git] / dist / B-Deparse / t / deparse.t
1 #!./perl
2
3 BEGIN {
4     unshift @INC, 't';
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     }
10 }
11
12 use warnings;
13 use strict;
14 BEGIN {
15     # BEGIN block is actually a subroutine :-)
16     return unless $] > 5.009;
17     require feature;
18     feature->import(':5.10');
19 }
20 use Test::More;
21 use Config ();
22
23 my $tests = 17; # not counting those in the __DATA__ section
24
25 use B::Deparse;
26 my $deparse = B::Deparse->new();
27 isa_ok($deparse, 'B::Deparse', 'instantiate a B::Deparse object');
28
29 # Tell B::Deparse about our ambient pragmas
30 { my ($hint_bits, $warning_bits, $hinthash);
31  BEGIN { ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H); }
32  $deparse->ambient_pragmas (
33      hint_bits    => $hint_bits,
34      warning_bits => $warning_bits,
35      '%^H'        => $hinthash,
36  );
37 }
38
39 $/ = "\n####\n";
40 while (<DATA>) {
41     chomp;
42     $tests ++;
43     # This code is pinched from the t/lib/common.pl for TODO.
44     # It's not clear how to avoid duplication
45     # Now tweaked a bit to do skip or todo
46     my %reason;
47     foreach my $what (qw(skip todo)) {
48         s/^#\s*\U$what\E\s*(.*)\n//m and $reason{$what} = $1;
49         # If the SKIP reason starts ? then it's taken as a code snippet to
50         # evaluate. This provides the flexibility to have conditional SKIPs
51         if ($reason{$what} && $reason{$what} =~ s/^\?//) {
52             my $temp = eval $reason{$what};
53             if ($@) {
54                 die "# In \U$what\E code reason:\n# $reason{$what}\n$@";
55             }
56             $reason{$what} = $temp;
57         }
58     }
59
60     s/^\s*#\s*(.*)$//mg;
61     my $desc = $1;
62     die "Missing name in test $_" unless defined $desc;
63
64     if ($reason{skip}) {
65         # Like this to avoid needing a label SKIP:
66        Test::More->builder->skip($reason{skip});
67         next;
68     }
69
70     my ($input, $expected);
71     if (/(.*)\n>>>>\n(.*)/s) {
72         ($input, $expected) = ($1, $2);
73     }
74     else {
75         ($input, $expected) = ($_, $_);
76     }
77
78     my $coderef = eval "sub {$input}";
79
80     if ($@) {
81         is($@, "", "compilation of $desc");
82     }
83     else {
84         my $deparsed = $deparse->coderef2text( $coderef );
85         my $regex = $expected;
86         $regex =~ s/(\S+)/\Q$1/g;
87         $regex =~ s/\s+/\\s+/g;
88         $regex = '^\{\s*' . $regex . '\s*\}$';
89
90         local $::TODO = $reason{todo};
91         like($deparsed, qr/$regex/, $desc);
92     }
93 }
94
95 use constant 'c', 'stuff';
96 is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
97    'the subroutine generated by use constant deparses');
98
99 my $a = 0;
100 is($deparse->coderef2text(sub{(-1) ** $a }), "{\n    (-1) ** \$a;\n}",
101    'anon sub capturing an external lexical');
102
103 use constant cr => ['hello'];
104 my $string = "sub " . $deparse->coderef2text(\&cr);
105 my $val = (eval $string)->() or diag $string;
106 is(ref($val), 'ARRAY', 'constant array references deparse');
107 is($val->[0], 'hello', 'and return the correct value');
108
109 my $path = join " ", map { qq["-I$_"] } @INC;
110
111 $a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
112 $a =~ s/-e syntax OK\n//g;
113 $a =~ s/.*possible typo.*\n//;     # Remove warning line
114 $a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037
115 $a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc'
116 $b = <<'EOF';
117 BEGIN { $^I = ".bak"; }
118 BEGIN { $^W = 1; }
119 BEGIN { $/ = "\n"; $\ = "\n"; }
120 LINE: while (defined($_ = <ARGV>)) {
121     chomp $_;
122     our(@F) = split(' ', $_, 0);
123     '???';
124 }
125 EOF
126 is($a, $b,
127    'command line flags deparse as BEGIN blocks setting control variables');
128
129 $a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
130 $a =~ s/-e syntax OK\n//g;
131 is($a, "use constant ('PI', 4);\n",
132    "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
133
134 #Re: perlbug #35857, patch #24505
135 #handle warnings::register-ed packages properly.
136 package B::Deparse::Wrapper;
137 use strict;
138 use warnings;
139 use warnings::register;
140 sub getcode {
141    my $deparser = B::Deparse->new();
142    return $deparser->coderef2text(shift);
143 }
144
145 package Moo;
146 use overload '0+' => sub { 42 };
147
148 package main;
149 use strict;
150 use warnings;
151 use constant GLIPP => 'glipp';
152 use constant PI => 4;
153 use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
154 use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
155 BEGIN { delete $::Fcntl::{O_APPEND}; }
156 use POSIX qw/O_CREAT/;
157 sub test {
158    my $val = shift;
159    my $res = B::Deparse::Wrapper::getcode($val);
160    like($res, qr/use warnings/,
161         '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
162 }
163 my ($q,$p);
164 my $x=sub { ++$q,++$p };
165 test($x);
166 eval <<EOFCODE and test($x);
167    package bar;
168    use strict;
169    use warnings;
170    use warnings::register;
171    package main;
172    1
173 EOFCODE
174
175 # Exotic sub declarations
176 $a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
177 $a =~ s/-e syntax OK\n//g;
178 is($a, <<'EOCODG', "sub :::: and sub ::::::");
179 sub :::: {
180     
181 }
182 sub :::::: {
183     
184 }
185 EOCODG
186
187 # [perl #33752]
188 {
189   my $code = <<"EOCODE";
190 {
191     our \$\x{1e1f}\x{14d}\x{14d};
192 }
193 EOCODE
194   my $deparsed
195    = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
196   s/$ \n//x for $deparsed, $code;
197   is $deparsed, $code, 'our $funny_Unicode_chars';
198 }
199
200 # [perl #62500]
201 $a =
202   `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
203 $a =~ s/-e syntax OK\n//g;
204 is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
205 sub BEGIN {
206     *CORE::GLOBAL::require = sub {
207         1;
208     }
209     ;
210 }
211 EOCODF
212
213 # [perl #91384]
214 $a =
215   `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
216 like($a, qr/-e syntax OK/,
217     "Deparse does not hang when traversing stash circularities");
218
219 # [perl #93990]
220 @* = ();
221 is($deparse->coderef2text(sub{ print "@{*}" }),
222 q<{
223     print "@{*}";
224 }>, 'curly around to interpolate "@{*}"');
225 is($deparse->coderef2text(sub{ print "@{-}" }),
226 q<{
227     print "@-";
228 }>, 'no need to curly around to interpolate "@-"');
229
230 # Strict hints in %^H are mercilessly suppressed
231 $a =
232   `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
233 unlike($a, qr/BEGIN/,
234     "Deparse does not emit strict hh hints");
235
236 # ambient_pragmas should not mess with strict settings.
237 SKIP: {
238     skip "requires 5.11", 1 unless $] >= 5.011;
239     eval q`
240         no strict;
241         BEGIN {
242             # Clear out the strict hints from %^H
243             %^H = ();
244             new B::Deparse -> ambient_pragmas(strict => 'all');
245         }
246         use 5.011;  # should enable strict
247         ok !eval '$do_noT_create_a_variable_with_this_name = 1',
248           'ambient_pragmas do not mess with compiling scope';
249    `;
250 }
251
252 done_testing($tests);
253
254 __DATA__
255 # A constant
256 1;
257 ####
258 # Constants in a block
259 {
260     no warnings;
261     '???';
262     2;
263 }
264 ####
265 # Lexical and simple arithmetic
266 my $test;
267 ++$test and $test /= 2;
268 >>>>
269 my $test;
270 $test /= 2 if ++$test;
271 ####
272 # list x
273 -((1, 2) x 2);
274 ####
275 # lvalue sub
276 {
277     my $test = sub : lvalue {
278         my $x;
279     }
280     ;
281 }
282 ####
283 # method
284 {
285     my $test = sub : method {
286         my $x;
287     }
288     ;
289 }
290 ####
291 # block with continue
292 {
293     234;
294 }
295 continue {
296     123;
297 }
298 ####
299 # lexical and package scalars
300 my $x;
301 print $main::x;
302 ####
303 # lexical and package arrays
304 my @x;
305 print $main::x[1];
306 ####
307 # lexical and package hashes
308 my %x;
309 $x{warn()};
310 ####
311 # <>
312 my $foo;
313 $_ .= <ARGV> . <$foo>;
314 ####
315 # \x{}
316 my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
317 ####
318 # s///e
319 s/x/'y';/e;
320 ####
321 # block
322 { my $x; }
323 ####
324 # while 1
325 while (1) { my $k; }
326 ####
327 # trailing for
328 my ($x,@a);
329 $x=1 for @a;
330 >>>>
331 my($x, @a);
332 $x = 1 foreach (@a);
333 ####
334 # 2 arguments in a 3 argument for
335 for (my $i = 0; $i < 2;) {
336     my $z = 1;
337 }
338 ####
339 # 3 argument for
340 for (my $i = 0; $i < 2; ++$i) {
341     my $z = 1;
342 }
343 ####
344 # 3 argument for again
345 for (my $i = 0; $i < 2; ++$i) {
346     my $z = 1;
347 }
348 ####
349 # while/continue
350 my $i;
351 while ($i) { my $z = 1; } continue { $i = 99; }
352 ####
353 # foreach with my
354 foreach my $i (1, 2) {
355     my $z = 1;
356 }
357 ####
358 # foreach
359 my $i;
360 foreach $i (1, 2) {
361     my $z = 1;
362 }
363 ####
364 # foreach, 2 mys
365 my $i;
366 foreach my $i (1, 2) {
367     my $z = 1;
368 }
369 ####
370 # foreach
371 foreach my $i (1, 2) {
372     my $z = 1;
373 }
374 ####
375 # foreach with our
376 foreach our $i (1, 2) {
377     my $z = 1;
378 }
379 ####
380 # foreach with my and our
381 my $i;
382 foreach our $i (1, 2) {
383     my $z = 1;
384 }
385 ####
386 # reverse sort
387 my @x;
388 print reverse sort(@x);
389 ####
390 # sort with cmp
391 my @x;
392 print((sort {$b cmp $a} @x));
393 ####
394 # reverse sort with block
395 my @x;
396 print((reverse sort {$b <=> $a} @x));
397 ####
398 # foreach reverse
399 our @a;
400 print $_ foreach (reverse @a);
401 ####
402 # foreach reverse (not inplace)
403 our @a;
404 print $_ foreach (reverse 1, 2..5);
405 ####
406 # bug #38684
407 our @ary;
408 @ary = split(' ', 'foo', 0);
409 ####
410 # bug #40055
411 do { () }; 
412 ####
413 # bug #40055
414 do { my $x = 1; $x }; 
415 ####
416 # <20061012113037.GJ25805@c4.convolution.nl>
417 my $f = sub {
418     +{[]};
419 } ;
420 ####
421 # bug #43010
422 '!@$%'->();
423 ####
424 # bug #43010
425 ::();
426 ####
427 # bug #43010
428 '::::'->();
429 ####
430 # bug #43010
431 &::::;
432 ####
433 # [perl #77172]
434 package rt77172;
435 sub foo {} foo & & & foo;
436 >>>>
437 package rt77172;
438 foo(&{&} & foo());
439 ####
440 # variables as method names
441 my $bar;
442 'Foo'->$bar('orz');
443 'Foo'->$bar('orz') = 'a stranger stranger than before';
444 ####
445 # constants as method names
446 'Foo'->bar('orz');
447 ####
448 # constants as method names without ()
449 'Foo'->bar;
450 ####
451 # [perl #47359] "indirect" method call notation
452 our @bar;
453 foo{@bar}+1,->foo;
454 (foo{@bar}+1),foo();
455 foo{@bar}1 xor foo();
456 >>>>
457 our @bar;
458 (foo { @bar } 1)->foo;
459 (foo { @bar } 1), foo();
460 foo { @bar } 1 xor foo();
461 ####
462 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
463 # say
464 say 'foo';
465 ####
466 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
467 # state vars
468 state $x = 42;
469 ####
470 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
471 # state var assignment
472 {
473     my $y = (state $x = 42);
474 }
475 ####
476 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
477 # state vars in anonymous subroutines
478 $a = sub {
479     state $x;
480     return $x++;
481 }
482 ;
483 ####
484 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
485 # each @array;
486 each @ARGV;
487 each @$a;
488 ####
489 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
490 # keys @array; values @array
491 keys @$a if keys @ARGV;
492 values @ARGV if values @$a;
493 ####
494 # Anonymous arrays and hashes, and references to them
495 my $a = {};
496 my $b = \{};
497 my $c = [];
498 my $d = \[];
499 ####
500 # SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
501 # implicit smartmatch in given/when
502 given ('foo') {
503     when ('bar') { continue; }
504     when ($_ ~~ 'quux') { continue; }
505     default { 0; }
506 }
507 ####
508 # conditions in elsifs (regression in change #33710 which fixed bug #37302)
509 if ($a) { x(); }
510 elsif ($b) { x(); }
511 elsif ($a and $b) { x(); }
512 elsif ($a or $b) { x(); }
513 else { x(); }
514 ####
515 # interpolation in regexps
516 my($y, $t);
517 /x${y}z$t/;
518 ####
519 # TODO new undocumented cpan-bug #33708
520 # cpan-bug #33708
521 %{$_ || {}}
522 ####
523 # TODO hash constants not yet fixed
524 # cpan-bug #33708
525 use constant H => { "#" => 1 }; H->{"#"}
526 ####
527 # TODO optimized away 0 not yet fixed
528 # cpan-bug #33708
529 foreach my $i (@_) { 0 }
530 ####
531 # tests with not, not optimized
532 my $c;
533 x() unless $a;
534 x() if not $a and $b;
535 x() if $a and not $b;
536 x() unless not $a and $b;
537 x() unless $a and not $b;
538 x() if not $a or $b;
539 x() if $a or not $b;
540 x() unless not $a or $b;
541 x() unless $a or not $b;
542 x() if $a and not $b and $c;
543 x() if not $a and $b and not $c;
544 x() unless $a and not $b and $c;
545 x() unless not $a and $b and not $c;
546 x() if $a or not $b or $c;
547 x() if not $a or $b or not $c;
548 x() unless $a or not $b or $c;
549 x() unless not $a or $b or not $c;
550 ####
551 # tests with not, optimized
552 my $c;
553 x() if not $a;
554 x() unless not $a;
555 x() if not $a and not $b;
556 x() unless not $a and not $b;
557 x() if not $a or not $b;
558 x() unless not $a or not $b;
559 x() if not $a and not $b and $c;
560 x() unless not $a and not $b and $c;
561 x() if not $a or not $b or $c;
562 x() unless not $a or not $b or $c;
563 x() if not $a and not $b and not $c;
564 x() unless not $a and not $b and not $c;
565 x() if not $a or not $b or not $c;
566 x() unless not $a or not $b or not $c;
567 x() unless not $a or not $b or not $c;
568 >>>>
569 my $c;
570 x() unless $a;
571 x() if $a;
572 x() unless $a or $b;
573 x() if $a or $b;
574 x() unless $a and $b;
575 x() if $a and $b;
576 x() if not $a || $b and $c;
577 x() unless not $a || $b and $c;
578 x() if not $a && $b or $c;
579 x() unless not $a && $b or $c;
580 x() unless $a or $b or $c;
581 x() if $a or $b or $c;
582 x() unless $a and $b and $c;
583 x() if $a and $b and $c;
584 x() unless not $a && $b && $c;
585 ####
586 # tests that should be constant folded
587 x() if 1;
588 x() if GLIPP;
589 x() if !GLIPP;
590 x() if GLIPP && GLIPP;
591 x() if !GLIPP || GLIPP;
592 x() if do { GLIPP };
593 x() if do { no warnings 'void'; 5; GLIPP };
594 x() if do { !GLIPP };
595 if (GLIPP) { x() } else { z() }
596 if (!GLIPP) { x() } else { z() }
597 if (GLIPP) { x() } elsif (GLIPP) { z() }
598 if (!GLIPP) { x() } elsif (GLIPP) { z() }
599 if (GLIPP) { x() } elsif (!GLIPP) { z() }
600 if (!GLIPP) { x() } elsif (!GLIPP) { z() }
601 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
602 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
603 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
604 >>>>
605 x();
606 x();
607 '???';
608 x();
609 x();
610 x();
611 x();
612 do {
613     '???'
614 };
615 do {
616     x()
617 };
618 do {
619     z()
620 };
621 do {
622     x()
623 };
624 do {
625     z()
626 };
627 do {
628     x()
629 };
630 '???';
631 do {
632     t()
633 };
634 '???';
635 !1;
636 ####
637 # TODO constant deparsing has been backed out for 5.12
638 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
639 # tests that shouldn't be constant folded
640 # It might be fundamentally impossible to make this work on ithreads, in which
641 # case the TODO should become a SKIP
642 x() if $a;
643 if ($a == 1) { x() } elsif ($b == 2) { z() }
644 if (do { foo(); GLIPP }) { x() }
645 if (do { $a++; GLIPP }) { x() }
646 >>>>
647 x() if $a;
648 if ($a == 1) { x(); } elsif ($b == 2) { z(); }
649 if (do { foo(); GLIPP }) { x(); }
650 if (do { ++$a; GLIPP }) { x(); }
651 ####
652 # TODO constant deparsing has been backed out for 5.12
653 # tests for deparsing constants
654 warn PI;
655 ####
656 # TODO constant deparsing has been backed out for 5.12
657 # tests for deparsing imported constants
658 warn O_TRUNC;
659 ####
660 # TODO constant deparsing has been backed out for 5.12
661 # tests for deparsing re-exported constants
662 warn O_CREAT;
663 ####
664 # TODO constant deparsing has been backed out for 5.12
665 # tests for deparsing imported constants that got deleted from the original namespace
666 warn O_APPEND;
667 ####
668 # TODO constant deparsing has been backed out for 5.12
669 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
670 # tests for deparsing constants which got turned into full typeglobs
671 # It might be fundamentally impossible to make this work on ithreads, in which
672 # case the TODO should become a SKIP
673 warn O_EXCL;
674 eval '@Fcntl::O_EXCL = qw/affe tiger/;';
675 warn O_EXCL;
676 ####
677 # TODO constant deparsing has been backed out for 5.12
678 # tests for deparsing of blessed constant with overloaded numification
679 warn OVERLOADED_NUMIFICATION;
680 ####
681 # strict
682 no strict;
683 print $x;
684 use strict 'vars';
685 print $main::x;
686 use strict 'subs';
687 print $main::x;
688 use strict 'refs';
689 print $main::x;
690 no strict 'vars';
691 $x;
692 ####
693 # TODO Subsets of warnings could be encoded textually, rather than as bitflips.
694 # subsets of warnings
695 no warnings 'deprecated';
696 my $x;
697 ####
698 # TODO Better test for CPAN #33708 - the deparsed code has different behaviour
699 # CPAN #33708
700 use strict;
701 no warnings;
702
703 foreach (0..3) {
704     my $x = 2;
705     {
706         my $x if 0;
707         print ++$x, "\n";
708     }
709 }
710 ####
711 # no attribute list
712 my $pi = 4;
713 ####
714 # SKIP ?$] > 5.013006 && ":= is now a syntax error"
715 # := treated as an empty attribute list
716 no warnings;
717 my $pi := 4;
718 >>>>
719 no warnings;
720 my $pi = 4;
721 ####
722 # : = empty attribute list
723 my $pi : = 4;
724 >>>>
725 my $pi = 4;
726 ####
727 # in place sort
728 our @a;
729 my @b;
730 @a = sort @a;
731 @b = sort @b;
732 ();
733 ####
734 # in place reverse
735 our @a;
736 my @b;
737 @a = reverse @a;
738 @b = reverse @b;
739 ();
740 ####
741 # #71870 Use of uninitialized value in bitwise and B::Deparse
742 my($r, $s, @a);
743 @a = split(/foo/, $s, 0);
744 $r = qr/foo/;
745 @a = split(/$r/, $s, 0);
746 ();
747 ####
748 # package declaration before label
749 {
750     package Foo;
751     label: print 123;
752 }
753 ####
754 # shift optimisation
755 shift;
756 >>>>
757 shift();
758 ####
759 # shift optimisation
760 shift @_;
761 ####
762 # shift optimisation
763 pop;
764 >>>>
765 pop();
766 ####
767 # shift optimisation
768 pop @_;
769 ####
770 #[perl #20444]
771 "foo" =~ (1 ? /foo/ : /bar/);
772 "foo" =~ (1 ? y/foo// : /bar/);
773 "foo" =~ (1 ? y/foo//r : /bar/);
774 "foo" =~ (1 ? s/foo// : /bar/);
775 >>>>
776 'foo' =~ ($_ =~ /foo/);
777 'foo' =~ ($_ =~ tr/fo//);
778 'foo' =~ ($_ =~ tr/fo//r);
779 'foo' =~ ($_ =~ s/foo//);
780 ####
781 # The fix for [perl #20444] broke this.
782 'foo' =~ do { () };
783 ####
784 # [perl #81424] match against aelemfast_lex
785 my @s;
786 print /$s[1]/;
787 ####
788 # /$#a/
789 print /$#main::a/;
790 ####
791 # [perl #91318] /regexp/applaud
792 print /a/a, s/b/c/a;
793 print /a/aa, s/b/c/aa;
794 print /a/p, s/b/c/p;
795 print /a/l, s/b/c/l;
796 print /a/u, s/b/c/u;
797 {
798     use feature "unicode_strings";
799     print /a/d, s/b/c/d;
800 }
801 {
802     use re "/u";
803     print /a/d, s/b/c/d;
804 }
805 {
806     use 5.012;
807     print /a/d, s/b/c/d;
808 }
809 >>>>
810 print /a/a, s/b/c/a;
811 print /a/aa, s/b/c/aa;
812 print /a/p, s/b/c/p;
813 print /a/l, s/b/c/l;
814 print /a/u, s/b/c/u;
815 {
816     use feature 'unicode_strings';
817     print /a/d, s/b/c/d;
818 }
819 {
820     BEGIN { $^H{'reflags'}         = '0';
821             $^H{'reflags_charset'} = '2'; }
822     print /a/d, s/b/c/d;
823 }
824 {
825     no feature;
826     use feature ':5.12';
827     print /a/d, s/b/c/d;
828 }
829 ####
830 # Test @threadsv_names under 5005threads
831 foreach $' (1, 2) {
832     sleep $';
833 }
834 ####
835 # y///r
836 tr/a/b/r;
837 ####
838 # y/uni/code/
839 tr/\x{345}/\x{370}/;
840 ####
841 # [perl #90898]
842 <a,>;
843 ####
844 # [perl #91008]
845 each $@;
846 keys $~;
847 values $!;
848 ####
849 # readpipe with complex expression
850 readpipe $a + $b;
851 ####
852 # aelemfast
853 $b::a[0] = 1;
854 ####
855 # aelemfast for a lexical
856 my @a;
857 $a[0] = 1;
858 ####
859 # feature features without feature
860 no feature 'say', 'state', 'switch';
861 CORE::state $x;
862 CORE::say $x;
863 CORE::given ($x) {
864     CORE::when (3) {
865         continue;
866     }
867     CORE::default {
868         CORE::break;
869     }
870 }
871 CORE::evalbytes '';
872 () = CORE::__SUB__;
873 ####
874 # feature features when feature has been disabled by use VERSION
875 use feature (sprintf(":%vd", $^V));
876 use 1;
877 CORE::state $x;
878 CORE::say $x;
879 CORE::given ($x) {
880     CORE::when (3) {
881         continue;
882     }
883     CORE::default {
884         CORE::break;
885     }
886 }
887 CORE::evalbytes '';
888 () = CORE::__SUB__;
889 >>>>
890 no feature;
891 use feature ':default';
892 CORE::state $x;
893 CORE::say $x;
894 CORE::given ($x) {
895     CORE::when (3) {
896         continue;
897     }
898     CORE::default {
899         CORE::break;
900     }
901 }
902 CORE::evalbytes '';
903 () = CORE::__SUB__;
904 ####
905 # Feature hints
906 use feature 'current_sub', 'evalbytes';
907 print;
908 use 1;
909 print;
910 use 5.014;
911 print;
912 no feature 'unicode_strings';
913 print;
914 >>>>
915 use feature 'current_sub', 'evalbytes';
916 print $_;
917 no feature;
918 use feature ':default';
919 print $_;
920 no feature;
921 use feature ':5.12';
922 print $_;
923 no feature 'unicode_strings';
924 print $_;
925 ####
926 # $#- $#+ $#{%} etc.
927 my @x;
928 @x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
929 @x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
930 @x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
931 @x = ($#{;}, $#{:});
932 ####
933 # ${#} interpolated (the first line magically disables the warning)
934 () = *#;
935 () = "${#}a";
936 ####
937 # ()[...]
938 my(@a) = ()[()];
939 ####
940 # sort(foo(bar))
941 # sort(foo(bar)) is interpreted as sort &foo(bar)
942 # sort foo(bar) is interpreted as sort foo bar
943 # parentheses are not optional in this case
944 print sort(foo('bar'));
945 >>>>
946 print sort(foo('bar'));
947 ####
948 # substr assignment
949 substr(my $a, 0, 0) = (foo(), bar());
950 $a++;
951 ####
952 # hint hash
953 BEGIN { $^H{'foo'} = undef; }
954 {
955  BEGIN { $^H{'bar'} = undef; }
956  {
957   BEGIN { $^H{'baz'} = undef; }
958   {
959    print $_;
960   }
961   print $_;
962  }
963  print $_;
964 }
965 BEGIN { $^H{q[']} = '('; }
966 print $_;
967 ####
968 # hint hash changes that serialise the same way with sort %hh
969 BEGIN { $^H{'a'} = 'b'; }
970 {
971  BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
972  print $_;
973 }
974 print $_;
975 ####
976 # [perl #47361] do({}) and do +{} (variants of do-file)
977 do({});
978 do +{};
979 sub foo::do {}
980 package foo;
981 CORE::do({});
982 CORE::do +{};
983 >>>>
984 do({});
985 do({});
986 package foo;
987 CORE::do({});
988 CORE::do({});
989 ####
990 # [perl #77096] functions that do not follow the llafr
991 () = (return 1) + time;
992 () = (return ($1 + $2) * $3) + time;
993 () = (return ($a xor $b)) + time;
994 () = (do 'file') + time;
995 () = (do ($1 + $2) * $3) + time;
996 () = (do ($1 xor $2)) + time;
997 () = (goto 1) + 3;
998 () = (require 'foo') + 3;
999 () = (require foo) + 3;
1000 () = (CORE::dump 1) + 3;
1001 () = (last 1) + 3;
1002 () = (next 1) + 3;
1003 () = (redo 1) + 3;
1004 () = (-R $_) + 3;
1005 () = (-W $_) + 3;
1006 () = (-X $_) + 3;
1007 () = (-r $_) + 3;
1008 () = (-w $_) + 3;
1009 () = (-x $_) + 3;
1010 ####
1011 # [perl #97476] not() *does* follow the llafr
1012 $_ = ($a xor not +($1 || 2) ** 2);
1013 ####
1014 # Precedence conundrums with argument-less function calls
1015 () = (eof) + 1;
1016 () = (return) + 1;
1017 () = (return, 1);
1018 () = warn;
1019 () = warn() + 1;
1020 () = setpgrp() + 1;
1021 ####
1022 # [perl #63558] open local(*FH)
1023 open local *FH;
1024 pipe local *FH, local *FH;
1025 ####
1026 # [perl #91416] open "string"
1027 open 'open';
1028 open '####';
1029 open '^A';
1030 open "\ca";
1031 >>>>
1032 open *open;
1033 open '####';
1034 open '^A';
1035 open *^A;
1036 ####
1037 # "string"->[] ->{}
1038 no strict 'vars';
1039 () = 'open'->[0]; #aelemfast
1040 () = '####'->[0];
1041 () = '^A'->[0];
1042 () = "\ca"->[0];
1043 () = 'a::]b'->[0];
1044 () = 'open'->[$_]; #aelem
1045 () = '####'->[$_];
1046 () = '^A'->[$_];
1047 () = "\ca"->[$_];
1048 () = 'a::]b'->[$_];
1049 () = 'open'->{0}; #helem
1050 () = '####'->{0};
1051 () = '^A'->{0};
1052 () = "\ca"->{0};
1053 () = 'a::]b'->{0};
1054 >>>>
1055 no strict 'vars';
1056 () = $open[0];
1057 () = '####'->[0];
1058 () = '^A'->[0];
1059 () = $^A[0];
1060 () = 'a::]b'->[0];
1061 () = $open[$_];
1062 () = '####'->[$_];
1063 () = '^A'->[$_];
1064 () = $^A[$_];
1065 () = 'a::]b'->[$_];
1066 () = $open{'0'};
1067 () = '####'->{'0'};
1068 () = '^A'->{'0'};
1069 () = $^A{'0'};
1070 () = 'a::]b'->{'0'};
1071 ####
1072 # [perl #74740] -(f()) vs -f()
1073 $_ = -(f());
1074 ####
1075 # require <binop>
1076 require 'a' . $1;