File: matchline.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 (44 lines) | stat: -rw-r--r-- 1,446 bytes parent folder | download | duplicates (5)
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
use strict;
use 5.010;

use Test::More 'no_plan';

my $test_grammar = do {
    use Regexp::Grammars;
    qr{
        <startmarker>
            <content>
        <endmarker>

        <token: startmarker>   <at=matchline> \{ <after=matchline>

        <token: content>       (?: <[matchline]> <[num]> <ws>? )+
                       |       <data=(.*)> <matched=(?{1})>

        <token: endmarker>     <matchline> \}
                         |     \] <superbracket=(?{1})>

        <token: num>           \d++
    }xms;
};

   #012345
ok " \n{\naa\n}" =~ $test_grammar  => 'Matched test 1';
is $/{startmarker}{at}, 2          => "Aliased <matchline>";
is $/{startmarker}{after}, 2       => "Post-aliased <matchline>";
is $/{endmarker}{matchline},  4    => "Unaliased <matchline>";
ok ! exists $/{content}{matchline} => "No <matchline>";

   #012345
ok " \n{\naa\n]" =~ $test_grammar    => 'Matched test 2';
is $/{startmarker}{at}, 2            => "Aliased <matchline>";
ok ! exists $/{endmarker}{matchline} => "No unaliased <matchline>";
ok ! exists $/{content}{matchline}   => "No <matchline>";

   #0123456
ok "{11\n22\n\n\n33\n}" =~ $test_grammar  => 'Matched test 3';
is $/{startmarker}{at}, 1                 => "Aliased <matchline>";
is $/{endmarker}{matchline}, 6            => "Unaliased <matchline>";
is_deeply $/{content}{num}, [11,22,33]    => "Repeated contents";
is_deeply $/{content}{matchline}, [1,2,5] => "Repeated <[matchline]>";