-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new test for route passing (t/routes/004_route_passing.t)
- Loading branch information
Alexis Sukrieh
committed
Jul 22, 2009
1 parent
42ba47f
commit f9d2d52
Showing
2 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 19, import => ['!pass']; | ||
|
||
BEGIN { | ||
use_ok 'Dancer'; | ||
use_ok 'Dancer::Route'; | ||
} | ||
|
||
ok(get('/say/:char' => sub { | ||
my $params = shift; | ||
pass and return false if length($params->{char}) > 1; | ||
"char: ".$params->{char}; | ||
}), 'route /say/:char defined'); | ||
|
||
ok(get('/say/:number' => sub { | ||
my $params = shift; | ||
pass and return false if $params->{number} !~ /^\d+$/; | ||
"number: ".$params->{number}; | ||
}), 'route /say/:number defined'); | ||
|
||
ok(get({regexp => '/say/_(.*)'} => sub { | ||
my $params = shift; | ||
"underscore: ".$params->{splat}[0]; | ||
}), 'route /say/_(.*) defined'); | ||
|
||
ok(get('/say/:word' => sub { | ||
my $params = shift; | ||
pass and return false if $params->{word} =~ /trash/; | ||
"word: ".$params->{word}; | ||
}), 'route /say/:word defined'); | ||
|
||
ok(get('/say/*' => sub { | ||
my $params = shift; | ||
"trash: ".$params->{splat}[0]; | ||
}), 'route /say/* defined'); | ||
|
||
my @tests = ( | ||
{path => '/say/A', expected => 'char: A'}, | ||
{path => '/say/24', expected => 'number: 24'}, | ||
{path => '/say/B', expected => 'char: B'}, | ||
{path => '/say/Perl', expected => 'word: Perl'}, | ||
{path => '/say/_stuff', expected => 'underscore: stuff'}, | ||
{path => '/say/go_to_trash', expected => 'trash: go_to_trash'}, | ||
); | ||
|
||
foreach my $test (@tests) { | ||
my $handle; | ||
my $path = $test->{path}; | ||
my $expected = $test->{expected}; | ||
|
||
$handle = Dancer::Route->find($path); | ||
ok( defined($handle), "route found for path `$path'"); | ||
is_deeply( | ||
Dancer::Route->call($handle)->{body}, $expected, | ||
"match data for path `$path' looks good"); | ||
} |