File: base.t

package info (click to toggle)
libdancer2-perl 0.400001%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,580 kB
  • sloc: perl: 8,461; makefile: 9
file content (67 lines) | stat: -rw-r--r-- 1,802 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Dancer2::Core::Route;

plan tests => 3;

my @no_leading_slash = ( 'no+leading+slash', '' );
my @leading_slash = ('/+leading+slash', '/', '//' );

subtest "no prefix, paths without a leading slash" => sub {
    for my $string ( @no_leading_slash ) {
        my $route;
        my $exception = exception {
            $route = Dancer2::Core::Route->new(
                regexp => $string,
                method => 'get',
                code   => sub {1},
            );
        };
        is( $exception, undef,
            "'$string' is a valid route pattern"
        );
        is( $route->spec_route, "/$string",
            "undef prefix prepends '/' to spec_route"
        );
    }
};

subtest "no prefix, paths with a leading slash" => sub {
    for my $string ( @leading_slash ) {
        my $route;
        my $exception = exception {
            $route = Dancer2::Core::Route->new(
                regexp => $string,
                method => 'get',
                code   => sub {1},
            );
        };
        is( $exception, undef,
            "'$string' is a valid route pattern"
        );
        is( $route->spec_route, $string,
            "undef prefix does not prepend '/' to spec_route"
        );
    }
};

subtest "prefix and paths append" => sub {
    my $prefix = '/prefix';
    for my $string ( @no_leading_slash, @leading_slash) {
        my $route;
        my $exception = exception {
            $route = Dancer2::Core::Route->new(
                regexp => $string,
                prefix => $prefix,
                method => 'get',
                code   => sub {1},
            );
        };
        is( $exception, undef,
            "'$prefix$string' is a valid route pattern"
        );
    }
};