root/lang/perl/HTTP-Router/branches/merb-like/t/21_define_nested_match.t @ 27376

Revision 27376, 0.9 kB (checked in by masaki, 6 years ago)

split match() and route_for()

Line 
1use Test::Base;
2use Test::Deep;
3use t::Router;
4use HTTP::Router;
5
6plan tests => 1 + 2*blocks;
7
8filters { map { $_ => ['eval'] } qw(params conditions request results) };
9
10my $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
18is scalar @{[ $router->routes ]} => blocks;
19
20run {
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' }
Note: See TracBrowser for help on using the browser.