File: 24_named_captures.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 (35 lines) | stat: -rw-r--r-- 847 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
use strict;
use warnings;
use Test::More import => ['!pass'];

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

plan tests => 2;

SKIP: {
    skip "Need perl >= 5.10", 2 unless $] >= 5.010;

    my $route_regex =
      "/(?<class> user | content | post )/(?<action> delete | find )/(?<id> \\d+ )";

    get qr{$route_regex}x => sub {captures};

    for my $test (
        {   path     => '/user/delete/234',
            expected => {qw/ class user action delete id 234 /}
        }
      )
    {
        my $handle;
        my $path     = $test->{path};
        my $expected = $test->{expected};
        my $request  = [GET => $path];
        response_status_is         $request => 200;
        response_content_is_deeply $request => $expected;
    }
}

# perl <= 5.8.x doesn't support named captures
#plan skip_all => 'Need perl >= 5.10' if $] < 5.010;