File: repop_ws.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 (50 lines) | stat: -rw-r--r-- 1,134 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
45
46
47
48
49
50
use 5.010;
use strict;
use warnings;
use Regexp::Grammars;
use Test::More tests => 4;

# The text to match against
my $text = 'a' . (' ' x 5) . 'z';

# This should match without backtracking
my $repop_match = qr/
    \A<TOP>\Z

    <token: TOP> <[val]> ** <sep>
    <token: sep> \s{5}
    <token: val> \w+
/x;

# This should NOT match
my $repop_nomatch = qr/
    \A<TOP>\Z

    <token: TOP> <[val]> ** <sep>
    <token: sep> \s{3}
    <token: val> \w+
/x;

# This demonstrates the expected behaviour of $repop_match
my $standard_match = qr/
    \A<TOP>\Z

    <token: TOP> <[val]> (?: <sep> <[val]> )*
    <token: sep> \s{5}
    <token: val> \w+
/x;

# This demonstrates the expected behaviour of $repop_nomatch
my $standard_nomatch = qr/
    \A<TOP>\Z

    <token: TOP> <[val]> (?: <sep> <[val]> )*
    <token: sep> \s{3}
    <token: val> \w+
/x;

ok $text =~ $repop_match   => "Repetition operator correctly matches";
ok $text !~ $repop_nomatch => "Repetition operator correctly doesn't match";

ok $text =~ $standard_match   => "Simulation correctly matches";
ok $text !~ $standard_nomatch => "Simulation correctly doesn't match";