File: uri.t

package info (click to toggle)
libplack-perl 0.9989-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,556 kB
  • sloc: perl: 6,890; python: 6; makefile: 2
file content (88 lines) | stat: -rw-r--r-- 2,330 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More;
use Plack::Request;

my @tests = (
    { add_env => {
        HTTP_HOST => 'example.com',
        SCRIPT_NAME => "",
      },
      uri => 'http://example.com/',
      parameters => {} },
    { add_env => {
        HTTP_HOST => 'example.com',
        SCRIPT_NAME => "",
        PATH_INFO => "/foo bar",
      },
      uri => 'http://example.com/foo%20bar',
      parameters => {} },
    { add_env => {
        HTTP_HOST => 'example.com',
        SCRIPT_NAME => '/test.c',
      },
      uri => 'http://example.com/test.c',
      parameters => {} },
    { add_env => {
        HTTP_HOST => 'example.com',
        SCRIPT_NAME => '/test.c',
        PATH_INFO => '/info',
      },
      uri => 'http://example.com/test.c/info',
      parameters => {} },
    { add_env => {
        HTTP_HOST => 'example.com',
        SCRIPT_NAME => '/test',
        QUERY_STRING => 'dynamic=daikuma',
      },
      uri => 'http://example.com/test?dynamic=daikuma',
      parameters => { dynamic => 'daikuma' } },
    { add_env => {
        HTTP_HOST => 'example.com',
        SCRIPT_NAME => '/exec/'
      },
      uri => 'http://example.com/exec/',
      parameters => {} },
    { add_env => {
        SERVER_NAME => 'example.com'
      },
      uri => 'http://example.com/',
      parameters => {} },
    { add_env => {},
      uri => 'http:///',
      parameters => {} },
    { add_env => {
        HTTP_HOST => 'example.com',
        SCRIPT_NAME => "",
        QUERY_STRING => 'aco=tie'
      },
      uri => 'http://example.com/?aco=tie',
      parameters => { aco => 'tie' } },
    { add_env => {
        HTTP_HOST => 'example.com',
        SCRIPT_NAME => "",
        QUERY_STRING => 0
      },
      uri => 'http://example.com/?0',
      parameters => {} },
    { add_env => {
        HTTP_HOST => 'example.com',
        SCRIPT_NAME => "/foo bar",
        PATH_INFO => "/baz quux",
      },
      uri => 'http://example.com/foo%20bar/baz%20quux',
      parameters => {} }
);

plan tests => 2 * @tests;

for my $block (@tests) {
    my $env = {SERVER_PORT => 80};
    while (my($key, $val) = each %{ $block->{add_env} || {} }) {
        $env->{$key} = $val;
    }
    my $req = Plack::Request->new($env);

    is $req->uri, $block->{uri};
    is_deeply $req->query_parameters, $block->{parameters};
};