Debian Codegraph @

t/33pieces-termexpr.t

raw
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 = piecetermexpr "a term";
17 is( $ret, "(a term)", 'a single term' );
18 }
19
20 # termexpr vs concat
21 {
22 $ret = piecetermexpr "x" . "y";
23 is( $ret, "(xy)", 'termexpr consumes concat' );
24 }
25
26 # termexpr vs comma
27 {
28 $ret = join "", "x", piecetermexpr "inside", "y";
29 is( $ret, "x(inside)y", 'termexpr stops before comma' );
30 }
31
32 # termexpr in piece1 can act as entire parens
33 {
34 $ret = piecetermexpr( "x" ) . "y";
35 is( $ret, "(x)y", 'termexpr treats (PARENS) as entire expression' );
36 }
37
38 # termexpr in piece1 can act as eat empty parens
39 {
40 no warnings 'uninitialized';
41
42 $ret = piecetermexpr() . "y";
43 is( $ret, "()y", 'termexpr accepts empty (PARENS)' );
44 }
45
46 {
47 $ret = pieceprefixedtermexpr_VAR $VAR . ", world!";
48 is( $ret, "(Hello, world!)", 'result of pieceprefixedtermexpr_VAR' );
49 }
50
51 # optional termexpr
52 {
53 my $ret1 = piecetermexpr_opt "term";
54 my $ret2 = piecetermexpr_opt;
55
56 is( $ret1, "(term)", 'optional termexpr with value' );
57 is( $ret2, undef, 'optional termexpr empty' );
58 }
59
60 done_testing;