File: arg.t

package info (click to toggle)
libregexp-grammars-perl 1.058-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,328 kB
  • sloc: perl: 53,328; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download | duplicates (4)
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
use 5.010;
use strict;

use Test::More;
plan 'no_plan';

my $test_grammar = do {
    use Regexp::Grammars;
    qr{
        <keyword=(\w+)>
            <content=(.+?)>
        <dekeyword( delim => 'fo+/')>
      |
        <keyword=(\w+)>
            <content=(.+?)>
        <unkeyword(:keyword, prefix=>'end')>

      |
        <keyword=(\w+)>
            <content=(.+?)>
        <revkeyword=unkeyword(?{ keyword => scalar(reverse($::MATCH{keyword})) })>


        <rule: unkeyword>
            (??{ quotemeta( ($::ARG{prefix}//q{}) . $::ARG{keyword} ) })

        <token: dekeyword>
            (<:delim>) <terminator=(?{$::CAPTURE})>
    }xms;
};

ok 'fooxoof' =~ $test_grammar => 'Match reverse';
is $/{keyword}, 'foo'         => 'Keyword as expected';
is $/{content}, 'x'           => 'Content as expected';
is $/{revkeyword}, 'oof'      => 'Revkeyword as expected';

ok 'fooxendfoo' =~ $test_grammar => 'Match end';
is $/{keyword}, 'foo'            => 'Keyword as expected';
is $/{content}, 'x'              => 'Content as expected';
is $/{unkeyword}, 'endfoo'       => 'Unkeyword as expected';

ok 'fooxfoo/' =~ $test_grammar => 'Match /';
is $/{keyword}, 'foo'          => 'Keyword as expected';
is $/{content}, 'x'            => 'Content as expected';
is_deeply $/{dekeyword}, { "" =>'foo/', 'terminator'=>'foo/' }
                               => 'Dekeyword as expected';