add ':strict' import shortcut
[p5sagit/Function-Parameters.git] / t / checkered_3.t
CommitLineData
fcaf7811 1#!perl
2
3use Test::More tests => 101;
4
5use warnings FATAL => 'all';
6use strict;
7
8use Function::Parameters qw(:strict);
9
10fun error_like($re, $body, $name = undef) {
11 local $@;
12 ok !eval { $body->(); 1 };
13 like $@, $re, $name;
14}
15
16fun foo_any { [@_] }
17fun foo_any_a(@args) { [@args] }
18fun foo_any_b($x = undef, @rest) { [@_] }
19fun foo_0() { [@_] }
20fun foo_1($x) { [@_] }
21fun foo_2($x, $y) { [@_] }
22fun foo_3($x, $y, $z) { [@_] }
23fun foo_0_1($x = 'D0') { [$x] }
24fun foo_0_2($x = 'D0', $y = 'D1') { [$x, $y] }
25fun foo_0_3($x = 'D0', $y, $z = 'D2') { [$x, $y, $z] }
26fun foo_1_2($x, $y = 'D1') { [$x, $y] }
27fun foo_1_3($x, $y = 'D1', $z = 'D2') { [$x, $y, $z] }
28fun foo_2_3($x, $y, $z = 'D2') { [$x, $y, $z] }
29fun foo_1_($x, @y) { [@_] }
30
31is_deeply foo_any, [];
32is_deeply foo_any('a'), ['a'];
33is_deeply foo_any('a', 'b'), ['a', 'b'];
34is_deeply foo_any('a', 'b', 'c'), ['a', 'b', 'c'];
35is_deeply foo_any('a', 'b', 'c', 'd'), ['a', 'b', 'c', 'd'];
36
37is_deeply foo_any_a, [];
38is_deeply foo_any_a('a'), ['a'];
39is_deeply foo_any_a('a', 'b'), ['a', 'b'];
40is_deeply foo_any_a('a', 'b', 'c'), ['a', 'b', 'c'];
41is_deeply foo_any_a('a', 'b', 'c', 'd'), ['a', 'b', 'c', 'd'];
42
43is_deeply foo_any_b, [];
44is_deeply foo_any_b('a'), ['a'];
45is_deeply foo_any_b('a', 'b'), ['a', 'b'];
46is_deeply foo_any_b('a', 'b', 'c'), ['a', 'b', 'c'];
47is_deeply foo_any_b('a', 'b', 'c', 'd'), ['a', 'b', 'c', 'd'];
48
49is_deeply foo_0, [];
50error_like qr/Too many arguments.*foo_0/, fun { foo_0 'a' };
51error_like qr/Too many arguments.*foo_0/, fun { foo_0 'a', 'b' };
52error_like qr/Too many arguments.*foo_0/, fun { foo_0 'a', 'b', 'c' };
53error_like qr/Too many arguments.*foo_0/, fun { foo_0 'a', 'b', 'c', 'd' };
54
55error_like qr/Not enough arguments.*foo_1/, fun { foo_1 };
56is_deeply foo_1('a'), ['a'];
57error_like qr/Too many arguments.*foo_1/, fun { foo_1 'a', 'b' };
58error_like qr/Too many arguments.*foo_1/, fun { foo_1 'a', 'b', 'c' };
59error_like qr/Too many arguments.*foo_1/, fun { foo_1 'a', 'b', 'c', 'd' };
60
61error_like qr/Not enough arguments.*foo_2/, fun { foo_2 };
62error_like qr/Not enough arguments.*foo_2/, fun { foo_2 'a' };
63is_deeply foo_2('a', 'b'), ['a', 'b'];
64error_like qr/Too many arguments.*foo_2/, fun { foo_2 'a', 'b', 'c' };
65error_like qr/Too many arguments.*foo_2/, fun { foo_2 'a', 'b', 'c', 'd' };
66
67error_like qr/Not enough arguments.*foo_3/, fun { foo_3 };
68error_like qr/Not enough arguments.*foo_3/, fun { foo_3 'a' };
69error_like qr/Not enough arguments.*foo_3/, fun { foo_3 'a', 'b' };
70is_deeply foo_3('a', 'b', 'c'), ['a', 'b', 'c'];
71error_like qr/Too many arguments.*foo_3/, fun { foo_3 'a', 'b', 'c', 'd' };
72
73is_deeply foo_0_1, ['D0'];
74is_deeply foo_0_1('a'), ['a'];
75error_like qr/Too many arguments.*foo_0_1/, fun { foo_0_1 'a', 'b' };
76error_like qr/Too many arguments.*foo_0_1/, fun { foo_0_1 'a', 'b', 'c' };
77error_like qr/Too many arguments.*foo_0_1/, fun { foo_0_1 'a', 'b', 'c', 'd' };
78
79is_deeply foo_0_2, ['D0', 'D1'];
80is_deeply foo_0_2('a'), ['a', 'D1'];
81is_deeply foo_0_2('a', 'b'), ['a', 'b'];
82error_like qr/Too many arguments.*foo_0_2/, fun { foo_0_2 'a', 'b', 'c' };
83error_like qr/Too many arguments.*foo_0_2/, fun { foo_0_2 'a', 'b', 'c', 'd' };
84
85is_deeply foo_0_3, ['D0', undef, 'D2'];
86is_deeply foo_0_3('a'), ['a', undef, 'D2'];
87is_deeply foo_0_3('a', 'b'), ['a', 'b', 'D2'];
88is_deeply foo_0_3('a', 'b', 'c'), ['a', 'b', 'c'];
89error_like qr/Too many arguments.*foo_0_3/, fun { foo_0_3 'a', 'b', 'c', 'd' };
90
91error_like qr/Not enough arguments.*foo_1_2/, fun { foo_1_2 };
92is_deeply foo_1_2('a'), ['a', 'D1'];
93is_deeply foo_1_2('a', 'b'), ['a', 'b'];
94error_like qr/Too many arguments.*foo_1_2/, fun { foo_1_2 'a', 'b', 'c' };
95error_like qr/Too many arguments.*foo_1_2/, fun { foo_1_2 'a', 'b', 'c', 'd' };
96
97error_like qr/Not enough arguments.*foo_1_3/, fun { foo_1_3 };
98is_deeply foo_1_3('a'), ['a', 'D1', 'D2'];
99is_deeply foo_1_3('a', 'b'), ['a', 'b', 'D2'];
100is_deeply foo_1_3('a', 'b', 'c'), ['a', 'b', 'c'];
101error_like qr/Too many arguments.*foo_1_3/, fun { foo_1_3 'a', 'b', 'c', 'd' };
102
103error_like qr/Not enough arguments.*foo_2_3/, fun { foo_2_3 };
104error_like qr/Not enough arguments.*foo_2_3/, fun { foo_2_3 'a' };
105is_deeply foo_2_3('a', 'b'), ['a', 'b', 'D2'];
106is_deeply foo_2_3('a', 'b', 'c'), ['a', 'b', 'c'];
107error_like qr/Too many arguments.*foo_2_3/, fun { foo_2_3 'a', 'b', 'c', 'd' };
108
109error_like qr/Not enough arguments.*foo_1_/, fun { foo_1_ };
110is_deeply foo_1_('a'), ['a'];
111is_deeply foo_1_('a', 'b'), ['a', 'b'];
112is_deeply foo_1_('a', 'b', 'c'), ['a', 'b', 'c'];
113is_deeply foo_1_('a', 'b', 'c', 'd'), ['a', 'b', 'c', 'd'];
114