File: autoflatten.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 (42 lines) | stat: -rw-r--r-- 1,100 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
use 5.010;
use warnings;
use Test::More 'no_plan';

my $parser = do{
    use Regexp::Grammars;
    qr{
        <num> | <str> | <bool> | <list(arg=>1)>

        <token: num>
            \d++

        <token: str>
            ' <content=( .*? )> '

        <token: bool>
            <MATCH=(t)> <etc=(rue)>
          | <etc=(f)> <MATCH=(alse)>

        <token: list>
            <[Dash=(-)]> ** <[Dot=(\.)]>
            <minimize:>
    }xms
};

ok +("'abc'" =~ $parser)    => 'Matched str';
is_deeply $/{str}, { q{} => "'abc'", content => 'abc' }  => 'Unflattened correctly';

ok +(42 =~ $parser) => 'Matched num';
is $/{num}, 42      => 'Flattened correctly';

ok +('true' =~ $parser) => 'Matched true';
is $/{bool}, 't'        => 'Flattened correctly';

ok +('false' =~ $parser) => 'Matched false';
is $/{bool}, 'alse'      => 'Flattened correctly';

ok +('-.-.-' =~ $parser)    => 'Matched list';
is_deeply $/{list}, { q{}=>'-.-.-', Dash=>['-','-','-'], Dot=>['.','.'] }     => 'Flattened correctly';

ok +('-' =~ $parser) => 'Matched minimized list';
is $/{list}, '-'     => 'Flattened correctly';