more renaming and cleanup
[catagits/Web-Simple.git] / t / dispatch_parser.t
CommitLineData
920d6222 1use strict;
2use warnings FATAL => 'all';
3
4use Test::More qw(no_plan);
5
6use Web::Simple::DispatchParser;
7
8my $dp = Web::Simple::DispatchParser->new;
9
10my $get = $dp->parse_dispatch_specification('GET');
11
12is_deeply(
13 [ $get->({ REQUEST_METHOD => 'GET' }) ],
14 [ {} ],
15 'GET matches'
16);
17
18is_deeply(
19 [ $get->({ REQUEST_METHOD => 'POST' }) ],
20 [],
21 'POST does not match'
22);
23
24ok(
25 !eval { $dp->parse_dispatch_specification('GET POST'); 1; },
26 "Don't yet allow two methods"
27);
28
29my $html = $dp->parse_dispatch_specification('.html');
30
31is_deeply(
32 [ $html->({ PATH_INFO => '/foo/bar.html' }) ],
33 [ { PATH_INFO => '/foo/bar' } ],
34 '.html matches'
35);
36
37is_deeply(
38 [ $html->({ PATH_INFO => '/foo/bar.xml' }) ],
39 [],
40 '.xml does not match .html'
41);
42
43my $slash = $dp->parse_dispatch_specification('/');
44
45is_deeply(
46 [ $slash->({ PATH_INFO => '/' }) ],
47 [ {} ],
48 '/ matches /'
49);
50
51is_deeply(
52 [ $slash->({ PATH_INFO => '/foo' }) ],
53 [ ],
54 '/foo does not match /'
55);
56
57my $post = $dp->parse_dispatch_specification('/post/*');
58
59is_deeply(
60 [ $post->({ PATH_INFO => '/post/one' }) ],
61 [ {}, 'one' ],
62 '/post/one parses out one'
63);
64
65is_deeply(
66 [ $post->({ PATH_INFO => '/post/one/' }) ],
67 [],
68 '/post/one/ does not match'
69);
70
9e4713ab 71my $combi = $dp->parse_dispatch_specification('GET+/post/*');
920d6222 72
73is_deeply(
74 [ $combi->({ PATH_INFO => '/post/one', REQUEST_METHOD => 'GET' }) ],
75 [ {}, 'one' ],
76 '/post/one parses out one'
77);
78
79is_deeply(
80 [ $combi->({ PATH_INFO => '/post/one/', REQUEST_METHOD => 'GET' }) ],
81 [],
82 '/post/one/ does not match'
83);
84
85is_deeply(
86 [ $combi->({ PATH_INFO => '/post/one', REQUEST_METHOD => 'POST' }) ],
87 [],
88 'POST /post/one does not match'
89);