Skip to content

Commit

Permalink
a few more routing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 18, 2014
1 parent 8a40c41 commit 0bff738
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Mojolicious/Routes/Pattern.pm
Expand Up @@ -204,7 +204,7 @@ sub _tokenize {
# Placeholder, relaxed or wildcard
elsif ($inside) { $tree[-1][-1] .= $char }

# Text (optimize slash-text and *-text-slash-text)
# Text (optimize slash+text and *+text+slash+text)
elsif ($tree[-1][0] eq 'text') { $tree[-1][-1] .= $char }
elsif (!$tree[-2] && $tree[-1][0] eq 'slash') {
@tree = (['text', "/$char"]);
Expand Down
10 changes: 10 additions & 0 deletions t/mojolicious/routes.t
Expand Up @@ -384,13 +384,23 @@ $m->match($c => {method => 'GET', path => '/optional2'});
is_deeply $m->stack, [{foo => 'one', bar => 'two'}], 'right structure';
is $m->path_for->{path}, '/optional2', 'right path';
$m = Mojolicious::Routes::Match->new(root => $r);
$m->match($c => {method => 'GET', path => '/optional2.txt'});
is_deeply $m->stack, [{foo => 'one', bar => 'two', format => 'txt'}],
'right structure';
is $m->path_for->{path}, '/optional2', 'right path';
$m = Mojolicious::Routes::Match->new(root => $r);
$m->match($c => {method => 'GET', path => '/optional2/three'});
is_deeply $m->stack, [{foo => 'three', bar => 'two'}], 'right structure';
is $m->path_for->{path}, '/optional2/three', 'right path';
$m = Mojolicious::Routes::Match->new(root => $r);
$m->match($c => {method => 'GET', path => '/optional2/three/four'});
is_deeply $m->stack, [{foo => 'three', bar => 'four'}], 'right structure';
is $m->path_for->{path}, '/optional2/three/four', 'right path';
$m = Mojolicious::Routes::Match->new(root => $r);
$m->match($c => {method => 'GET', path => '/optional2/three/four.txt'});
is_deeply $m->stack, [{foo => 'three', bar => 'four', format => 'txt'}],
'right structure';
is $m->path_for->{path}, '/optional2/three/four', 'right path';

# Real world example using most features at once
$m = Mojolicious::Routes::Match->new(root => $r);
Expand Down

0 comments on commit 0bff738

Please sign in to comment.