File: 24_multiple_params.t

package info (click to toggle)
libdancer-perl 1.3521%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,460 kB
  • sloc: perl: 7,436; xml: 2,211; sh: 54; makefile: 32; sql: 5
file content (69 lines) | stat: -rw-r--r-- 2,953 bytes parent folder | download | duplicates (6)
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
use strict;
use warnings;

use Test::More tests => 26*2, import => ['!pass'];

use Dancer ':syntax';
use Dancer::Test;

{
    get '/'                           => sub { 'index' };
    get '/name/:name'                 => sub { params->{name} };
    get '/name/:name/:location'       => sub { params->{name} };
    get '/location/:location'         => sub { params->{location} };
    get '/location/:name/:location'   => sub { params->{location} };

    post '/name/:name'                => sub { params->{name} };
    post '/name/:name/:location'      => sub { params->{name} };
    post '/location/:location'        => sub { params->{location} };
    post '/location/:name/:location'  => sub { params->{location} };
}

my @tests = (
    {method => 'GET', path => '/',                expected => 'index'},

    {method => 'GET', path => '/name/bob',        expected => 'bob'},
    {method => 'GET', path => '/name/bill',       expected => 'bill'},
    {method => 'GET', path => '/name/bob',        expected => 'bob'},

    {method => 'GET', path => '/name/bob/paris',  expected => 'bob' },
    {method => 'GET', path => '/name/bob/dublin', expected => 'bob' },
    {method => 'GET', path => '/name/bob/paris',  expected => 'bob' },

    {method => 'GET', path => '/name/bill/paris',  expected => 'bill' },
    {method => 'GET', path => '/name/bill/dublin', expected => 'bill' },
    {method => 'GET', path => '/name/bill/paris',  expected => 'bill' },

    {method => 'GET', path => '/name/bob/paris',   expected => 'bob' },
    {method => 'GET', path => '/name/bob/dublin',  expected => 'bob' },
    {method => 'GET', path => '/name/bill/paris',  expected => 'bill' },
    {method => 'GET', path => '/name/bill/dublin', expected => 'bill' },

    {method => 'GET', path => '/location/paris',      expected => 'paris'},
    {method => 'GET', path => '/location/dublin',     expected => 'dublin'},
    {method => 'GET', path => '/location/paris',      expected => 'paris'},

    {method => 'GET', path => '/location/bob/paris',  expected => 'paris' },
    {method => 'GET', path => '/location/bob/dublin', expected => 'dublin' },
    {method => 'GET', path => '/location/bob/paris',  expected => 'paris' },

    {method => 'post', path => '/name/bob',       expected => 'bob'},
    {method => 'post', path => '/name/bob/paris', expected => 'bob' },
    {method => 'post', path => '/location/paris',     expected => 'paris'},
    {method => 'post', path => '/location/bob/paris', expected => 'paris' },
    {method => 'post', path => '/location/bob/dublin', expected => 'dublin' },
    {method => 'post', path => '/location/bob/paris', expected => 'paris' },
);

setting route_cache => 1;

foreach my $test (@tests) {
    my $method = $test->{method};
    my $path = $test->{path};
    my $expected = $test->{expected};

    my $request = [$method => $path];

    response_status_is $request => 200;
    response_content_is_deeply $request, $expected, 
}