Debian Codegraph @

t/06func-conditional-default.t

raw
1 #!/usr/bin/perl
2
3 use v5.14;
4 use warnings;
5
6 use Test2::V0;
7 BEGIN {
8 $] >= 5.026000 or plan skip_all => "No parse_subsignature()";
9 $] >= 5.038000 or plan skip_all => "No OPpARG_IF_UNDEF";
10 }
11
12 use feature 'signatures';
13 no warnings 'experimental';
14
15 use lib "t";
16 use testcase "t::func";
17
18 BEGIN { $^H{"t::func/nfunc"}++ }
19
20 # defaulting expressions can use //= and ||=
21 {
22 nfunc withdefined($x //= "default") { return $x }
23
24 is( withdefined( "value" ), "value", 'param with defined-or' );
25 is( withdefined( undef ), "default", 'param with defined-or defaulting' );
26
27 nfunc withtrue($x ||= "default") { return $x }
28
29 is( withtrue( "value" ), "value", 'param with true-or' );
30 is( withtrue( "" ), "default", 'param with true-or defaulting' );
31 }
32
33 done_testing;