Commit | Line | Data |
60682a8e |
1 | use strict; |
2 | use warnings; |
3 | use Test::More; |
4 | |
5 | use Function::Parameters 'f'; |
6 | |
7 | my $add = f ($x, $y) { $x + $y }; |
8 | |
9 | is $add->(2, 4), 6; |
10 | |
5bf140a1 |
11 | ok !eval { Function::Parameters->import('g', 'h', 'i'); 1 }; |
2a5e8ebe |
12 | |
13 | for my $kw ('', '42', 'A::B', 'a b') { |
14 | ok !eval{ Function::Parameters->import($kw); 1 }; |
15 | like $@, qr/valid identifier /; |
16 | } |
17 | |
5bf140a1 |
18 | use Function::Parameters 'func_a', 'meth_a'; |
19 | |
20 | func_a cat_a($x, $y) { |
21 | $x . $y |
22 | } |
23 | |
24 | meth_a tac_a($x) { |
25 | $x . $self |
26 | } |
27 | |
28 | is cat_a('ab', 'cde'), 'abcde'; |
29 | is tac_a('ab', 'cde'), 'cdeab'; |
30 | |
31 | use Function::Parameters { |
32 | meth_b => 'method', |
33 | func_b => 'function', |
34 | }; |
35 | |
36 | func_b cat_b($x, $y) { |
37 | $x . $y |
38 | } |
39 | |
40 | meth_b tac_b($x) { |
41 | $x . $self |
42 | } |
43 | |
44 | is cat_b('ab', 'cde'), 'abcde'; |
45 | is tac_b('ab', 'cde'), 'cdeab'; |
46 | |
60682a8e |
47 | done_testing; |