File: type_req_opt.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 (40 lines) | stat: -r--r--r-- 989 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl

use strict;
use warnings;

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


{
    package TypeCheck::RequiredOptional;

    use strict;
    use warnings;

    use Method::Signatures;

    method new ($class:) { bless {}, $class; }


    method required_named      ( Int :$foo! ) {}
    method optional_named      ( Int :$foo  ) {}
    method required_positional ( Int  $foo  ) {}
    method optional_positional ( Int  $foo? ) {}

}

our $tester = TypeCheck::RequiredOptional->new;


lives_ok { $tester->optional_named() } 'no type error when failing to pass optional named arg';
lives_ok { $tester->optional_positional() } 'no type error when failing to pass optional positional arg';

throws_ok { $tester->required_named() } qr/missing required argument/,
        'proper error when failing to pass required named arg';
throws_ok { $tester->required_positional() } qr/missing required argument/,
        'proper error when failing to pass required positional arg';


done_testing;