/
urlmap.t
72 lines (61 loc) · 2.09 KB
/
urlmap.t
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
use v6;
use Test;
use Crust::App::URLMap;
use Crust::Test;
use HTTP::Request;
my $app = Crust::App::URLMap.new;
$app.map: '/foo', sub ($env) { start { 200, [], ['hello'] } };
$app.map: '/bar', sub ($env) { start { 200, [], ['world'] } };
$app.map: 'http://localhost:5000/hello', sub ($env) { start { 200, [], ['こんにちわ'] } };
$app.map: 'http://127.0.0.1:5000/world', sub ($env) { start { 200, [], ['世界'] } };
$app
.map('/perl6', sub ($env) { start { 200, [], ['perl6'] } })
.map('/perl5', sub ($env) { start { 200, [], ['perl5'] } })
.map('/path', sub ($env) { start { 200, [], [$env<PATH_INFO>] } });
my $client = -> $cb {
my ($req, $res);
$req = HTTP::Request.new(GET => "/foo");
$res = $cb($req);
is $res.code, 200;
is $res.content.decode, "hello";
$req = HTTP::Request.new(GET => "/bar");
$res = $cb($req);
is $res.code, 200;
is $res.content.decode, "world";
$req = HTTP::Request.new(GET => "http://localhost:5000/hello");
$res = $cb($req);
is $res.code, 200;
is $res.content.decode, "こんにちわ";
$req = HTTP::Request.new(GET => "http://127.0.0.1:5000/world");
$res = $cb($req);
is $res.code, 200;
is $res.content.decode, "世界";
$req = HTTP::Request.new(GET => "/zoo");
$res = $cb($req);
is $res.code, 404;
$req = HTTP::Request.new(GET => "/perl6");
$res = $cb($req);
is $res.code, 200;
is $res.content.decode, "perl6";
$req = HTTP::Request.new(GET => "/perl5");
$res = $cb($req);
is $res.code, 200;
is $res.content.decode, "perl5";
$req = HTTP::Request.new(GET => "/path");
$res = $cb($req);
is $res.content.decode, "";
$req = HTTP::Request.new(GET => "/path/");
$res = $cb($req);
is $res.content.decode, "/";
$req = HTTP::Request.new(GET => "/path/bar");
$res = $cb($req);
is $res.content.decode, "/bar";
$req = HTTP::Request.new(GET => "/path/bar/");
$res = $cb($req);
is $res.content.decode, "/bar/";
$req = HTTP::Request.new(GET => "/pathbar");
$res = $cb($req);
is $res.code, 404;
};
test-p6w $app, $client;
done-testing;