implement extended import types
[p5sagit/Function-Parameters.git] / t / named.t
CommitLineData
20f5d15a 1use warnings;
2use strict;
3
4use Test::More tests => 4;
5
6use Dir::Self;
7
8use Function::Parameters {
9 func => {
10 name => 'required',
11 },
12
13 f => {
14 name => 'prohibited',
15 },
16
17 method => {
18 name => 'required',
19 shift => '$this',
20 },
21};
22
23func foo($x, $y, $z) {
24 $x .= $z;
25 return $y . $x . $y;
26}
27
28method bar($k, $d) {
29 $d = $k . $d;
30 return $d . $this->{$k} . $d;
31}
32
33is foo('a', 'b', 'c'), 'bacb';
34is bar({ab => 'cd'}, 'ab', 'e'), 'eabcdeab';
35
36my $baz = f ($x) { $x * 2 + 1 };
37is $baz->(11), 23;
38is $baz->(-0.5), 0;
39
40for my $fail (map [__DIR__ . "/named_$_.fail"], '1', '2', '3', '4') {
41 my ($file) = @$fail;
42 my $done = do $file;
43 my $exc = $@;
44 my $err = $!;
45
46 is $done, undef, "faulty code doesn't load";
47 $exc or die "$file: $err";
48 warn "$exc\n";
49}