[Bps-public-commit] Path-Dispatcher branch, named_captures, updated. ba63bd5e50c74dae50f871b63e9975bebd725225
Shawn Moore
sartak at bestpractical.com
Thu Jun 24 16:22:26 EDT 2010
The branch, named_captures has been updated
via ba63bd5e50c74dae50f871b63e9975bebd725225 (commit)
from a467f7ef576f8a8eca263d90e51a012e80ede977 (commit)
Summary of changes:
lib/Path/Dispatcher/Rule/Enum.pm | 10 ++++++-
t/026-enum.t | 50 ++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 2 deletions(-)
create mode 100644 t/026-enum.t
- Log -----------------------------------------------------------------
commit ba63bd5e50c74dae50f871b63e9975bebd725225
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Thu Jun 24 16:23:28 2010 -0400
Improve enum test coverage
diff --git a/lib/Path/Dispatcher/Rule/Enum.pm b/lib/Path/Dispatcher/Rule/Enum.pm
index 870187f..5cb73c9 100644
--- a/lib/Path/Dispatcher/Rule/Enum.pm
+++ b/lib/Path/Dispatcher/Rule/Enum.pm
@@ -18,16 +18,22 @@ sub _match {
my $self = shift;
my $path = shift;
+ my $p = $path->path;
+
if ($self->case_sensitive) {
for my $value (@{ $self->enum }) {
- return {} if $path->path eq $value;
+ return { positional_captures => [ $p ] }
+ if $p eq $value;
}
}
else {
for my $value (@{ $self->enum }) {
- return {} if lc($path->path) eq lc($value);
+ return { positional_captures => [ $p ] }
+ if lc($p) eq lc($value);
}
}
+
+ return;
}
sub _prefix_match {
diff --git a/t/026-enum.t b/t/026-enum.t
new file mode 100644
index 0000000..eb00b7e
--- /dev/null
+++ b/t/026-enum.t
@@ -0,0 +1,50 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 8;
+use Path::Dispatcher;
+
+my @calls;
+
+my $dispatcher = Path::Dispatcher->new;
+$dispatcher->add_rule(
+ Path::Dispatcher::Rule::Enum->new(
+ enum => ['foo', 'bar'],
+ block => sub { push @calls, [$1, $2] },
+ ),
+);
+
+$dispatcher->run('foo');
+is_deeply([splice @calls], [ ['foo', undef] ], "correctly populated number vars from enum");
+
+$dispatcher->run('bar');
+is_deeply([splice @calls], [ ['bar', undef] ], "correctly populated number vars from enum");
+
+$dispatcher->run('jhdsaskjh');
+is_deeply([splice @calls], [ ], "no match");
+
+
+$dispatcher = Path::Dispatcher->new;
+$dispatcher->add_rule(
+ Path::Dispatcher::Rule::Enum->new(
+ enum => ['foo', 'bar'],
+ block => sub { push @calls, [$1, $2] },
+ case_sensitive => 0,
+ ),
+);
+
+$dispatcher->run('foo');
+is_deeply([splice @calls], [ ['foo', undef] ], "correctly populated number vars from enum");
+
+$dispatcher->run('bar');
+is_deeply([splice @calls], [ ['bar', undef] ], "correctly populated number vars from enum");
+
+$dispatcher->run('jhdsaskjh');
+is_deeply([splice @calls], [ ], "no match");
+
+$dispatcher->run('FoO');
+is_deeply([splice @calls], [ ['FoO', undef] ], "correctly populated number vars from enum");
+
+$dispatcher->run('bAR');
+is_deeply([splice @calls], [ ['bAR', undef] ], "correctly populated number vars from enum");
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list