X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fdispatch_parser.t;h=f8e7e06cb6a0976f26b6e8ab687b1ca395bda0ef;hb=eb9e0e25ce6999be81b80424ccb16d04966debed;hp=28da3b81ec0d3d0776117c4c53ebb9f2bca668ed;hpb=da8429c93d5e013a72456da945681cb2a84aaf80;p=catagits%2FWeb-Simple.git diff --git a/t/dispatch_parser.t b/t/dispatch_parser.t index 28da3b8..f8e7e06 100644 --- a/t/dispatch_parser.t +++ b/t/dispatch_parser.t @@ -220,3 +220,69 @@ is_deeply( [], '/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 => [ '/' ], +); + +foreach my $lose ('?foo=','?:foo=','?@foo=','?:@foo=') { + my $foo = $dp->parse_dispatch_specification($lose); + + is_deeply( + [ $foo->({ QUERY_STRING => '' }) ], + [], + "${lose} fails with no query" + ); + + is_deeply( + [ $foo->({ QUERY_STRING => 'bar=baz' }) ], + [], + "${lose} fails with query missing foo key" + ); +} + +foreach my $win ( + [ '?foo=' => 'FOO' ], + [ '?:foo=' => { foo => 'FOO' } ], + [ '?spoo~' => undef ], + [ '?:spoo~' => {} ], + [ '?@spoo~' => [] ], + [ '?:@spoo~' => { spoo => [] } ], + [ '?bar=' => 'BAR2' ], + [ '?:bar=' => { bar => 'BAR2' } ], + [ '?@bar=' => [ qw(BAR1 BAR2) ] ], + [ '?:@bar=' => { bar => [ qw(BAR1 BAR2) ] } ], + [ '?foo=&@bar=' => 'FOO', [ qw(BAR1 BAR2) ] ], + [ '?foo=&:@bar=' => 'FOO', { bar => [ qw(BAR1 BAR2) ] } ], + [ '?:foo=&:@bar=' => { foo => 'FOO', bar => [ qw(BAR1 BAR2) ] } ], + [ '?:baz=&:evil=' => { baz => 'one two', evil => '/' } ], + [ '?*' => \%all_single ], + [ '?@*' => \%all_multi ], + [ '?foo=&@*' => 'FOO', do { my %h = %all_multi; delete $h{foo}; \%h } ], + [ '?: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" + ); +}