2 use warnings FATAL => 'all';
4 use Test::More qw(no_plan);
6 use Web::Simple::DispatchParser;
8 my $dp = Web::Simple::DispatchParser->new;
10 my $get = $dp->parse_dispatch_specification('GET');
13 [ $get->({ REQUEST_METHOD => 'GET' }) ],
19 [ $get->({ REQUEST_METHOD => 'POST' }) ],
25 !eval { $dp->parse_dispatch_specification('GET POST'); 1; },
26 "Don't yet allow two methods"
29 my $html = $dp->parse_dispatch_specification('.html');
32 [ $html->({ PATH_INFO => '/foo/bar.html' }) ],
33 [ { PATH_INFO => '/foo/bar' } ],
38 [ $html->({ PATH_INFO => '/foo/bar.xml' }) ],
40 '.xml does not match .html'
43 my $any_ext = $dp->parse_dispatch_specification('.*');
46 [ $any_ext->({ PATH_INFO => '/foo/bar.html' }) ],
47 [ { PATH_INFO => '/foo/bar' }, 'html' ],
48 '.html matches .* and extension returned'
52 [ $any_ext->({ PATH_INFO => '/foo/bar' }) ],
54 'no extension does not match .*'
58 my $slash = $dp->parse_dispatch_specification('/');
61 [ $slash->({ PATH_INFO => '/' }) ],
67 [ $slash->({ PATH_INFO => '/foo' }) ],
69 '/foo does not match /'
72 my $post = $dp->parse_dispatch_specification('/post/*');
75 [ $post->({ PATH_INFO => '/post/one' }) ],
77 '/post/one parses out one'
81 [ $post->({ PATH_INFO => '/post/one/' }) ],
83 '/post/one/ does not match'
86 my $combi = $dp->parse_dispatch_specification('GET+/post/*');
89 [ $combi->({ PATH_INFO => '/post/one', REQUEST_METHOD => 'GET' }) ],
91 '/post/one parses out one'
95 [ $combi->({ PATH_INFO => '/post/one/', REQUEST_METHOD => 'GET' }) ],
97 '/post/one/ does not match'
101 [ $combi->({ PATH_INFO => '/post/one', REQUEST_METHOD => 'POST' }) ],
103 'POST /post/one does not match'
106 my $or = $dp->parse_dispatch_specification('GET|POST');
108 foreach my $meth (qw(GET POST)) {
111 [ $or->({ REQUEST_METHOD => $meth }) ],
113 'GET|POST matches method '.$meth
118 [ $or->({ REQUEST_METHOD => 'PUT' }) ],
120 'GET|POST does not match PUT'