Permalink
Browse files

Test for multiple delimiters in a row

  • Loading branch information...
sartak committed Apr 19, 2011
1 parent 34ea260 commit dcd650099fc6afc71200c3a7c135a7d1c68d1bca
Showing with 65 additions and 0 deletions.
  1. +65 −0 t/032-multiple-delimiter.t
View
@@ -0,0 +1,65 @@
+use strict;
+use warnings;
+use Test::More;
+use Path::Dispatcher;
+
+my @calls;
+
+my $dispatcher = Path::Dispatcher->new;
+$dispatcher->add_rule(
+ Path::Dispatcher::Rule::Sequence->new(
+ delimiter => ' ',
+ rules => [
+ Path::Dispatcher::Rule::Eq->new(
+ string => 'foo',
+ ),
+ Path::Dispatcher::Rule::Eq->new(
+ string => 'bar',
+ ),
+ ],
+ block => sub { push @calls, shift->positional_captures },
+ ),
+);
+
+$dispatcher->run('foo bar');
+is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule");
+
+$dispatcher->run('foo bar');
+is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule");
+
+$dispatcher->run(' foo bar ');
+is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule");
+
+
+$dispatcher = Path::Dispatcher->new;
+$dispatcher->add_rule(
+ Path::Dispatcher::Rule::Sequence->new(
+ delimiter => '/',
+ rules => [
+ Path::Dispatcher::Rule::Eq->new(
+ string => 'foo',
+ ),
+ Path::Dispatcher::Rule::Eq->new(
+ string => 'bar',
+ ),
+ ],
+ block => sub { push @calls, shift->positional_captures },
+ ),
+);
+
+$dispatcher->run('/foo/bar');
+is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule");
+
+$dispatcher->run('/foo/bar/');
+is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule");
+
+$dispatcher->run('/foo//bar/');
+is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule");
+
+$dispatcher->run('foo/bar');
+is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule");
+
+$dispatcher->run('///foo///bar///');
+is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule");
+
+done_testing;

0 comments on commit dcd6500

Please sign in to comment.