File: 015-regex-prefix.t

package info (click to toggle)
libpath-dispatcher-perl 1.08-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 512 kB
  • sloc: perl: 1,046; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 804 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More;
use Path::Dispatcher;

my @calls;

my $rule = Path::Dispatcher::Rule::Regex->new(
    regex  => qr/^(foo)\s*(bar)/,
    block  => sub { push @calls, [$1, $2] },
    prefix => 1,
);

ok(!$rule->match(Path::Dispatcher::Path->new('foo')), "prefix means the rule matches a prefix of the path, not the other way around");
ok($rule->match(Path::Dispatcher::Path->new('foo bar')), "prefix matches the full path");
ok($rule->match(Path::Dispatcher::Path->new('foo bar baz')), "prefix matches a prefix of the path");
my $match = $rule->match(Path::Dispatcher::Path->new('foobar:baz'));

ok($match, "matched foobar:baz");

is_deeply($match->positional_captures, ["foo", "bar"], "match returns just the results");
is($match->leftover, ':baz', "leftovers");

done_testing;