[Bps-public-commit] Path-Dispatcher branch, named_captures, created. dd898a522ce2a691955ee5859ba8bd0fced749a4

Shawn Moore sartak at bestpractical.com
Thu Jun 24 14:35:33 EDT 2010


The branch, named_captures has been created
        at  dd898a522ce2a691955ee5859ba8bd0fced749a4 (commit)

- Log -----------------------------------------------------------------
commit dd898a522ce2a691955ee5859ba8bd0fced749a4
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Jun 24 14:30:42 2010 -0400

    Failing test for named captures

diff --git a/t/904-named-captures.t b/t/904-named-captures.t
new file mode 100644
index 0000000..92fd932
--- /dev/null
+++ b/t/904-named-captures.t
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 9;
+use Test::Exception;
+use Path::Dispatcher;
+
+my @vars;
+
+"abc" =~ /(?<head>.)(.)(?<tail>.)/;
+is_deeply([$1, $2, $3, $4, \%+], ["a", "b", "c", undef, {head=>'a',tail=>'c'}]);
+
+my $dispatcher = Path::Dispatcher->new(
+    rules => [
+        Path::Dispatcher::Rule::Tokens->new(
+            tokens => [qr/(?<style>bus)/, qr/(?<auto>train)/],
+            block  => sub { push @vars, [$1, $2, $3, \%+] },
+        ),
+    ],
+);
+
+is_deeply([splice @vars], []);
+is_deeply([$1, $2, $3, $4], ["a", "b", "c", undef]);
+is_deeply([$1, $2, $3, $4, \%+], ["a", "b", "c", undef, {head=>'a',tail=>'c'}]);
+
+my $dispatch = $dispatcher->dispatch("bus train");
+
+is_deeply([splice @vars], []);
+is_deeply([$1, $2, $3, $4], ["a", "b", "c", undef]);
+is_deeply([$1, $2, $3, $4, \%+], ["a", "b", "c", undef, {head=>'a',tail=>'c'}]);
+
+$dispatch->run;
+
+is_deeply([splice @vars], [['bus', 'train', undef, {head=>'a',tail=>'c',auto=>'train',style=>'bus'}]]);
+
+TODO: {
+    local $TODO = "we stomp on capture vars..";
+    is_deeply([$1, $2, $3, $4, \%+], ["a", "b", "c", undef, {head=>'a',tail=>'c'}]);
+};
+

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list