File: seplist_greediness.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 (73 lines) | stat: -rw-r--r-- 1,654 bytes parent folder | download | duplicates (6)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
use 5.010;
use warnings;

use Test::More 'no_plan';

use Regexp::Grammars;

my $list_greedy = qr{
    <List>

    <rule: List>
        <[item=Value]>+ % [,]
        <after=(.+)>

    <token: Value>
        \d+
}xms;

my $list_parsimonious = qr{
    <List>

    <rule: List>
        <[item=Value]>+? % [,]
        <after=(.+)>

    <token: Value>
        \d+
}xms;

my $list_parsimonious_anchored = qr{
    <List>

    <rule: List>
        <[item=Value]>+? % [,]
        <after=(, \d+ etc)>

    <token: Value>
        \d+
}xms;

my $list_gluttonous = qr{
    <List>

    <rule: List>
        <[item=Value]>++ % [,]
        <after=(.+)>

    <token: Value>
        \d+
}xms;

no Regexp::Grammars;

my $data     = '1,2,3,4,5';
my $data_etc = '1,2,3,4,5etc';

ok +($data =~ $list_greedy)         => 'Matched greedy';
is_deeply $/{List}{item}, [1,2,3,4] => '...with correct items';
is        $/{List}{after}, ',5'     => '...with correct remainder';

ok +($data =~ $list_parsimonious)     => 'Matched parsimonious';
is_deeply $/{List}{item}, [1]         => '...with correct items';
is        $/{List}{after}, ',2,3,4,5' => '...with correct remainder';

ok +($data_etc =~ $list_parsimonious_anchored) => 'Matched parsimonious anchored';
is_deeply $/{List}{item}, [1,2,3,4]            => '...with correct items';
is        $/{List}{after}, ',5etc'             => '...with correct remainder';

ok !($data =~ $list_gluttonous)      => 'Did not match gluttonous';

ok +($data_etc =~ $list_gluttonous) => 'Matched gluttonous';
#is_deeply $/{List}{item}, [1,2,3,4,5] => '...with correct items';
is        $/{List}{after}, 'etc'      => '...with correct remainder';