Commit | Line | Data |
20f5d15a |
1 | use warnings; |
2 | use strict; |
3 | |
6f61373b |
4 | use Test::More tests => 12; |
20f5d15a |
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'; |
6f61373b |
34 | is bar({ab => 'cd'}, 'ab', 'e'), 'abecdabe'; |
20f5d15a |
35 | |
36 | my $baz = f ($x) { $x * 2 + 1 }; |
37 | is $baz->(11), 23; |
38 | is $baz->(-0.5), 0; |
39 | |
6f61373b |
40 | for my $fail ( |
41 | map [__DIR__ . "/named_$_->[0].fail", @$_[1 .. $#$_]], |
42 | ['1', qr/expect.*function.*name/], |
43 | ['2', qr/expect.*function.*body/], |
44 | ['3', qr/expect.*function.*name/], |
45 | ['4', qr/Global symbol "\$self" requires explicit package name/] |
46 | ) { |
47 | my ($file, $pat) = @$fail; |
20f5d15a |
48 | my $done = do $file; |
49 | my $exc = $@; |
50 | my $err = $!; |
51 | |
52 | is $done, undef, "faulty code doesn't load"; |
53 | $exc or die "$file: $err"; |
6f61373b |
54 | like $exc, $pat; |
20f5d15a |
55 | } |