root/lang/perl/HTTP-Router/branches/merb-like/t/24_define_register.t @ 27376

Revision 27376, 0.8 kB (checked in by masaki, 5 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(request results) };
9
10my $router = HTTP::Router->new->define(sub {
11    $_->match('/{controller}/{action}/{id}.{format}')->register;
12    $_->match('/{controller}/{action}/{id}')->register;
13});
14
15is scalar @{[ $router->routes ]} => blocks;
16
17run {
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' }
Note: See TracBrowser for help on using the browser.