X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fdispatch_parser.t;h=a001b4195c0d361220ead78437730305a986e903;hb=92e23550709cc075dd06e14d50dc302d0b405977;hp=ffde868e9c88f35b46e6f8f1f2a3750baf7d7d82;hpb=2ee4ab06c2d14ce6b7c594b1819c314f8b496e0c;p=catagits%2FWeb-Simple.git diff --git a/t/dispatch_parser.t b/t/dispatch_parser.t index ffde868..a001b41 100644 --- a/t/dispatch_parser.t +++ b/t/dispatch_parser.t @@ -200,3 +200,73 @@ is_deeply( [], '!.html+.* does not match /foo' ); + +my $sub = $dp->parse_dispatch_specification('/foo/*/...'); + +is_deeply( + [ $sub->({ PATH_INFO => '/foo/1/bar' }) ], + [ { PATH_INFO => '/bar' }, 1 ], + '/foo/*/... matches /foo/1/bar and strips to /bar' +); + +is_deeply( + [ $sub->({ PATH_INFO => '/foo/1/' }) ], + [ { PATH_INFO => '/' }, 1 ], + '/foo/*/... matches /foo/1/bar and strips to /' +); + +is_deeply( + [ $sub->({ PATH_INFO => '/foo/1' }) ], + [], + '/foo/*/... does not match /foo/1 (no trailing /)' +); + +my $q = 'foo=FOO&bar=BAR1&baz=one+two&quux=QUUX1&quux=QUUX2' + .'&bar=BAR2&quux=QUUX3&evil=%2F'; + +my %all_single = ( + foo => 'FOO', + bar => 'BAR2', + baz => 'one two', + quux => 'QUUX3', + evil => '/', +); + +my %all_multi = ( + foo => [ 'FOO' ], + bar => [ qw(BAR1 BAR2) ], + baz => [ 'one two' ], + quux => [ qw(QUUX1 QUUX2 QUUX3) ], + evil => [ '/' ], +); + +my $foo = $dp->parse_dispatch_specification('?foo='); + +is_deeply( + [ $foo->({ QUERY_STRING => '' }) ], + [], + '?foo= fails with no query' +); + +foreach my $win ( + [ '?foo=' => { foo => 'FOO' } ], + [ '?spoo~' => { } ], + [ '?@spoo~' => { spoo => [] } ], + [ '?bar=' => { bar => 'BAR2' } ], + [ '?@bar=' => { bar => [ qw(BAR1 BAR2) ] } ], + [ '?foo=&@bar=' => { foo => 'FOO', bar => [ qw(BAR1 BAR2) ] } ], + [ '?baz=&evil=' => { baz => 'one two', evil => '/' } ], + [ '?*' => \%all_single ], + [ '?@*' => \%all_multi ], + [ '?foo=&@*' => { %all_multi, foo => 'FOO' } ], + [ '?@bar=&*' => { %all_single, bar => [ qw(BAR1 BAR2) ] } ], +) { + my ($spec, $res) = @$win; + my $match = $dp->parse_dispatch_specification($spec); +#use Data::Dump::Streamer; warn Dump($match); + is_deeply( + [ $match->({ QUERY_STRING => $q }) ], + [ {}, $res ], + "${spec} matches correctly" + ); +}