preliminary tests for new import syntax
[p5sagit/Function-Parameters.git] / t / named.t
1 use warnings;
2 use strict;
3
4 use Test::More tests => 4;
5
6 use Dir::Self;
7
8 use 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
23 func foo($x, $y, $z) {
24         $x .= $z;
25         return $y . $x . $y;
26 }
27
28 method bar($k, $d) {
29         $d = $k . $d;
30         return $d . $this->{$k} . $d;
31 }
32
33 is foo('a', 'b', 'c'), 'bacb';
34 is bar({ab => 'cd'}, 'ab', 'e'), 'eabcdeab';
35
36 my $baz = f ($x) { $x * 2 + 1 };
37 is $baz->(11), 23;
38 is $baz->(-0.5), 0;
39
40 for 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 }