summaryrefslogtreecommitdiffstats
path: root/t/uri.t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-07-18 16:22:08 -0500
committerJesse Luehrs <doy@tozt.net>2012-07-18 16:22:08 -0500
commitb5d66ba6e274eed251da951bb943b9ff67765290 (patch)
tree8b468f4ec6279a2d218f44d69a530c2a2476f1fc /t/uri.t
parentbc67313aa7191255f4123ae8d89f890e2f0772bc (diff)
downloadweb-request-b5d66ba6e274eed251da951bb943b9ff67765290.tar.gz
web-request-b5d66ba6e274eed251da951bb943b9ff67765290.zip
import the Plack::Request test suite
Diffstat (limited to 't/uri.t')
-rw-r--r--t/uri.t104
1 files changed, 104 insertions, 0 deletions
diff --git a/t/uri.t b/t/uri.t
new file mode 100644
index 0000000..08aa584
--- /dev/null
+++ b/t/uri.t
@@ -0,0 +1,104 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Web::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 => "foo_only"
+ },
+ uri => 'http://example.com/?foo_only',
+ parameters => { foo_only => '' } },
+ { add_env => {
+ HTTP_HOST => 'example.com',
+ SCRIPT_NAME => "",
+ QUERY_STRING => "foo&bar=baz"
+ },
+ uri => 'http://example.com/?foo&bar=baz',
+ parameters => { foo => '', bar => 'baz' } },
+ { add_env => {
+ HTTP_HOST => 'example.com',
+ SCRIPT_NAME => "",
+ QUERY_STRING => 0
+ },
+ uri => 'http://example.com/?0',
+ parameters => { 0 => '' } },
+ { add_env => {
+ HTTP_HOST => 'example.com',
+ SCRIPT_NAME => "/foo bar",
+ PATH_INFO => "/baz quux",
+ },
+ uri => 'http://example.com/foo%20bar/baz%20quux',
+ parameters => {} }
+);
+
+for my $block (@tests) {
+ my $env = {SERVER_PORT => 80};
+ while (my($key, $val) = each %{ $block->{add_env} || {} }) {
+ $env->{$key} = $val;
+ }
+ my $req = Web::Request->new_from_env($env);
+
+ is $req->uri, $block->{uri};
+ is_deeply $req->query_parameters, $block->{parameters};
+};
+
+done_testing;