File: qr_combine.t

package info (click to toggle)
libppr-perl 0.001010-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 932 kB
  • sloc: perl: 5,987; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,010 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
use strict;
use warnings;
use Test::More;

use PPR::X;
use re 'eval';
use warnings FATAL => 'regexp';

sub lives_ok(&;$) {
    if ($] >= 5.018 && $] <= 5.030) {
        pass "SKIP: $_[1]  (known regex bug in Perl $])";
        return;
    }

    eval { $_[0]->() };
    if (!$@) {
        pass $_[1];
    }
    else {
        fail "$_[1]: $@";
    }
}

my $define_block = q{
        (?(DEFINE)
            (?<MyRandomRule>
                random (?{ 1 })
            )
        )
};
my $g = $PPR::X::GRAMMAR;

lives_ok {
    qr/
        (?(DEFINE)
            (?<MyRandomRule>
                random (?{ 1 })
            )
        )

        $g
    /x;
} 'inline DEFINE + interpolated grammar inside of qr//';

lives_ok {
    qr/
        ${define_block}
        ${g}
    /x;
} 'interpolate DEFINE + interpolate grammar inside of qr';

lives_ok {
    my $whole = qq{
        ${define_block}
        ${g}
    };
    qr/ ${whole} /x;
} 'concatenate regex in string then interpolate inside of qr//';

done_testing;