File: 33pieces-termexpr.t

package info (click to toggle)
libxs-parse-keyword-perl 0.48-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 572 kB
  • sloc: ansic: 2,037; perl: 1,013; sh: 6; makefile: 3
file content (60 lines) | stat: -rw-r--r-- 1,177 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use lib "t";
use testcase "t::pieces";

BEGIN { $^H{"t::pieces/permit"} = 1; }

my $ret;

{
   $ret = piecetermexpr "a term";
   is( $ret, "(a term)", 'a single term' );
}

# termexpr vs concat
{
   $ret = piecetermexpr "x" . "y";
   is( $ret, "(xy)", 'termexpr consumes concat' );
}

# termexpr vs comma
{
   $ret = join "", "x", piecetermexpr "inside", "y";
   is( $ret, "x(inside)y", 'termexpr stops before comma' );
}

# termexpr in piece1 can act as entire parens
{
   $ret = piecetermexpr( "x" ) . "y";
   is( $ret, "(x)y", 'termexpr treats (PARENS) as entire expression' );
}

# termexpr in piece1 can act as eat empty parens
{
   no warnings 'uninitialized';

   $ret = piecetermexpr() . "y";
   is( $ret, "()y", 'termexpr accepts empty (PARENS)' );
}

{
   $ret = pieceprefixedtermexpr_VAR $VAR . ", world!";
   is( $ret, "(Hello, world!)", 'result of pieceprefixedtermexpr_VAR' );
}

# optional termexpr
{
   my $ret1 = piecetermexpr_opt "term";
   my $ret2 = piecetermexpr_opt;

   is( $ret1, "(term)", 'optional termexpr with value' );
   is( $ret2, undef,    'optional termexpr empty' );
}

done_testing;