|
Revision 27376, 0.9 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(params conditions request results) }; |
|---|
| 9 | |
|---|
| 10 | my $router = HTTP::Router->new->define(sub { |
|---|
| 11 | $_->match('/account', { method => 'GET' }, sub { |
|---|
| 12 | while (my $block = next_block) { |
|---|
| 13 | $_->match($block->path, $block->conditions)->to($block->params); |
|---|
| 14 | } |
|---|
| 15 | }); |
|---|
| 16 | }); |
|---|
| 17 | |
|---|
| 18 | is scalar @{[ $router->routes ]} => blocks; |
|---|
| 19 | |
|---|
| 20 | run { |
|---|
| 21 | my $block = shift; |
|---|
| 22 | my $req = create_request($block->request); |
|---|
| 23 | |
|---|
| 24 | my $match = $router->match($req); |
|---|
| 25 | ok $match; |
|---|
| 26 | cmp_deeply $match->params => $block->results; |
|---|
| 27 | }; |
|---|
| 28 | |
|---|
| 29 | __END__ |
|---|
| 30 | === |
|---|
| 31 | --- path: /login |
|---|
| 32 | --- params: { name => 'login' } |
|---|
| 33 | --- request: { path => '/account/login', method => 'GET' } |
|---|
| 34 | --- results: { name => 'login' } |
|---|
| 35 | |
|---|
| 36 | === |
|---|
| 37 | --- path: /logout |
|---|
| 38 | --- params: { name => 'logout' } |
|---|
| 39 | --- request: { path => '/account/logout', method => 'GET' } |
|---|
| 40 | --- results: { name => 'logout' } |
|---|