| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use v5.14; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test2::V0; |
| 7 |
BEGIN { |
| 8 |
$] >= 5.026000 or plan skip_all => "No parse_subsignature()"; |
| 9 |
} |
| 10 |
|
| 11 |
use feature 'signatures'; |
| 12 |
no warnings 'experimental'; |
| 13 |
|
| 14 |
use lib "t"; |
| 15 |
use testcase "t::func"; |
| 16 |
|
| 17 |
BEGIN { $^H{"t::func/func"}++ } |
| 18 |
|
| 19 |
use B::Deparse; |
| 20 |
|
| 21 |
my $deparser = B::Deparse->new(); |
| 22 |
|
| 23 |
# The standard boilerplate that we have to go through |
| 24 |
my ( $hint_bits, $warning_bits, $hinthash ); |
| 25 |
BEGIN { ( $hint_bits, $warning_bits, $hinthash ) = ( $^H, ${^WARNING_BITS}, \%^H ); } |
| 26 |
$deparser->ambient_pragmas( |
| 27 |
hint_bits => $hint_bits, |
| 28 |
warning_bits => $warning_bits, |
| 29 |
'%^H' => $hinthash, |
| 30 |
); |
| 31 |
|
| 32 |
# check that signatured functions deparse the right way |
| 33 |
# (RT132335) |
| 34 |
|
| 35 |
# with signature |
| 36 |
{ |
| 37 |
my $sub = sub ($x, $y) { return $x + $y; }; |
| 38 |
my $func = func ($x, $y) { return $x + $y; }; |
| 39 |
|
| 40 |
my $code = $deparser->coderef2text( $sub ); # the reference source text |
| 41 |
is( $deparser->coderef2text( $func ), $code, |
| 42 |
'Deparsed func with signature identical to deparsed code' ); |
| 43 |
} |
| 44 |
|
| 45 |
# empty signature |
| 46 |
{ |
| 47 |
my $sub = sub () { return 123; }; |
| 48 |
my $func = func () { return 123; }; |
| 49 |
|
| 50 |
my $code = $deparser->coderef2text( $sub ); # the reference source text |
| 51 |
is( $deparser->coderef2text( $func ), $code, |
| 52 |
'Deparsed func with empty signature identical to deparsed code' ); |
| 53 |
} |
| 54 |
|
| 55 |
# empty body |
| 56 |
{ |
| 57 |
my $sub = sub () {}; |
| 58 |
my $func = func () {}; |
| 59 |
|
| 60 |
my $code = $deparser->coderef2text( $sub ); # the reference source text |
| 61 |
is( $deparser->coderef2text( $func ), $code, |
| 62 |
'Deparsed func with empty body identical to deparsed code' ); |
| 63 |
} |
| 64 |
|
| 65 |
done_testing; |