File: named.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 (54 lines) | stat: -rw-r--r-- 1,298 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
#!perl
use warnings FATAL => 'all';
use strict;

use Test::More;

{
    package Foo;

    use Test::More;
    use Test::Fatal;;
    use Function::Parameters qw(:strict);

    method formalize($text, :$justify = "left", :$case = undef) {
        my %params;
        $params{text}           = $text;
        $params{justify}        = $justify;
        $params{case}           = $case if defined $case;

        return \%params;
    }

    is_deeply( Foo->formalize( "stuff" ), { text => "stuff", justify => "left" } );

    like exception { Foo->formalize( "stuff", wibble => 23 ) }, qr/\bnamed\b.+\bwibble\b/;

    method foo( :$arg ) {
        return $arg;
    }

    is( Foo->foo( arg => 42 ), 42 );
    like exception { foo() }, qr/Too few arguments/;


    # Compile time errors need internal refactoring before I can get file, line and method
    # information.
    eval q{
        method wrong( :$named, $pos ) {}
    };
    like $@, qr/\bpositional\b.+\$pos\b.+\bnamed\b.+\$named\b/;

    eval q{
        method wrong( $foo, :$named, $bar ) {}
    };
    like $@, qr/\bpositional\b.+\$bar\b.+\bnamed\b.+\$named\b/;

    eval q{
        method wrong( $foo, $bar = undef, :$named ) {}
    };
    like $@, qr/\boptional positional\b.+\$bar\b.+\brequired named\b.+\$named\b/;
}


done_testing();