File: slurpy.t

package info (click to toggle)
libfunction-parameters-perl 2.001003-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 948 kB
  • sloc: perl: 6,478; makefile: 3
file content (64 lines) | stat: -rw-r--r-- 1,684 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!perl

# Test slurpy parameters

use strict;
use warnings FATAL => 'all';

use Test::More;
#use Test::Exception;

{
    package Stuff;
    use Function::Parameters qw(:strict);
    use Test::More;

    method slurpy(@that) { return \@that }
    method slurpy_required(@that) { return \@that }
    method slurpy_last($this, @that) { return $this, \@that; }

    ok !eval q[fun slurpy_first(@that, $this) { return $this, \@that; }];
    like $@, qr{\$this\b.+\@that\b};
#    TODO: {
#        local $TODO = "error message incorrect inside an eval";

#        like $@, qr{Stuff::};
        like $@, qr{\bslurpy_first\b};
#    }

    ok !eval q[fun slurpy_middle($this, @that, $other) { return $this, \@that, $other }];
    like $@, qr{\$other\b.+\@that\b};
#    TODO: {
#        local $TODO = "error message incorrect inside an eval";

#        like $@, qr{Stuff::};
        like $@, qr{\bslurpy_middle\b};
#    }

    ok !eval q[fun slurpy_positional(:@that) { return \@that; }];
    like $@, qr{\bnamed\b.+\@that\b.+\barray\b};

#    TODO: {
#        local $TODO = "error message incorrect inside an eval";

#        like $@, qr{Stuff::};
        like $@, qr{\bslurpy_positional\b};
#    }

    ok !eval q[fun slurpy_two($this, @that, @other) { return $this, \@that, \@other }];
    like $@, qr{\@other\b.+\@that\b};
}


note "Optional slurpy params accept 0 length list"; {
    is_deeply [Stuff->slurpy()], [[]];
    is_deeply [Stuff->slurpy_last(23)], [23, []];
}

#note "Required slurpy params require an argument"; {
#    throws_ok { Stuff->slurpy_required() }
#      qr{slurpy_required\Q()\E, missing required argument \@that at \Q$0\E line @{[__LINE__ - 1]}};
#}


done_testing;