[Bps-public-commit] Path-Dispatcher branch, master, updated. 9de06cf8c3bff3175dc4bc7849a1806ce8e0dc7b
Shawn Moore
sartak at bestpractical.com
Sun Oct 24 01:39:31 EDT 2010
The branch, master has been updated
via 9de06cf8c3bff3175dc4bc7849a1806ce8e0dc7b (commit)
from 05836f7eb86cb817b49b1dc48890acb9f902a281 (commit)
Summary of changes:
t/031-structured-match.t | 42 ++++++++++++++++++++++++++++++------------
1 files changed, 30 insertions(+), 12 deletions(-)
- Log -----------------------------------------------------------------
commit 9de06cf8c3bff3175dc4bc7849a1806ce8e0dc7b
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Sun Oct 24 14:39:33 2010 +0900
More tests for parent matches
diff --git a/t/031-structured-match.t b/t/031-structured-match.t
index 2c5370a..9120d9f 100644
--- a/t/031-structured-match.t
+++ b/t/031-structured-match.t
@@ -4,27 +4,45 @@ use warnings;
use Test::More;
use Path::Dispatcher;
+my $outer = Path::Dispatcher::Rule::Regex->new(
+ regex => qr/^(\w+) /,
+ prefix => 1,
+);
+
+my $inner = Path::Dispatcher::Rule::Regex->new(
+ regex => qr/^(\w+)/,
+ block => sub { return shift }
+);
+
my $dispatcher = Path::Dispatcher->new(
rules => [
Path::Dispatcher::Rule::Under->new(
- predicate => Path::Dispatcher::Rule::Regex->new(
- regex => qr/^(\w+) /,
- prefix => 1,
- ),
- rules => [
- Path::Dispatcher::Rule::Regex->new(
- regex => qr/^(\w+)/,
- block => sub { return shift }
- ),
- ],
+ predicate => $outer,
+ rules => [ $inner ],
),
],
);
my $match = $dispatcher->run("hello world");
-ok($match, "matched");
+my $parent = $match->parent;
+
+ok($parent, 'we have a parent too');
+ok($match, 'matched');
+
+is($parent->pos(1), 'hello', 'outer capture');
is($match->pos(1), 'world', 'inner capture');
-is($match->parent->pos(1), 'hello', 'outer capture');
+
+is($parent->rule, $outer, 'outer rule');
+is($match->rule, $inner, 'inner rule');
+
+is_deeply($parent->positional_captures, ['hello'], 'all pos captures');
+is_deeply($match->positional_captures, ['world'], 'all pos captures');
+
+is($parent->path->path, 'hello world', 'outer path');
+is($match->path->path, 'world', 'inner path');
+
+is($parent->leftover, 'world', 'outer leftover');
+is($match->leftover, undef, 'no inner leftover');
done_testing;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list