added failing todo test for empty dispatch prototype
[catagits/Web-Simple.git] / t / dispatch_parser.t
index 8405d7d..d0b8db4 100644 (file)
@@ -7,6 +7,27 @@ use Web::Dispatch::Parser;
 
 my $dp = Web::Dispatch::Parser->new;
 
+TODO: {
+   local $TODO = 'according to the synopsis this should work';
+   my $all = eval {
+     $dp->parse('');
+   };
+   ok $all;
+   eval {
+     is_deeply(
+       [ $all->({ REQUEST_METHOD => 'GET' }) ],
+       [ {} ],
+       'GET matches'
+     );
+
+     is_deeply(
+       [ $all->({ REQUEST_METHOD => 'POST' }) ],
+       [ {} ],
+       'POST matches'
+     );
+   };
+};
+
 {
    my $get = $dp->parse('GET');
 
@@ -23,17 +44,12 @@ my $dp = Web::Dispatch::Parser->new;
    );
 }
 
-ok(
-  !eval { $dp->parse('GET POST'); 1; },
-  "Don't yet allow two methods"
-);
-
 {
    my $html = $dp->parse('.html');
 
    is_deeply(
      [ $html->({ PATH_INFO => '/foo/bar.html' }) ],
-     [ { PATH_INFO => '/foo/bar' } ],
+     [ { } ],
      '.html matches'
    );
 
@@ -49,7 +65,7 @@ ok(
 
    is_deeply(
      [ $any_ext->({ PATH_INFO => '/foo/bar.html' }) ],
-     [ { PATH_INFO => '/foo/bar' }, 'html' ],
+     [ { }, 'html' ],
      '.html matches .* and extension returned'
    );
 
@@ -90,6 +106,12 @@ ok(
      [],
      '/post/one/ does not match'
    );
+
+   is_deeply(
+     [ $post->({ PATH_INFO => '/post/one.html' }) ],
+     [ {}, 'one' ],
+     '/post/one.html still parses out one'
+   );
 }
 
 {
@@ -219,7 +241,7 @@ ok(
 
    is_deeply(
      [ $not->({ PATH_INFO => '/foo.xml' }) ],
-     [ { PATH_INFO => '/foo' }, 'xml' ],
+     [ {}, 'xml' ],
      '!.html+.* matches /foo.xml'
    );
 
@@ -258,6 +280,23 @@ ok(
    );
 }
 
+{
+  my @dot_pairs = (
+    [ '/one/*' => 'two' ],
+    [ '/one/*.*' => 'two.three' ],
+    [ '/**' => 'one/two' ],
+    [ '/**.*' => 'one/two.three' ],
+  );
+
+  foreach my $p (@dot_pairs) {
+    is_deeply(
+      [ $dp->parse($p->[0])->({ PATH_INFO => '/one/two.three' }) ],
+      [ {}, $p->[1] ],
+      "${\$p->[0]} matches /one/two.three and returns ${\$p->[1]}"
+    );
+  }
+}
+
 #
 # query string
 #
@@ -314,7 +353,7 @@ foreach my $win (
     [ '?:baz=&:evil=' => { baz => 'one two', evil => '/' } ],
     [ '?*' => \%all_single ],
     [ '?@*' => \%all_multi ],
-    [ '?foo=&@*' => 'FOO', do { my %h = %all_multi; delete $h{foo}; \%h } ],
+    [ '?foo=&@*' => 'FOO', \%all_multi ],
     [ '?:foo=&@*' => { %all_multi, foo => 'FOO' } ],
     [ '?:@bar=&*' => { %all_single, bar => [ qw(BAR1 BAR2) ] } ],
 ) {
@@ -365,7 +404,7 @@ foreach my $win2 (
     [ '/foo/bar/+?:baz=&:evil=' => { baz => 'one two', evil => '/' } ],
     [ '/foo/bar/+?*' => \%all_single ],
     [ '/foo/bar/+?@*' => \%all_multi ],
-    [ '/foo/bar/+?foo=&@*' => 'FOO', do { my %h = %all_multi; delete $h{foo}; \%h } ],
+    [ '/foo/bar/+?foo=&@*' => 'FOO', \%all_multi ],
     [ '/foo/bar/+?:foo=&@*' => { %all_multi, foo => 'FOO' } ],
     [ '/foo/bar/+?:@bar=&*' => { %all_single, bar => [ qw(BAR1 BAR2) ] } ],
 ) {
@@ -416,7 +455,7 @@ foreach my $win3 (
     [ '/foo/bar+?:baz=&:evil=' => { baz => 'one two', evil => '/' } ],
     [ '/foo/bar+?*' => \%all_single ],
     [ '/foo/bar+?@*' => \%all_multi ],
-    [ '/foo/bar+?foo=&@*' => 'FOO', do { my %h = %all_multi; delete $h{foo}; \%h } ],
+    [ '/foo/bar+?foo=&@*' => 'FOO', \%all_multi ],
     [ '/foo/bar+?:foo=&@*' => { %all_multi, foo => 'FOO' } ],
     [ '/foo/bar+?:@bar=&*' => { %all_single, bar => [ qw(BAR1 BAR2) ] } ],
 ) {