File: types_caller.t

package info (click to toggle)
libfunction-parameters-perl 2.002005-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: perl: 3,945; makefile: 3
file content (103 lines) | stat: -rw-r--r-- 1,923 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!perl
use warnings FATAL => 'all';
use strict;

use Test::More tests => 20;

{
    package MyTC;

    sub new {
        my $class = shift;
        bless {}, $class
    }

    sub check {
        1
    }

    sub get_message {
        die "Internal error: get_message";
    }
}

my ($reify_arg, @reify_caller);
sub take_em {
    my $t = $reify_arg;
    $reify_arg = undef;
    $t, splice @reify_caller
}

use Function::Parameters {
    fun => {
        defaults   => 'function_strict',
        reify_type => sub {
            @_ == 1 or die "WTF: (@_)";
            $_[0] =~ /\ADie\[(.*)\]\z/s and die "$1\n";
            $reify_arg = $_[0];
            @reify_caller = caller;
            MyTC->new
        },
    },
};

{
    my ($t, @c);
    BEGIN { ($t, @c) = take_em; }
    is $t, undef;
    is @c, 0;
}

{
    package SineWeave;
#line 666 "abc.def"
    fun foo(time [ time [ time ] ] $x) {}
#line 56 "t/types_caller.t"
}

{
    my ($t, @c);
    BEGIN { ($t, @c) = take_em; }
    is $t, 'time[time[time]]';
    is $c[0], 'SineWeave';
    is $c[1], 'abc.def';
    is $c[2], 666;
}

{
    {
        package SineWeave::InEvalOutside;
        eval q{#line 500 "abc2.def"
            fun foo2(A[B] | C::D | E::F [ G, H::I, J | K[L], M::N::O [ P::Q, R ] | S::T ] $x) {}
        };
    }
    is $@, '';
    my ($t, @c) = take_em;
    is $t, 'A[B]|C::D|E::F[G,H::I,J|K[L],M::N::O[P::Q,R]|S::T]';
    is $c[0], 'SineWeave::InEvalOutside';
    is $c[1], 'abc2.def';
    is $c[2], 500;
}

{
    {
        eval q{#line 500 "abc3.def"
            package SineWeave::InEvalInside;
            fun foo3(Any $x) {}
        };
    }
    is $@, '';
    my ($t, @c) = take_em;
    is $t, 'Any';
    is $c[0], 'SineWeave::InEvalInside';
    is $c[1], 'abc3.def';
    is $c[2], 501;
}

{
    is eval q{ fun foo4(Die[blaue[Blume]] $x) {} 1 }, undef;
    is $@, "blaue[Blume]\n";
    my ($t, @c) = take_em;
    is $t, undef;
    is @c, 0;
}