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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More 1.001013;
use Test::Path::Router ();
use Path::Router;
$Test::Path::Router::Test = Test::Builder->create;
my $capture = $Test::Path::Router::Test;
my $test = Test::More->builder;
my $router = Path::Router->new;
{
my $output;
$capture->output(\$output);
$capture->failure_output(\$output);
$capture->todo_output(\$output);
}
$router->add_route('blog' => (
defaults => { controller => 'Blog' }
));
$router->add_route('feed' => (
defaults => { controller => 'Feed' }
));
my %tests = (
mapping_not_ok => {
pass => {
desc => 'mapping_not_ok passes when mapping not found',
args => [{controller => 'Wiki'}, 'fail'],
},
fail => {
desc => 'mapping_not_ok fails when mapping found',
args => [{controller => 'Blog'}, 'pass'],
},
coderef => \&Test::Path::Router::mapping_not_ok,
},
mapping_ok => {
pass => {
desc => 'mapping_ok passes when mapping found',
args => [{controller => 'Blog'}, 'pass'],
},
fail => {
desc => 'mapping_ok fails when mapping not found',
args => [{controller => 'Wiki'}, 'fail'],
},
coderef => \&Test::Path::Router::mapping_ok,
},
mapping_is => {
pass => {
desc => 'mapping_is passes when mapping matches path',
args => [{controller => 'Blog'}, 'blog'],
},
fail => {
desc => 'mapping_is fails when mapping does not match path',
args => [{controller => 'Wiki'}, 'blog'],
},
coderef => \&Test::Path::Router::mapping_is,
},
path_not_ok => {
pass => {
desc => 'path_not_ok passes when path not found',
args => ['wiki'],
},
fail => {
desc => 'path_not_ok fails when path found',
args => ['blog'],
},
coderef => \&Test::Path::Router::path_not_ok,
},
path_ok => {
pass => {
desc => 'path_ok passes when path found',
args => ['blog'],
},
fail => {
desc => 'path_ok fails when path not found',
args => ['wiki'],
},
coderef => \&Test::Path::Router::path_ok,
},
path_is => {
pass => {
desc => 'path_is passes when path matches mapping',
args => [blog => {controller => 'Blog'}],
},
fail => {
desc => 'path_is fails when path does not match mapping',
args => [blog => {controller => 'Wiki'}],
},
coderef => \&Test::Path::Router::path_is,
},
routes_ok => {
pass => {
desc => 'routes_ok passes when all paths and mappings match',
args => [{
blog => {controller => 'Blog'},
feed => {controller => 'Feed'},
}],
},
fail => {
desc => 'routes_ok fails when all paths and mappings do not match',
args => [{
blog => {controller => 'Blog'},
feed => {controller => 'Wiki'},
}],
},
coderef => \&Test::Path::Router::routes_ok,
},
);
for my $function (sort keys %tests) {
my $coderef = $tests{$function}->{coderef};
for my $state (qw(pass fail)) {
my $arguments = $tests{$function}->{$state}->{args};
my $description = $tests{$function}->{$state}->{desc};
$coderef->($router, @$arguments, $description);
my $result = ($capture->details)[-1]->{ok};
$result = !$result if $state eq 'fail';
$test->ok($result, $description);
}
}
$capture->done_testing;
$test->done_testing;
|