version 1.0401
[p5sagit/Function-Parameters.git] / t / foreign / Method-Signatures / slurpy.t
1 #!perl
2
3 # Test slurpy parameters
4
5 use strict;
6 use warnings FATAL => 'all';
7
8 use Test::More;
9 #use Test::Exception;
10
11 {
12     package Stuff;
13     use Function::Parameters qw(:strict);
14     use Test::More;
15
16     method slurpy(@that) { return \@that }
17     method slurpy_required(@that) { return \@that }
18     method slurpy_last($this, @that) { return $this, \@that; }
19
20     ok !eval q[fun slurpy_first(@that, $this) { return $this, \@that; }];
21     like $@, qr{\@that\b.+\$this\b};
22 #    TODO: {
23 #        local $TODO = "error message incorrect inside an eval";
24
25 #        like $@, qr{Stuff::};
26         like $@, qr{\bslurpy_first\b};
27 #    }
28
29     ok !eval q[fun slurpy_middle($this, @that, $other) { return $this, \@that, $other }];
30     like $@, qr{\@that\b.+\$other\b};
31 #    TODO: {
32 #        local $TODO = "error message incorrect inside an eval";
33
34 #        like $@, qr{Stuff::};
35         like $@, qr{\bslurpy_middle\b};
36 #    }
37
38     ok !eval q[fun slurpy_positional(:@that) { return \@that; }];
39     like $@, qr{\bnamed\b.+\@that\b.+\barray\b};
40
41 #    TODO: {
42 #        local $TODO = "error message incorrect inside an eval";
43
44 #        like $@, qr{Stuff::};
45         like $@, qr{\bslurpy_positional\b};
46 #    }
47
48     ok !eval q[fun slurpy_two($this, @that, @other) { return $this, \@that, \@other }];
49     like $@, qr{\@that\b.+\@other\b};
50 }
51
52
53 note "Optional slurpy params accept 0 length list"; {
54     is_deeply [Stuff->slurpy()], [[]];
55     is_deeply [Stuff->slurpy_last(23)], [23, []];
56 }
57
58 #note "Required slurpy params require an argument"; {
59 #    throws_ok { Stuff->slurpy_required() }
60 #      qr{slurpy_required\Q()\E, missing required argument \@that at \Q$0\E line @{[__LINE__ - 1]}};
61 #}
62
63
64 done_testing;