File: undef_method_arg.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 (32 lines) | stat: -rw-r--r-- 1,020 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
#!perl
use strict;
use warnings FATAL => 'all';
use Test::More;
use Test::Fatal;

{
    package Foo;
    use Function::Parameters qw(:strict);

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

    method m1(:$bar        ) { }
    method m2(:$bar = undef) { }
    method m3(:$bar        ) { }

    method m4( $bar        ) { }
    method m5( $bar = undef) { }
    method m6( $bar        ) { }
}

my $foo = Foo->new;

is(exception { $foo->m1(bar => undef) }, undef, 'Explicitly pass undef to named implicit required arg');
is(exception { $foo->m2(bar => undef) }, undef, 'Explicitly pass undef to named explicit optional arg');
is(exception { $foo->m3(bar => undef) }, undef, 'Explicitly pass undef to named implicit required arg');

is(exception { $foo->m4(undef) }, undef, 'Explicitly pass undef to implicit required arg');
is(exception { $foo->m5(undef) }, undef, 'Explicitly pass undef to explicit required arg');
is(exception { $foo->m6(undef) }, undef, 'Explicitly pass undef to implicit required arg');

done_testing;