import some (modified) MS tests
[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
10 {
11     package Stuff;
12     use Function::Parameters qw(:strict);
13     use Test::More;
14
15     method slurpy(@that) { return \@that }
16     method slurpy_required(@that) { return \@that }
17     method slurpy_last($this, @that) { return $this, \@that; }
18
19     ok !eval q[fun slurpy_first(@that, $this) { return $this, \@that; }];
20     like $@, qr{\@that\b.+\$this\b};
21     TODO: {
22         #local $TODO = "error message incorrect inside an eval";
23
24         like $@, qr{\bslurpy_first\b};
25     }
26
27     ok !eval q[fun slurpy_middle($this, @that, $other) { return $this, \@that, $other }];
28     like $@, qr{\@that\b.+\$other\b};
29     TODO: {
30         #local $TODO = "error message incorrect inside an eval";
31
32         like $@, qr{\bslurpy_middle\b};
33     }
34
35 #    ok !eval q[fun slurpy_positional(:@that) { return \@that; }];
36 #    like $@, qr{slurpy parameter \@that cannot be named, use a reference instead};
37 #
38 #    TODO: {
39 #        local $TODO = "error message incorrect inside an eval";
40 #
41 #        like $@, qr{Stuff::};
42 #        like $@, qr{slurpy_positional\(\)};
43 #    }
44
45     ok !eval q[fun slurpy_two($this, @that, @other) { return $this, \@that, \@other }];
46     like $@, qr{\@that\b.+\@other\b};
47 }
48
49
50 note "Optional slurpy params accept 0 length list"; {
51     is_deeply [Stuff->slurpy()], [[]];
52     is_deeply [Stuff->slurpy_last(23)], [23, []];
53 }
54
55 #note "Required slurpy params require an argument"; {
56 #    throws_ok { Stuff->slurpy_required() }
57 #      qr{slurpy_required\Q()\E, missing required argument \@that at \Q$0\E line @{[__LINE__ - 1]}};
58 #}
59
60
61 done_testing;