| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use v5.14; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test2::V0; |
| 7 |
|
| 8 |
use lib "t"; |
| 9 |
use testcase "t::pieces"; |
| 10 |
|
| 11 |
BEGIN { $^H{"t::pieces/permit"} = 1; } |
| 12 |
|
| 13 |
my $ret; |
| 14 |
|
| 15 |
{ |
| 16 |
$ret = piecearithexpr "a term"; |
| 17 |
is( $ret, "(a term)", 'a single term' ); |
| 18 |
} |
| 19 |
|
| 20 |
# arithexpr vs concat |
| 21 |
{ |
| 22 |
$ret = piecearithexpr "x" . "y"; |
| 23 |
is( $ret, "(xy)", 'arithexpr consumes concat' ); |
| 24 |
} |
| 25 |
|
| 26 |
# arithexpr vs comma |
| 27 |
{ |
| 28 |
$ret = join "", "x", piecearithexpr "inside", "y"; |
| 29 |
is( $ret, "x(inside)y", 'arithexpr stops before comma' ); |
| 30 |
} |
| 31 |
|
| 32 |
# arithexpr in piece1 can act as entire parens |
| 33 |
{ |
| 34 |
$ret = piecearithexpr( "x" ) . "y"; |
| 35 |
is( $ret, "(x)y", 'arithexpr treats (PARENS) as entire expression' ); |
| 36 |
} |
| 37 |
|
| 38 |
# optional arithexpr |
| 39 |
{ |
| 40 |
my $ret1 = piecearithexpr_opt "term"; |
| 41 |
my $ret2 = piecearithexpr_opt; |
| 42 |
|
| 43 |
is( $ret1, "(term)", 'optional arithexpr with value' ); |
| 44 |
is( $ret2, undef, 'optional arithexpr empty' ); |
| 45 |
} |
| 46 |
|
| 47 |
done_testing; |