Debian Codegraph @

cpan/Scalar-List-Utils/t/prototype.t

raw
1 #!./perl
2
3 use strict;
4 use warnings;
5
6 use Sub::Util qw( prototype set_prototype );
7 use Test::More tests => 13;
8
9 sub f { }
10 is( prototype('f'), undef, 'no prototype');
11 is( CORE::prototype('f'), undef, 'no prototype from CORE');
12
13 my $r = set_prototype('$', \&f);
14 is( prototype('f'), '$', 'prototype');
15 is( CORE::prototype('f'), '$', 'prototype from CORE');
16 is( $r, \&f, 'return value');
17
18 set_prototype(undef, \&f);
19 is( prototype('f'), undef, 'remove prototype');
20
21 set_prototype('', \&f);
22 is( prototype('f'), '', 'empty prototype');
23
24 sub g (@) { }
25 is( prototype('g'), '@', '@ prototype');
26
27 set_prototype(undef, \&g);
28 is( prototype('g'), undef, 'remove prototype');
29
30 sub stub;
31 is( prototype('stub'), undef, 'non existing sub');
32
33 set_prototype('$$$', \&stub);
34 is( prototype('stub'), '$$$', 'change non existing sub');
35
36 sub f_decl ($$$$);
37 is( prototype('f_decl'), '$$$$', 'forward declaration');
38
39 set_prototype('\%', \&f_decl);
40 is( prototype('f_decl'), '\%', 'change forward declaration');