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