Commit | Line | Data |
98e6239b |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings FATAL => 'all'; |
5 | |
6 | use Test::More; |
7 | |
8 | use Function::Parameters qw(:strict); |
9 | |
10 | fun no_sig { return @_ } |
11 | fun no_args() { return @_ } |
12 | fun one_arg($foo) { return $foo } |
13 | fun two_args($foo, $bar) { return ($foo, $bar) } |
14 | fun array_at_end($foo, @stuff) { return ($foo, @stuff) } |
15 | fun one_named(:$foo) { return $foo; } |
16 | fun one_named_one_positional($bar, :$foo) { return($foo, $bar) } |
17 | |
18 | note "too many arguments"; { |
1a52f2db |
19 | is_deeply [no_sig(42)], [42]; |
20 | |
98e6239b |
21 | |
22 | ok !eval { no_args(42); 1 }, "no args"; |
23 | like $@, qr{Too many arguments}; |
24 | |
25 | ok !eval { one_arg(23, 42); 1 }, "one arg"; |
26 | like $@, qr{Too many arguments}; |
27 | |
28 | ok !eval { two_args(23, 42, 99); 1 }, "two args"; |
29 | like $@, qr{Too many arguments}; |
30 | |
31 | is_deeply [array_at_end(23, 42, 99)], [23, 42, 99], "array at end"; |
32 | } |
33 | |
34 | |
35 | note "with positionals"; { |
36 | is one_named(foo => 42), 42; |
37 | is one_named(foo => 23, foo => 42), 42; |
38 | |
39 | |
1a52f2db |
40 | |
98e6239b |
41 | is_deeply [one_named_one_positional(23, foo => 42)], [42, 23]; |
42 | is_deeply [one_named_one_positional(23, foo => 42, foo => 23)], [23, 23]; |
1a52f2db |
43 | |
98e6239b |
44 | } |
45 | |
46 | |
47 | done_testing; |