X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fdispatch_parser.t;fp=t%2Fdispatch_parser.t;h=f8e7e06cb6a0976f26b6e8ab687b1ca395bda0ef;hb=eb9e0e25ce6999be81b80424ccb16d04966debed;hp=a001b4195c0d361220ead78437730305a986e903;hpb=92e23550709cc075dd06e14d50dc302d0b405977;p=catagits%2FWeb-Simple.git diff --git a/t/dispatch_parser.t b/t/dispatch_parser.t index a001b41..f8e7e06 100644 --- a/t/dispatch_parser.t +++ b/t/dispatch_parser.t @@ -240,33 +240,49 @@ my %all_multi = ( evil => [ '/' ], ); -my $foo = $dp->parse_dispatch_specification('?foo='); +foreach my $lose ('?foo=','?:foo=','?@foo=','?:@foo=') { + my $foo = $dp->parse_dispatch_specification($lose); -is_deeply( - [ $foo->({ QUERY_STRING => '' }) ], - [], - '?foo= fails with no query' -); + 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' } ], - [ '?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 => '/' } ], + [ '?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=&@*' => { %all_multi, foo => 'FOO' } ], - [ '?@bar=&*' => { %all_single, bar => [ qw(BAR1 BAR2) ] } ], + [ '?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 ($spec, @res) = @$win; my $match = $dp->parse_dispatch_specification($spec); #use Data::Dump::Streamer; warn Dump($match); is_deeply( [ $match->({ QUERY_STRING => $q }) ], - [ {}, $res ], + [ {}, @res ], "${spec} matches correctly" ); }