/
006_match_w_targets.t
117 lines (101 loc) · 2.49 KB
/
006_match_w_targets.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl6
use v6;
use Test;
use Test::Path::Router;
use Path::Router;
class Blog::Index { }
class Blog::ShowDate { }
class Blog::Controller { }
my $INDEX = Blog::Index.new;
my $SHOW_DATE = Blog::ShowDate.new;
my $GENERAL = Blog::Controller.new;
my $router = Path::Router.new;
isa-ok($router, 'Path::Router');
# create some routes
$router.add-route('blog' => {
defaults => {
controller => 'blog',
action => 'index',
},
target => $INDEX,
});
$router.add-route('blog/:year/:month/:day' => {
defaults => {
controller => 'blog',
action => 'show_date',
},
validations => {
year => /\d ** 4/,
month => /\d ** 1..2/,
day => /\d ** 1..2/,
},
target => $SHOW_DATE,
});
$router.add-route('blog/:action/:id' => {
defaults => {
controller => 'blog',
},
validations => {
action => /\D+/,
id => /\d+/
},
target => $GENERAL
});
{
my $match = $router.match('/blog/');
isa-ok($match, 'Path::Router::Route::Match');
is($match.route.target, $INDEX, '... got the right target');
is-deeply(
$match.mapping,
{
controller => 'blog',
action => 'index',
},
'... got the right mapping'
);
}
{
my $match = $router.match('/blog/2006/12/1');
isa-ok($match, 'Path::Router::Route::Match');
is($match.route.target, $SHOW_DATE, '... got the right target');
is-deeply(
$match.mapping,
{
controller => 'blog',
action => 'show_date',
year => '2006',
month => '12',
day => '1',
},
'... got the right mapping'
);
}
{
my $match = $router.match('/blog/show/5');
isa-ok($match, 'Path::Router::Route::Match');
is($match.route.target, $GENERAL, '... got the right target');
is-deeply(
$match.mapping,
{
controller => 'blog',
action => 'show',
id => '5',
},
'... got the right mapping'
);
}
{
my $match = $router.match('/blog/show/0');
isa-ok($match, 'Path::Router::Route::Match');
is($match.route.target, $GENERAL, '... got the right target');
is-deeply(
$match.mapping,
{
controller => 'blog',
action => 'show',
id => '0',
},
'... got the right mapping'
);
}
done-testing;