]> git.vpit.fr Git - perl/modules/B-RecDeparse.git/blob - t/17-calls.t
Stop tripping on special function calls.
[perl/modules/B-RecDeparse.git] / t / 17-calls.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 2 * 4 * 5;
7
8 use B::RecDeparse;
9
10 my $brd = B::RecDeparse->new(level => -1);
11
12 sub foo { 123 }
13 my $pkg;
14
15 my @tests = (
16  [ e1 => 'foo()',      '123' ],
17  [ e2 => 'foo(1)',     '123' ],
18  [ e3 => 'foo(@_)',    '123' ],
19  [ e4 => 'foo(shift)', '123' ],
20
21  [ x1 => 'bar()',      'bar' ],
22  [ x2 => 'bar(1)',     'bar' ],
23  [ x3 => 'bar(@_)',    'bar' ],
24  [ x4 => 'bar(shift)', 'bar' ],
25
26  [ m1  => '"pkg"->qux()',      'qux' ],
27  [ m2  => '"pkg"->qux(1)',     'qux' ],
28  [ m3  => '"pkg"->qux(@_)',    'qux' ],
29  [ m4  => '"pkg"->qux(shift)', 'qux' ],
30  [ m5  => '$pkg->qux()',       'qux' ],
31  [ m6  => '$pkg->qux(1)',      'qux' ],
32  [ m7  => '$pkg->qux(@_)',     'qux' ],
33  [ m8  => '$pkg->qux(shift)',  'qux' ],
34  [ m9  => 'shift->qux()',      'qux' ],
35  [ m10 => 'shift->qux(1)',     'qux' ],
36  [ m11 => 'shift->qux(@_)',    'qux' ],
37  [ m12 => 'shift->qux(shift)', 'qux' ],
38 );
39
40 for my $test (@tests) {
41  my ($name, $source, $match) = @$test;
42
43  my $code = do {
44   local $@;
45   eval "sub { $source }";
46  };
47
48  my $res = eval { $brd->coderef2text($code) };
49  is  $@,    '',             "deparsing sub $name doesn't croak";
50  $res = '' unless defined $res;
51  like $res, qr/\Q$match\E/, "deparsing sub $name works as expected";
52 }