import some (modified) MS tests
[p5sagit/Function-Parameters.git] / t / foreign / Method-Signatures / optional.t
CommitLineData
633048d5 1#!perl
2
3# Test the $arg = undef optional syntax.
4
5use strict;
6use warnings FATAL => 'all';
7
8use Test::More;
9
10{
11 package Stuff;
12
13 use Test::More;
14 use Test::Fatal;
15 use Function::Parameters qw(:strict);
16
17 method whatever($this = undef) {
18 return $this;
19 }
20
21 is( Stuff->whatever(23), 23 );
22
23 method things($this = 99) {
24 return $this;
25 }
26
27 is( Stuff->things(), 99 );
28
29 method some_optional($that, $this = undef) {
30 return $that + ($this || 0);
31 }
32
33 is( Stuff->some_optional(18, 22), 18 + 22 );
34 is( Stuff->some_optional(18), 18 );
35
36
37# # are named parameters optional by default?
38# method named_params(:$this, :$that) {}
39#
40# lives_ok { Stuff->named_params(this => 0) } 'can leave out some named params';
41# lives_ok { Stuff->named_params( ) } 'can leave out all named params';
42
43
44 # are slurpy parameters optional by default?
45 # (throwing in a default just for a little feature interaction test)
46 method slurpy_param($this, $that = 0, @other) {}
47
48 my @a = ();
49 is exception { Stuff->slurpy_param(0, 0, @a) }, undef, 'can pass empty array to slurpy param';
50 is exception { Stuff->slurpy_param(0, 0 ) }, undef, 'can omit slurpy param altogether';
51 is exception { Stuff->slurpy_param(0 ) }, undef, 'can omit other optional params as well as slurpy param';
52}
53
54
55done_testing;