File: 06func-conditional-default.t

package info (click to toggle)
libxs-parse-sublike-perl 0.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 516 kB
  • sloc: ansic: 944; perl: 930; sh: 6; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 777 bytes parent folder | download
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;
BEGIN {
   $] >= 5.026000 or plan skip_all => "No parse_subsignature()";
   $] >= 5.038000 or plan skip_all => "No OPpARG_IF_UNDEF";
}

use feature 'signatures';
no warnings 'experimental';

use lib "t";
use testcase "t::func";

BEGIN { $^H{"t::func/nfunc"}++ }

# defaulting expressions can use //= and ||=
{
   nfunc withdefined($x //= "default") { return $x }

   is( withdefined( "value" ), "value",   'param with defined-or' );
   is( withdefined( undef ),   "default", 'param with defined-or defaulting' );

   nfunc withtrue($x ||= "default") { return $x }

   is( withtrue( "value" ), "value",   'param with true-or' );
   is( withtrue( "" ),      "default", 'param with true-or defaulting' );
}

done_testing;