[Bps-public-commit] r14618 - in Path-Dispatcher/trunk: lib/Path/Dispatcher t

sartak at bestpractical.com sartak at bestpractical.com
Tue Jul 29 15:46:01 EDT 2008


Author: sartak
Date: Tue Jul 29 15:46:01 2008
New Revision: 14618

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
   Path-Dispatcher/trunk/t/002-rule.t

Log:
 r67900 at onn:  sartak | 2008-07-29 15:45:25 -0400
 More rule tests


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm	Tue Jul 29 15:46:01 2008
@@ -27,6 +27,7 @@
 
     return unless $path =~ $self->regex;
 
+    # return [$1, $2, $3, ...]
     return [ map { substr($path, $-[$_], $+[$_] - $-[$_]) } 1 .. $#- ]
 }
 

Modified: Path-Dispatcher/trunk/t/002-rule.t
==============================================================================
--- Path-Dispatcher/trunk/t/002-rule.t	(original)
+++ Path-Dispatcher/trunk/t/002-rule.t	Tue Jul 29 15:46:01 2008
@@ -1,13 +1,36 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 1;
+use Test::More tests => 4;
 use Path::Dispatcher::Rule;
 
+my @calls;
+
 my $rule = Path::Dispatcher::Rule->new(
     regex => qr/^(..)(..)/,
-    block => sub {},
+    block => sub {
+        push @calls, {
+            vars => [$1, $2, $3],
+            args => [@_],
+        }
+    },
 );
 
 is_deeply([$rule->match('foobar')], [['fo', 'ob']]);
+is_deeply([splice @calls], [], "block not called on match");
+
+$rule->run;
+is_deeply([splice @calls], [{
+    vars => [undef, undef, undef],
+    args => [],
+}], "block called on ->run");
+
+# make sure ->run grabs $1
+"bah" =~ /^(\w+)/;
+
+$rule->run;
+is_deeply([splice @calls], [{
+    vars => ["bah", undef, undef],
+    args => [],
+}], "block called on ->run");
 



More information about the Bps-public-commit mailing list