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"; { |
19 | is_deeply [no_sig(42)], [42]; |
20 | |
21 | ok !eval { no_args(42); 1 }, "no args"; |
22 | like $@, qr{Too many arguments}; |
23 | |
24 | ok !eval { one_arg(23, 42); 1 }, "one arg"; |
25 | like $@, qr{Too many arguments}; |
26 | |
27 | ok !eval { two_args(23, 42, 99); 1 }, "two args"; |
28 | like $@, qr{Too many arguments}; |
29 | |
30 | is_deeply [array_at_end(23, 42, 99)], [23, 42, 99], "array at end"; |
31 | } |
32 | |
33 | |
34 | note "with positionals"; { |
35 | is one_named(foo => 42), 42; |
36 | is one_named(foo => 23, foo => 42), 42; |
37 | |
38 | |
39 | is_deeply [one_named_one_positional(23, foo => 42)], [42, 23]; |
40 | is_deeply [one_named_one_positional(23, foo => 42, foo => 23)], [23, 23]; |
41 | } |
42 | |
43 | |
44 | done_testing; |