steal more tests from other modules
[p5sagit/Function-Parameters.git] / t / foreign / Method-Signatures / too_many_args.t
CommitLineData
98e6239b 1#!perl
2
3use strict;
4use warnings FATAL => 'all';
5
6use Test::More;
7
8use Function::Parameters qw(:strict);
9
10fun no_sig { return @_ }
11fun no_args() { return @_ }
12fun one_arg($foo) { return $foo }
13fun two_args($foo, $bar) { return ($foo, $bar) }
14fun array_at_end($foo, @stuff) { return ($foo, @stuff) }
15fun one_named(:$foo) { return $foo; }
16fun one_named_one_positional($bar, :$foo) { return($foo, $bar) }
17
18note "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
34note "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
44done_testing;