RouterSimple/t/Basic.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 4 / 4 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 96.6% 57 / 59 CC 6 SCAR 12.5
CC
6
Cov
100%
__ANON__
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« RouterSimple/Interp.pm ↑ Summary RouterSimple/Request.pm »
1 package Mason::Plugin::RouterSimple::t::Basic;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $Mason::Plugin::RouterSimple::t::Basic::VERSION = '0.07';
4 }
5 1 ▶use Test::Class::Most parent => 'Mason::Test::Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 __PACKAGE__->default_plugins( [ '@Default', 'RouterSimple' ] );
8  
9 1 ▶sub test_routes : Tests {
Subroutine test_routes: called CC=1 SCAR=0.0
Pod undocumented
10 1 my $self = shift;
11  
12 1 $self->add_comp(
13 path => '/foo.mc',
14 src => '
15 %% route "bar";
16 %% route "wiki/:page", { action => "wiki" };
17 %% route "download/*.*", { action => "download" };
18 %% route "blog/{year:[0-9]+}/{month:[0-9]{2}}";
19  
20 <%args>
21 $.page => (default => "standard")
22 </%args>
23  
24 month = <% $.month || "undef" %>
25 page = <% $.page || "standard" %>
26 splat = <% $.splat ? split(",", $.splat) : "undef" %>
27 action = <% $.action || "undef" %>
28  
29 % $m->result->data->{args} = $.args;
30 ',
31 );
32  
33 6 ▶ my $try = sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
34 6 my ( $path, $expect ) = @_;
35  
36 6 my $result;
37 6 ▶ if ($expect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expect) { } 4 2 6
38 4 ▶ my $month = $expect->{month} || "undef";
Condition100%2/2
$expect->{'month'} || 'undef'
l!l
13
MC/DC100%1/1
$expect->{'month'} || 'undef'
$expect->{'month'}
Truth table100%2/2
A
A= $expect->{'month'}
Aresult
11
00
39 4 ▶ my $page = $expect->{page} || "standard";
Condition100%2/2
$expect->{'page'} || 'standard'
l!l
13
MC/DC100%1/1
$expect->{'page'} || 'standard'
$expect->{'page'}
Truth table100%2/2
A
A= $expect->{'page'}
Aresult
11
00
40 4 ▶ my $splat = $expect->{splat} ? split( ',', $expect->{splat} ) : "undef";
Branch: 1 branch
BranchTrueFalseTotal
$expect->{'splat'} ? : 1 3 4
41 4 ▶ my $action = $expect->{action} || "undef";
Condition100%2/2
$expect->{'action'} || 'undef'
l!l
22
MC/DC100%1/1
$expect->{'action'} || 'undef'
$expect->{'action'}
Truth table100%2/2
A
A= $expect->{'action'}
Aresult
11
00
42 4 $self->test_comp(
43 path => $path,
44 expect => "month = $month\npage = $page\nsplat = $splat\naction = $action",
45 expect_data => { args => { %$expect, router_result => $expect } },
46 );
47 }
48 else {
49 2 $self->test_comp( path => $path, expect_error => qr/could not resolve request path/ );
50 }
51 1 };
52  
53 1 $try->( '/foo/bar', {} );
54 1 $try->( '/foo/wiki/abc', { action => 'wiki', page => 'abc' } );
55 1 $try->( '/foo/download/tune.mp3', { action => 'download', splat => [ 'tune', 'mp3' ] } );
56 1 $try->( '/foo/blog/2010/02', { year => '2010', month => '02' } );
57 1 $try->( '/foo/baz', undef );
58 1 $try->( '/foo/blog/201O/02', undef );
59 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 1 ▶sub test_no_routes : Tests {
Subroutine test_no_routes: called CC=1 SCAR=0.0
Pod undocumented
62 1 my $self = shift;
63  
64 1 $self->add_comp(
65 path => '/no_route.mc',
66 src => '<%class>method allow_path_info { 1 }</%class>
67 path_info = <% $m->path_info || "" %>',
68 );
69 1 $self->test_existing_comp( path => '/no_route', expect => 'path_info =' );
70 1 $self->test_existing_comp( path => '/no_route/abc', expect => 'path_info = abc' );
71  
72 1 $self->add_comp(
73 path => '/no_route_or_allow.mc',
74 src => 'path_info = <% $m->path_info || "" %>',
75 );
76 1 $self->test_existing_comp( path => '/no_route_or_allow', expect => 'path_info =' );
77 1 $self->test_existing_comp(
78 path => '/no_route_or_allow/abc',
79 expect_error => qr/could not resolve request path/
80 );
81 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 1 1;
« RouterSimple/Interp.pm ↑ Summary RouterSimple/Request.pm »