File: 03func-deparse.t

package info (click to toggle)
libxs-parse-sublike-perl 0.39-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 516 kB
  • sloc: perl: 959; ansic: 952; sh: 6; makefile: 3
file content (65 lines) | stat: -rw-r--r-- 1,581 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
#!/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();

# The standard boilerplate that we have to go through
my ( $hint_bits, $warning_bits, $hinthash );
BEGIN { ( $hint_bits, $warning_bits, $hinthash ) = ( $^H, ${^WARNING_BITS}, \%^H ); }
$deparser->ambient_pragmas(
   hint_bits    => $hint_bits,
   warning_bits => $warning_bits,
   '%^H'        => $hinthash,
);

# 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;