File: too_many_args.t

package info (click to toggle)
libmethod-signatures-perl 20170211-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 672 kB
  • sloc: perl: 3,860; makefile: 2
file content (47 lines) | stat: -r--r--r-- 1,580 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use Method::Signatures { compile_at_BEGIN => 0 };

func no_sig { return @_ }
func no_args() { return @_ }
func one_arg($foo) { return $foo }
func two_args($foo, $bar) { return ($foo, $bar) }
func array_at_end($foo, @stuff) { return ($foo, @stuff) }
func one_named(:$foo) { return $foo; }
func one_named_one_positional($bar, :$foo) { return($foo, $bar) }

note "too many arguments"; {
    ok !eval { no_sig(42); 1 },                                   "no args";
    like $@, qr{no_sig\(\), was given too many arguments; it expects 0};

    ok !eval { no_args(42); 1 },                                   "no args";
    like $@, qr{no_args\(\), was given too many arguments; it expects 0};

    ok !eval { one_arg(23, 42); 1 },                               "one arg";
    like $@, qr{one_arg\(\), was given too many arguments; it expects 1};

    ok !eval { two_args(23, 42, 99); 1 },                          "two args";
    like $@, qr{two_args\(\), was given too many arguments; it expects 2};

    is_deeply [array_at_end(23, 42, 99)], [23, 42, 99],         "array at end";
}


note "with positionals"; {
    is one_named(foo => 42), 42;
    ok !eval { one_named(foo => 23, foo => 42); 1 };
    like $@, qr{one_named\(\), was given too many arguments; it expects 1};


    is_deeply [one_named_one_positional(23, foo => 42)], [42, 23];
    ok !eval { one_named_one_positional(23, foo => 42, foo => 23); 1 };
    like $@, qr{one_named_one_positional\(\), was given too many arguments; it expects 2};
}


done_testing;