| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use Test::Fatal; |
| 5 |
use Dancer2::Core::Route; |
| 6 |
|
| 7 |
plan tests => 3; |
| 8 |
|
| 9 |
my @no_leading_slash = ( 'no+leading+slash', '' ); |
| 10 |
my @leading_slash = ('/+leading+slash', '/', '//' ); |
| 11 |
|
| 12 |
subtest "no prefix, paths without a leading slash" => sub { |
| 13 |
for my $string ( @no_leading_slash ) { |
| 14 |
my $route; |
| 15 |
my $exception = exception { |
| 16 |
$route = Dancer2::Core::Route->new( |
| 17 |
regexp => $string, |
| 18 |
method => 'get', |
| 19 |
code => sub {1}, |
| 20 |
); |
| 21 |
}; |
| 22 |
is( $exception, undef, |
| 23 |
"'$string' is a valid route pattern" |
| 24 |
); |
| 25 |
is( $route->spec_route, "/$string", |
| 26 |
"undef prefix prepends '/' to spec_route" |
| 27 |
); |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
subtest "no prefix, paths with a leading slash" => sub { |
| 32 |
for my $string ( @leading_slash ) { |
| 33 |
my $route; |
| 34 |
my $exception = exception { |
| 35 |
$route = Dancer2::Core::Route->new( |
| 36 |
regexp => $string, |
| 37 |
method => 'get', |
| 38 |
code => sub {1}, |
| 39 |
); |
| 40 |
}; |
| 41 |
is( $exception, undef, |
| 42 |
"'$string' is a valid route pattern" |
| 43 |
); |
| 44 |
is( $route->spec_route, $string, |
| 45 |
"undef prefix does not prepend '/' to spec_route" |
| 46 |
); |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
subtest "prefix and paths append" => sub { |
| 51 |
my $prefix = '/prefix'; |
| 52 |
for my $string ( @no_leading_slash, @leading_slash) { |
| 53 |
my $route; |
| 54 |
my $exception = exception { |
| 55 |
$route = Dancer2::Core::Route->new( |
| 56 |
regexp => $string, |
| 57 |
prefix => $prefix, |
| 58 |
method => 'get', |
| 59 |
code => sub {1}, |
| 60 |
); |
| 61 |
}; |
| 62 |
is( $exception, undef, |
| 63 |
"'$prefix$string' is a valid route pattern" |
| 64 |
); |
| 65 |
} |
| 66 |
}; |
| 67 |
|