File: subdecl.t

package info (click to toggle)
libppr-perl 0.001010-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 932 kB
  • sloc: perl: 5,987; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 891 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
use warnings;
use strict;

use B::Deparse;
use Test::More;
use PPR;

plan tests => 9;

my $subdecl = qr{ ^ (?&PerlSubroutineDeclaration) $  $PPR::GRAMMAR }x;

# Perl 5.38 addition...
ok 'sub or_equals   ($x ||= 0 ) {...}' =~ $subdecl, 'or_equals';
ok 'sub doh_equals  ($x //= 0 ) {...}' =~ $subdecl, 'doh_equals';

# 'sub' keyword is optional for these...
ok 'AUTOLOAD {}' =~ $subdecl, 'AUTOLOAD';
ok 'DESTROY {}'  =~ $subdecl, 'DESTROY';
ok '&DESTROY();' !~ $subdecl, '&DESTROY();';
ok 'DESTROY();'  =~ $subdecl, 'DESTROY();';

# Prototypes may come before or after signature, depending on the Perl version...
ok 'sub protofirst :prototype($$@) ($x, $y, @z) {...}' =~ $subdecl, 'protofirst';
ok 'sub protolast  ($x, $y, @z) :prototype($$@) {...}' =~ $subdecl, 'protolast';

# Unnamed subs can have signatures too...
ok 'sub unnamed  ($, $y) {...}' =~ $subdecl, 'unnamed';

done_testing();