File: proto.t

package info (click to toggle)
libfunction-parameters-perl 2.001003-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 948 kB
  • sloc: perl: 6,478; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (2)
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
#!perl
use strict;
use warnings;
use Test::More tests => 7;

use vars qw/@warnings/;
BEGIN { $SIG{__WARN__} = sub { push @warnings, @_ } }

BEGIN { is(@warnings, 0, 'no warnings yet') }

use Function::Parameters;

fun with_proto ($x, $y, $z) : prototype($$$) {
    return $x + $y + $z;
}

{
    my $foo;
    fun with_lvalue () : prototype() lvalue { $foo }
}

is(prototype('with_proto'), '$$$', ':proto attribute');

is(prototype('with_lvalue'), '', ':proto with other attributes');
with_lvalue = 1;
is(with_lvalue, 1, 'other attributes still there');

BEGIN { is(@warnings, 0, 'no warnings with correct :proto declarations') }

fun invalid_proto ($x) : prototype(invalid) { $x }

BEGIN {
    #TODO: {
    #    local $TODO = ':proto checks not yet implemented';
        is(@warnings, 1, 'warning with illegal :proto');
        like(
            $warnings[0],
            qr/Illegal character in prototype for fun invalid_proto : invalid at /,
            'warning looks sane',
        );
    #}
}

#eval 'sub foo ($bar) : proto { $bar }';
#like($@, qr/proto attribute requires argument/);