[Bps-public-commit] Path-Dispatcher branch, master, updated. 26e5df863e1ecbfed8de65423ac4e3f23693a004
sartak at bestpractical.com
sartak at bestpractical.com
Thu Jan 7 15:23:13 EST 2010
The branch, master has been updated
via 26e5df863e1ecbfed8de65423ac4e3f23693a004 (commit)
from 3e701107a681a52696a7159f61c1f81520b7c5ac (commit)
Summary of changes:
t/025-sequence-custom-rule.t | 79 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 0 deletions(-)
create mode 100644 t/025-sequence-custom-rule.t
- Log -----------------------------------------------------------------
commit 26e5df863e1ecbfed8de65423ac4e3f23693a004
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Thu Jan 7 15:23:06 2010 -0500
Tests for Sequence + custom rule
diff --git a/t/025-sequence-custom-rule.t b/t/025-sequence-custom-rule.t
new file mode 100644
index 0000000..460d193
--- /dev/null
+++ b/t/025-sequence-custom-rule.t
@@ -0,0 +1,79 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 15;
+use Path::Dispatcher;
+
+my @calls;
+
+do {
+ package MyApp::Dispatcher::Rule::Language;
+ use Moose;
+ extends 'Path::Dispatcher::Rule';
+
+ my @langs = qw/ruby perl php python/;
+
+ sub _match {
+ my $self = shift;
+ my $path = shift;
+
+ for my $lang (@langs) {
+ return $lang if $path->path eq $lang;
+ }
+
+ return;
+ }
+
+ sub complete {
+ my $self = shift;
+ my $path = shift->path;
+
+ my @completions;
+
+ for my $lang (@langs) {
+ my $partial = substr($lang, 0, length($path));
+ push @completions, $lang if $partial eq $path;
+ }
+
+ return @completions;
+ }
+};
+
+my $dispatcher = Path::Dispatcher->new(
+ rules => [
+ Path::Dispatcher::Rule::Sequence->new(
+ rules => [
+ Path::Dispatcher::Rule::Eq->new(string => 'use'),
+ MyApp::Dispatcher::Rule::Language->new,
+ ],
+ block => sub { push @calls, [$1, $2, $3] },
+ ),
+ ],
+);
+
+$dispatcher->run("use perl");
+is_deeply([splice @calls], [["use", "perl", undef]]);
+
+$dispatcher->run("use python");
+is_deeply([splice @calls], [["use", "python", undef]]);
+
+$dispatcher->run("use php");
+is_deeply([splice @calls], [["use", "php", undef]]);
+
+$dispatcher->run("use ruby");
+is_deeply([splice @calls], [["use", "ruby", undef]]);
+
+$dispatcher->run("use c++");
+is_deeply([splice @calls], []);
+
+is_deeply([$dispatcher->complete("u")], ["use"]);
+is_deeply([$dispatcher->complete("use")], ["use ruby", "use perl", "use php", "use python"]);
+is_deeply([$dispatcher->complete("use ")], ["use ruby", "use perl", "use php", "use python"]);
+is_deeply([$dispatcher->complete("use r")], ["use ruby"]);
+is_deeply([$dispatcher->complete("use p")], ["use perl", "use php", "use python"]);
+is_deeply([$dispatcher->complete("use pe")], ["use perl"]);
+is_deeply([$dispatcher->complete("use ph")], ["use php"]);
+is_deeply([$dispatcher->complete("use py")], ["use python"]);
+is_deeply([$dispatcher->complete("use px")], []);
+is_deeply([$dispatcher->complete("use x")], []);
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list