|
Revision 27376, 0.8 kB
(checked in by masaki, 4 years ago)
|
|
split match() and route_for()
|
| Line | |
|---|
| 1 | use Test::Base; |
|---|
| 2 | use Test::Deep; |
|---|
| 3 | use t::Router; |
|---|
| 4 | use HTTP::Router; |
|---|
| 5 | |
|---|
| 6 | plan tests => 1 + 2*blocks; |
|---|
| 7 | |
|---|
| 8 | filters { map { $_ => ['eval'] } qw(request results) }; |
|---|
| 9 | |
|---|
| 10 | my $router = HTTP::Router->new->define(sub { |
|---|
| 11 | $_->match('/{controller}/{action}/{id}.{format}')->register; |
|---|
| 12 | $_->match('/{controller}/{action}/{id}')->register; |
|---|
| 13 | }); |
|---|
| 14 | |
|---|
| 15 | is scalar @{[ $router->routes ]} => blocks; |
|---|
| 16 | |
|---|
| 17 | run { |
|---|
| 18 | my $block = shift; |
|---|
| 19 | my $req = create_request($block->request); |
|---|
| 20 | |
|---|
| 21 | my $match = $router->match($req); |
|---|
| 22 | ok $match; |
|---|
| 23 | cmp_deeply $match->params => $block->results; |
|---|
| 24 | }; |
|---|
| 25 | |
|---|
| 26 | __END__ |
|---|
| 27 | === |
|---|
| 28 | --- request: { path => '/foo/bar/baz' } |
|---|
| 29 | --- results: { controller => 'foo', action => 'bar', id => 'baz' } |
|---|
| 30 | |
|---|
| 31 | === |
|---|
| 32 | --- request: { path => '/foo/bar/baz.html' } |
|---|
| 33 | --- results: { controller => 'foo', action => 'bar', id => 'baz', format => 'html' } |
|---|