fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-02-28 01:57 pm

[dw-free] t/routing.t is getting quite large, split it up.

[commit: http://hg.dwscoalition.org/dw-free/rev/f99de538b3ec]

http://bugs.dwscoalition.org/show_bug.cgi?id=3548

Split up routing tests into smaller tests. Also, make sure that when testing
errors, we don't wrap it in site scheme.

Patch by [personal profile] exor674.

Files modified:
  • cgi-bin/DW/Routing.pm
  • cgi-bin/DW/Routing/Test.pm
  • t/routing-errors.t
  • t/routing-formats.t
  • t/routing-indexes.t
  • t/routing-methods.t
  • t/routing-roles-regex.t
  • t/routing-roles-string.t
  • t/routing-table.t
  • t/routing.t
--------------------------------------------------------------------------------
diff -r f199a27c29c2 -r f99de538b3ec cgi-bin/DW/Routing.pm
--- a/cgi-bin/DW/Routing.pm	Mon Feb 28 21:29:57 2011 +0800
+++ b/cgi-bin/DW/Routing.pm	Mon Feb 28 21:38:05 2011 +0800
@@ -8,7 +8,7 @@
 #      Andrea Nall <anall@andreanall.com>
 #      Mark Smith <mark@dreamwidth.org>
 #
-# Copyright (c) 2009-2010 by Dreamwidth Studios, LLC.
+# Copyright (c) 2009-2011 by Dreamwidth Studios, LLC.
 #
 # This program is free software; you may redistribute it and/or modify it under
 # the same terms as Perl itself.  For a copy of the license, please reference
@@ -30,6 +30,8 @@ our %regex_choices = (
     ssl  => [],
     user => []
 );
+
+our $T_TESTING_ERRORS;
 
 my $default_content_types = {
     'html' => "text/html; charset=utf-8",
@@ -182,7 +184,10 @@ sub _call_hash {
 
     my $err = LJ::errobj( $msg )
         or die "LJ::errobj didn't return anything.";
-    $err->log;
+    unless ( $T_TESTING_ERRORS ) {
+        $err->log;
+        warn "$msg";
+    }
 
     # JSON error rendering
     if ( $format eq 'json' ) {
@@ -199,19 +204,22 @@ sub _call_hash {
 
         chomp $msg;
         $msg .= " \@ $LJ::SERVER_NAME" if $LJ::SERVER_NAME;
-        warn "$msg\n";
 
         $r->status( 500 );
         my $text = $LJ::MSG_ERROR || "Sorry, there was a problem.";
         my $remote = LJ::get_remote();
         $text = "<b>[Error: $msg]</b>" if ( $remote && $remote->show_raw_errors ) || $LJ::IS_DEV_SERVER;
-        return DW::Template->render_string( $text, { status=>500, content_type=>'text/html' } );
+
+        my $opts = { status=>500, content_type=>'text/html' };
+
+        $opts->{no_sitescheme} = 1 if $T_TESTING_ERRORS;
+
+        return DW::Template->render_string( $text, $opts );
     } else {
         $msg = $err->as_string;
 
         chomp $msg;
         $msg .= " \@ $LJ::SERVER_NAME" if $LJ::SERVER_NAME;
-        warn "$msg\n";
 
         my $text = $LJ::MSG_ERROR || "Sorry, there was a problem.";
         my $remote = LJ::get_remote();
diff -r f199a27c29c2 -r f99de538b3ec cgi-bin/DW/Routing/Test.pm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/DW/Routing/Test.pm	Mon Feb 28 21:38:05 2011 +0800
@@ -0,0 +1,236 @@
+#!/usr/bin/perl
+#
+# DW::Routing::Test
+#
+# Testing class for DW::Routing core tests
+#
+# Authors:
+#      Andrea Nall <anall@andreanall.com>
+#
+# Copyright (c) 2011 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+package DW::Routing::Test;
+use strict;
+
+require 'ljlib.pl';
+use DW::Request::Standard;
+use HTTP::Request;
+
+use Test::Builder::Module;
+our @ISA    = qw(Test::Builder::Module);
+our @EXPORT = qw(
+    begin_tests got_result expected_format
+    handle_request handle_server_error handle_redirect
+    handler regex_handler
+    okay is todo_skip skip
+    $TODO
+);
+
+my $CLASS = __PACKAGE__;
+
+my $Test = $CLASS->builder;
+
+my $caller = undef;
+
+sub import_extra {
+    my ( $self, $data ) = @_;
+
+    my %args = @$data;
+
+    $args{tests}++ if exists $args{tests};
+
+    $DW::Routing::DONT_LOAD = 1 unless $args{load_table};
+
+    @$data = %args;
+
+    require DW::Routing;
+    DW::Routing->import;
+    $DW::Routing::T_TESTING_ERRORS = 1;
+}
+
+sub begin_tests {
+    my $ct = scalar keys %DW::Routing::string_choices;
+
+    $ct += scalar @$_ foreach values %DW::Routing::regex_choices;
+
+    $Test->is_eq( $ct, 0, "routing table empty" );
+}
+
+my $expected_format = 'html';
+my $result;
+
+sub expected_format { $expected_format = $_[0]; }
+
+sub got_result {
+    $result = $_[0];
+}
+
+sub handle_request {
+    my ( $name, $uri, $valid, $expected, %opts ) = @_;
+    $CLASS->builder->subtest($name, sub {
+        DW::Request->reset;
+
+        my $tb = $CLASS->builder;
+        $tb->plan( tests => 3 );
+
+        my $method = $opts{method} || 'GET';
+
+        my $req = HTTP::Request->new($method=>"$uri");
+        my $r = DW::Request::Standard->new($req);
+
+        my $ret;
+        my $fail = 0;
+        subtest("handler call", sub {
+            $ret = DW::Routing->call( %opts );
+            if ( $tb->current_test == 0 ) {
+                plan( tests => 1 );
+                ok( 1, "no tests to run" );
+            } else {
+                $fail = ! $tb->is_passing;
+            }
+        });
+
+        if ( $fail ) {
+            _skip("overall failure");
+            _skip("overall failure");
+            return 1;
+        }
+
+        if ( ! $valid ) {
+            ok( ! defined $ret , "return value defined when invalid" );
+            _skip("non-valid test");
+            return 1;
+        }
+
+        my $expected_ret = $opts{expected_error} || $r->OK;
+        is( $ret, $expected_ret, "wrong return" );
+        if ( $ret != $r->OK ) {
+            _skip("non-expected return");
+            return 0;
+        }
+        is( $result, $expected, "handler set wrong value.");
+    });
+}
+
+sub handle_redirect {
+    my ( $uri, $expected ) = @_;
+    my $tb = $CLASS->builder;
+    $CLASS->builder->subtest($uri, sub {
+        my $req = HTTP::Request->new(GET=>"$uri");
+
+        my $opts = DW::Routing->get_call_opts( uri => $uri );
+
+        unless ( $opts ) {
+            ok( 0, "opts exists" );
+            _skip("opts is undef");
+            return;
+        }
+
+        my $hash = $opts->call_opts;
+        
+        unless ( $hash && $hash->{sub} ) {
+             ok( 0, "improper opts" );
+             _skip("opts are improper");
+        }
+
+        is( $hash->{sub}, \&DW::Routing::_redirect_helper );
+        is( $hash->{args}, $expected );
+    });
+}
+
+sub handle_server_error {
+    my ( $name, $uri, $format, %opts ) = @_;
+    my $tb = $CLASS->builder;
+    $CLASS->builder->subtest($name, sub {
+        DW::Request->reset;
+
+        my $tb = $CLASS->builder;
+        $tb->plan( tests => 3 );
+
+        my $method = $opts{method} || 'GET';
+
+        my $req = HTTP::Request->new($method=>"$uri");
+        my $r = DW::Request::Standard->new($req);
+
+        my $ret;
+        my $fail = 0;
+        subtest("handler call", sub {
+            eval { $ret = DW::Routing->call( %opts ) };
+            if ( ! defined $ret ) {
+                plan( tests => 1 );
+                ok( 0, "test did not run" );
+                $fail = 1;
+            } elsif ( $tb->current_test == 0 ) {
+                plan( tests => 1 );
+                ok( 1, "no tests to run" );
+            } else {
+                $fail = ! $tb->is_passing;
+            }
+        });
+
+        if ( $fail ) {
+            _skip("overall failure");
+            _skip("overall failure");
+            return 1;
+        }
+
+        my $content_type = $r->content_type;
+        is( $r->status, $r->HTTP_SERVER_ERROR, "wrong return" );
+        is( $content_type, {
+            html => "text/html",
+            json => "application/json",
+        }->{$format} || "text/plain", "wrong returned content type for $format" );
+    });
+}
+
+
+sub handler {
+    my $r = DW::Request->get;
+    got_result( $_[0]->args );
+    is( $_[0]->format, $expected_format, "format wrong!" );
+    return $r->OK;
+}
+
+sub regex_handler {
+    my $r = DW::Request->get;
+    got_result( $_[0]->args->[1] );
+    is ( $_[0]->format, $expected_format, "format wrong!" );
+    is( $_[0]->subpatterns->[0], $_[0]->args->[0], "capture wrong!" );
+    return $r->OK;
+}
+
+sub _skip { return $CLASS->builder->skip(@_); }
+
+sub subtest { return $CLASS->builder->subtest(@_); }
+sub plan { return $CLASS->builder->plan(@_); }
+sub ok { return $CLASS->builder->ok(@_); }
+sub is { return $CLASS->builder->is_eq(@_); }
+
+sub skip {
+    my( $why, $how_many ) = @_;
+    my $tb = $CLASS->builder;
+
+    $how_many = 1 unless defined $how_many;
+    $tb->skip($why) for( 1 .. $how_many );
+
+    no warnings 'exiting';
+    last SKIP;
+}
+
+sub todo_skip {
+    my( $why, $how_many ) = @_;
+    my $tb = $CLASS->builder;
+
+    $how_many = 1 unless defined $how_many;
+    $tb->todo_skip($why) for( 1 .. $how_many );
+
+    no warnings 'exiting';
+    last TODO;
+}
+
+
+1;
\ No newline at end of file
diff -r f199a27c29c2 -r f99de538b3ec t/routing-errors.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/routing-errors.t	Mon Feb 28 21:38:05 2011 +0800
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+#
+# t/routing-errors.t
+#
+# Routing tests: Error pages
+#
+# Authors:
+#      Andrea Nall <anall@andreanall.com>
+#
+# Copyright (c) 2011 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+use strict;
+
+use lib "$ENV{LJHOME}/cgi-bin";
+use DW::Routing::Test tests => 4;
+
+$DW::Routing::T_TESTING_ERRORS = 1;
+
+expected_format('html');
+
+begin_tests();
+
+DW::Routing->register_string( "/test/die/all_format", \&died_handler, app => 1, formats => 1 );
+
+handle_server_error( "/test die implied_format (app)", "/test/die/all_format", "html" );
+handle_server_error( "/test die .json format (app)", "/test/die/all_format.json", "json" );
+handle_server_error( "/test die .html format (app)", "/test/die/all_format.html", "html" );
+handle_server_error( "/test die .blah format (app)", "/test/die/all_format.blah", "blah" );
+# 4
+
+sub died_handler {
+    die "deliberate die()";
+}
diff -r f199a27c29c2 -r f99de538b3ec t/routing-formats.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/routing-formats.t	Mon Feb 28 21:38:05 2011 +0800
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+#
+# t/routing-formats.t
+#
+# Routing tests: Formats
+#
+# Authors:
+#      Andrea Nall <anall@andreanall.com>
+#
+# Copyright (c) 2011 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+use strict;
+
+use lib "$ENV{LJHOME}/cgi-bin";
+use DW::Routing::Test tests => 12;
+
+expected_format('html');
+
+begin_tests();
+
+DW::Routing->register_string( "/test/all", \&handler, app => 1, user => 1, ssl => 1, format => 'json', args => "it_worked_multi", formats => [ 'json', 'format' ] );
+
+expected_format('json');
+handle_request( "/test all json (app)" , "/test/all", 1, "it_worked_multi");
+handle_request( "/test all json (ssl)" , "/test/all", 1, "it_worked_multi", ssl => 1 );
+handle_request( "/test all json (user)", "/test/all", 1, "it_worked_multi", username => 'test' );
+
+expected_format('format');
+handle_request( "/test all format (app)" , "/test/all.format", 1, "it_worked_multi");
+handle_request( "/test all format (ssl)" , "/test/all.format", 1, "it_worked_multi", ssl => 1 );
+handle_request( "/test all format (user)", "/test/all.format", 1, "it_worked_multi", username => 'test' );
+# 6
+
+DW::Routing->register_string( "/test/app", \&handler, app => 1, args => "it_worked_app", formats => [ 'html', 'format' ] );
+DW::Routing->register_regex( qr !^/r/app(/.+)$!, \&regex_handler, app => 1, args => ["/test", "it_worked_app"], formats => [ 'html', 'format' ] );
+
+expected_format('json');
+handle_request( "/test app (app) invalid" , "/test/app.json", 1, undef, expected_error => 404 );
+handle_request( "/r/app (app) invalid" , "/r/app/test.json", 1, undef, expected_error => 404 );
+# 8
+
+DW::Routing->register_string( "/test/app/implied_format", \&handler, app => 1, args => "it_worked_app_if" );
+
+expected_format('html');
+handle_request( "/test app implied_format (app)" , "/test/app/implied_format", 1, "it_worked_app_if" );
+
+expected_format('json');
+handle_request( "/test app implied_format (app) invalid" , "/test/app/implied_format.json", 1, undef, expected_error => 404 );
+# 10
+
+# test all formats
+DW::Routing->register_string( "/test/app/all_format", \&handler, app => 1, args => "it_worked_app_af", formats => 1 );
+
+expected_format('html');
+handle_request( "/test app implied_format (app)" , "/test/app/all_format", 1, "it_worked_app_af" ); # 3 tests
+
+expected_format('json');
+handle_request( "/test app implied_format (app)" , "/test/app/all_format.json", 1, "it_worked_app_af" ); # 3 test
+# 12
diff -r f199a27c29c2 -r f99de538b3ec t/routing-indexes.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/routing-indexes.t	Mon Feb 28 21:38:05 2011 +0800
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+#
+# t/routing-formats.t
+#
+# Routing tests: /index pages
+#
+# Authors:
+#      Andrea Nall <anall@andreanall.com>
+#
+# Copyright (c) 2011 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+use strict;
+
+use lib "$ENV{LJHOME}/cgi-bin";
+use DW::Routing::Test tests => 5;
+
+$DW::Routing::T_TESTING_ERRORS = 1;
+
+expected_format('html');
+
+begin_tests();
+
+DW::Routing->register_string( "/xx3/index", \&handler, app => 1, args => "it_worked_redir" );
+
+handle_request( "/xx3/" , "/xx3/", 1, "it_worked_redir" );
+handle_request( "/xx3/index" , "/xx3/index", 1, "it_worked_redir" );
+handle_redirect( '/xx3', '/xx3/' );
+# 3
+
+DW::Routing->register_string( "/index", \&handler, app => 1, args => "it_worked_redir" );
+
+TODO: {
+      local $TODO = "This doesn't acutally work yet";
+
+      handle_request( "/" , "/", 1, "it_worked_redir" );
+};
+handle_request( "/index" , "/index", 1, "it_worked_redir" );
+# 5
diff -r f199a27c29c2 -r f99de538b3ec t/routing-methods.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/routing-methods.t	Mon Feb 28 21:38:05 2011 +0800
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+#
+# t/routing-methods.t
+#
+# Routing tests: Methods
+#
+# Authors:
+#      Andrea Nall <anall@andreanall.com>
+#
+# Copyright (c) 2011 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+use strict;
+
+use lib "$ENV{LJHOME}/cgi-bin";
+use DW::Routing::Test tests => 4;
+
+$DW::Routing::T_TESTING_ERRORS = 1;
+
+expected_format('html');
+
+begin_tests();
+
+DW::Routing->register_string( "/test/die/all_format", \&died_handler, app => 1, formats => 1 );
+
+handle_server_error( "/test die implied_format (app)", "/test/die/all_format", "html" );
+handle_server_error( "/test die .json format (app)", "/test/die/all_format.json", "json" );
+handle_server_error( "/test die .html format (app)", "/test/die/all_format.html", "html" );
+handle_server_error( "/test die .blah format (app)", "/test/die/all_format.blah", "blah" );
+# 4
diff -r f199a27c29c2 -r f99de538b3ec t/routing-roles-regex.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/routing-roles-regex.t	Mon Feb 28 21:38:05 2011 +0800
@@ -0,0 +1,103 @@
+#!/usr/bin/perl
+#
+# t/routing-roles-regex.t
+#
+# Routing tests: Regex roles
+#
+# Authors:
+#      Andrea Nall <anall@andreanall.com>
+#
+# Copyright (c) 2011 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+use strict;
+
+use lib "$ENV{LJHOME}/cgi-bin";
+use DW::Routing::Test tests => 36;
+
+expected_format('html');
+
+begin_tests();
+
+DW::Routing->register_regex( qr !^/r/app(/.+)$!, \&regex_handler, app => 1, args => ["/test", "it_worked_app"], formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/r/app (app)" , "/r/app/test", 1, "it_worked_app" ); # 3 tests
+handle_request( "/r/app (ssl)" , "/r/app/test", 0, "it_worked_app", ssl => 1 ); # 1 test
+handle_request( "/r/app (user)", "/r/app/test", 0, "it_worked_app", username => 'test' ); # 1 test
+
+expected_format('format');
+handle_request( "/r/app (app)" , "/r/app/test.format", 1, "it_worked_app" ); # 3 tests
+handle_request( "/r/app (ssl)" , "/r/app/test.format", 0, "it_worked_app", ssl => 1 ); # 1 test
+handle_request( "/r/app (user)", "/r/app/test.format", 0, "it_worked_app", username => 'test' ); # 1 test
+# 6
+
+DW::Routing->register_regex( qr !^/r/ssl(/.+)$!, \&regex_handler, ssl => 1, app => 0, args => ["/test", "it_worked_ssl"], formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/r/ssl (app)" , "/r/ssl/test", 0, "it_worked_ssl" ); # 1 tests
+handle_request( "/r/ssl (ssl)" , "/r/ssl/test", 1, "it_worked_ssl", ssl => 1 ); # 3 tests
+handle_request( "/r/ssl (user)", "/r/ssl/test", 0, "it_worked_ssl", username => 'test' ); # 1 test
+
+expected_format('format');
+handle_request( "/r/ssl (app)" , "/r/ssl/test.format", 0, "it_worked_ssl" ); # 1 tests
+handle_request( "/r/ssl (ssl)" , "/r/ssl/test.format", 1, "it_worked_ssl", ssl => 1 ); # 3 tests
+handle_request( "/r/ssl (user)", "/r/ssl/test.format", 0, "it_worked_ssl", username => 'test' ); # 1 test
+# 12
+
+DW::Routing->register_regex( qr !^/r/user(/.+)$!, \&regex_handler, user => 1, args => ["/test", "it_worked_user"], formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/r/user (app)" , "/r/user/test", 0, "it_worked_user" ); # 1 tests
+handle_request( "/r/user (ssl)" , "/r/user/test", 0, "it_worked_user", ssl => 1 ); # 1 test
+handle_request( "/r/user (user)", "/r/user/test", 1, "it_worked_user", username => 'test' ); # 3 tests
+
+expected_format('format');
+handle_request( "/r/user (app)" , "/r/user/test.format", 0, "it_worked_user" ); # 1 tests
+handle_request( "/r/user (ssl)" , "/r/user/test.format", 0, "it_worked_user", ssl => 1 ); # 1 test
+handle_request( "/r/user (user)", "/r/user/test.format", 1, "it_worked_user", username => 'test' ); # 3 tests
+# 18
+
+DW::Routing->register_regex( qr !^/r/multi(/.+)$!, \&regex_handler, app => 1, args => ["/test", "it_worked_app"], formats => [ 'html', 'format' ] );
+DW::Routing->register_regex( qr !^/r/multi(/.+)$!, \&regex_handler, ssl => 1, app => 0, args => ["/test", "it_worked_ssl"], formats => [ 'html', 'format' ] );
+DW::Routing->register_regex( qr !^/r/multi(/.+)$!, \&regex_handler, user => 1, args => ["/test", "it_worked_user"], formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/r/multi (app)" , "/r/multi/test", 1, "it_worked_app" ); # 3 tests
+handle_request( "/r/multi (ssl)" , "/r/multi/test", 1, "it_worked_ssl", ssl => 1 ); # 3 tests
+handle_request( "/r/multi (user)", "/r/multi/test", 1, "it_worked_user", username => 'test' ); # 3 tests
+
+expected_format('format');
+handle_request( "/r/multi (app)" , "/r/multi/test.format", 1, "it_worked_app" ); # 3 tests
+handle_request( "/r/multi (ssl)" , "/r/multi/test.format", 1, "it_worked_ssl", ssl => 1 ); # 3 tests
+handle_request( "/r/multi (user)", "/r/multi/test.format", 1, "it_worked_user", username => 'test' ); # 3 tests
+# 24
+
+DW::Routing->register_regex( qr !^/r/all(/.+)$!, \&regex_handler, app => 1, user => 1, ssl => 1, format => 'html', args => ["/test", "it_worked_all"], formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/r/all (app)" , "/r/all/test", 1, "it_worked_all" ); # 3 tests
+handle_request( "/r/all (ssl)" , "/r/all/test", 1, "it_worked_all", ssl => 1 ); # 3 tests
+handle_request( "/r/all (user)", "/r/all/test", 1, "it_worked_all", username => 'test' ); # 3 tests
+
+expected_format('format');
+handle_request( "/r/all (app)" , "/r/all/test.format", 1, "it_worked_all" ); # 3 tests
+handle_request( "/r/all (ssl)" , "/r/all/test.format", 1, "it_worked_all", ssl => 1 ); # 3 tests
+handle_request( "/r/all (user)", "/r/all/test.format", 1, "it_worked_all", username => 'test' ); # 3 tests
+# 30
+
+DW::Routing->register_regex( qr !^/r/app_implicit(/.+)$!, \&regex_handler, args => ["/test", "it_worked_app"], formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/r/app_implicit (app)" , "/r/app_implicit/test", 1, "it_worked_app" ); # 3 tests
+handle_request( "/r/app_implicit (ssl)" , "/r/app_implicit/test", 0, "it_worked_app", ssl => 1 ); # 1 test
+handle_request( "/r/app_implicit (user)", "/r/app_implicit/test", 0, "it_worked_app", username => 'test' ); # 1 test
+
+expected_format('format');
+handle_request( "/r/app_implicit (app)" , "/r/app_implicit/test.format", 1, "it_worked_app" ); # 3 tests
+handle_request( "/r/app_implicit (ssl)" , "/r/app_implicit/test.format", 0, "it_worked_app", ssl => 1 ); # 1 test
+handle_request( "/r/app_implicit (user)", "/r/app_implicit/test.format", 0, "it_worked_app", username => 'test' ); # 1 test
+# 36
diff -r f199a27c29c2 -r f99de538b3ec t/routing-roles-string.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/routing-roles-string.t	Mon Feb 28 21:38:05 2011 +0800
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+#
+# t/routing-roles-string.t
+#
+# Routing tests: String roles
+#
+# Authors:
+#      Andrea Nall <anall@andreanall.com>
+#
+# Copyright (c) 2011 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+use strict;
+
+use lib "$ENV{LJHOME}/cgi-bin";
+use DW::Routing::Test tests => 36;
+
+expected_format('html');
+
+begin_tests();
+
+DW::Routing->register_string( "/test/app", \&handler, app => 1, args => "it_worked_app", formats => [ 'html', 'format' ] );
+
+handle_request( "/test app (app)" , "/test/app", 1, "it_worked_app" );
+handle_request( "/test app (ssl)" , "/test/app", 0, "it_worked_app", ssl => 1 );
+handle_request( "/test app (user)", "/test/app", 0, "it_worked_app", username => 'test' );
+
+expected_format('format');
+handle_request( "/test app (app)" , "/test/app.format", 1, "it_worked_app" );
+handle_request( "/test app (ssl)" , "/test/app.format", 0, "it_worked_app", ssl => 1 );
+handle_request( "/test app (user)", "/test/app.format", 0, "it_worked_app", username => 'test' );
+# 6
+
+DW::Routing->register_string( "/test/ssl", \&handler, ssl => 1, app => 0, args => "it_worked_ssl", formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/test ssl (app)" , "/test/ssl", 0, "it_worked_ssl" );
+handle_request( "/test ssl (ssl)" , "/test/ssl", 1, "it_worked_ssl", ssl => 1 );
+handle_request( "/test ssl (user)", "/test/ssl", 0, "it_worked_ssl", username => 'test' );
+
+expected_format('format');
+handle_request( "/test ssl (app)" , "/test/ssl.format", 0, "it_worked_ssl" );
+handle_request( "/test ssl (ssl)" , "/test/ssl.format", 1, "it_worked_ssl", ssl => 1 );
+handle_request( "/test ssl (user)", "/test/ssl.format", 0, "it_worked_ssl", username => 'test' );
+# 12
+
+DW::Routing->register_string( "/test/user", \&handler, user => 1, args => "it_worked_user", formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/test user (app)" , "/test/user", 0, "it_worked_user" );
+handle_request( "/test user (ssl)" , "/test/user", 0, "it_worked_user", ssl => 1 );
+handle_request( "/test user (user)", "/test/user", 1, "it_worked_user", username => 'test' );
+
+expected_format('format');
+handle_request( "/test user (app)" , "/test/user.format", 0, "it_worked_user" );
+handle_request( "/test user (ssl)" , "/test/user.format", 0, "it_worked_user", ssl => 1 );
+handle_request( "/test user (user)", "/test/user.format", 1, "it_worked_user", username => 'test' );
+# 18
+
+DW::Routing->register_string( "/test", \&handler, app => 1, args => "it_worked_app", formats => [ 'html', 'format' ] );
+DW::Routing->register_string( "/test", \&handler, ssl => 1, app => 0, args => "it_worked_ssl", formats => [ 'html', 'format' ] );
+DW::Routing->register_string( "/test", \&handler, user => 1, args => "it_worked_user", formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/test multi (app)" , "/test", 1, "it_worked_app" );
+handle_request( "/test multi (ssl)" , "/test", 1, "it_worked_ssl", ssl => 1 );
+handle_request( "/test multi (user)", "/test", 1, "it_worked_user", username => 'test' );
+
+expected_format('format');
+handle_request( "/test multi (app)" , "/test.format", 1, "it_worked_app" );
+handle_request( "/test multi (ssl)" , "/test.format", 1, "it_worked_ssl", ssl => 1 );
+handle_request( "/test multi (user)", "/test.format", 1, "it_worked_user", username => 'test' );
+# 24
+
+DW::Routing->register_string( "/test/all", \&handler, app => 1, user => 1, ssl => 1, args => "it_worked_multi", formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/test all (app)" , "/test/all", 1, "it_worked_multi");
+handle_request( "/test all (ssl)" , "/test/all", 1, "it_worked_multi", ssl => 1 );
+handle_request( "/test all (user)", "/test/all", 1, "it_worked_multi", username => 'test' );
+
+expected_format('format');
+handle_request( "/test all (app)" , "/test/all.format", 1, "it_worked_multi");
+handle_request( "/test all (ssl)" , "/test/all.format", 1, "it_worked_multi", ssl => 1 );
+handle_request( "/test all (user)", "/test/all.format", 1, "it_worked_multi", username => 'test' );
+# 30
+
+DW::Routing->register_string( "/test/app_implicit", \&handler, args => "it_worked_app", formats => [ 'html', 'format' ] );
+
+expected_format('html');
+handle_request( "/test app_implicit (app)" , "/test/app_implicit", 1, "it_worked_app" );
+handle_request( "/test app_implicit (ssl)" , "/test/app_implicit", 0, "it_worked_app", ssl => 1 );
+handle_request( "/test app_implicit (user)", "/test/app_implicit", 0, "it_worked_app", username => 'test' );
+
+expected_format('format');
+handle_request( "/test app_implicit (app)" , "/test/app_implicit.format", 1, "it_worked_app" );
+handle_request( "/test app_implicit (ssl)" , "/test/app_implicit.format", 0, "it_worked_app", ssl => 1 );
+handle_request( "/test app_implicit (user)", "/test/app_implicit.format", 0, "it_worked_app", username => 'test' );
+# 36
diff -r f199a27c29c2 -r f99de538b3ec t/routing-table.t
--- a/t/routing-table.t	Mon Feb 28 21:29:57 2011 +0800
+++ b/t/routing-table.t	Mon Feb 28 21:38:05 2011 +0800
@@ -17,4 +17,4 @@ use Test::More tests => 6;
 use Test::More tests => 6;
 use lib "$ENV{LJHOME}/cgi-bin";
 require 'ljlib.pl';
-require $LJ::HOME . "/t/bin/routing-table-helper.pl";
\ No newline at end of file
+require $LJ::HOME . "/t/bin/routing-table-helper.pl";
diff -r f199a27c29c2 -r f99de538b3ec t/routing.t
--- a/t/routing.t	Mon Feb 28 21:29:57 2011 +0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,373 +0,0 @@
-#!/usr/bin/perl
-#
-# t/routing.t
-#
-# Test to make sure routing works as expected.
-#
-# Authors:
-#      Andrea Nall <anall@andreanall.com>
-#
-# Copyright (c) 2009-2010 by Dreamwidth Studios, LLC.
-#
-# This program is free software; you may redistribute it and/or modify it under
-# the same terms as Perl itself.  For a copy of the license, please reference
-# 'perldoc perlartistic' or 'perldoc perlgpl'.
-#
-use strict;
-use Test::More tests => 238;
-use lib "$ENV{LJHOME}/cgi-bin";
-
-# don't let DW::Routing load DW::Controller subclasses
-BEGIN {
-    $DW::Routing::DONT_LOAD = 1;
-}
-
-require 'ljlib.pl';
-use DW::Request::Standard;
-use HTTP::Request;
-use DW::Routing;
-
-my $result;
-my $expected_format = 'html';
-my $__name;
-
-my $ct = scalar keys %DW::Routing::string_choices;
-
-$ct += scalar @$_ foreach values %DW::Routing::regex_choices;
-
-is( $ct, 0, "routing table empty" );
-
-handle_request( "foo", "/foo", 0, 0 ); # 1 test
-handle_request( "foo", "/foo.format", 0, 0 ); # 1 test
-# 2
-
-DW::Routing->register_string( "/test/app", \&handler, app => 1, args => "it_worked_app", formats => [ 'html', 'format' ] );
-
-$expected_format = 'html';
-handle_request( "/test app (app)" , "/test/app", 1, "it_worked_app" ); # 3 tests
-handle_request( "/test app (ssl)" , "/test/app", 0, "it_worked_app", ssl => 1 ); # 1 test
-handle_request( "/test app (user)", "/test/app", 0, "it_worked_app", username => 'test' ); # 1 test
-# 7
-
-$expected_format = 'format';
-handle_request( "/test app (app)" , "/test/app.format", 1, "it_worked_app" ); # 3 tests
-handle_request( "/test app (ssl)" , "/test/app.format", 0, "it_worked_app", ssl => 1 ); # 1 test
-handle_request( "/test app (user)", "/test/app.format", 0, "it_worked_app", username => 'test' ); # 1 test
-# 12
-
-DW::Routing->register_string( "/test/ssl", \&handler, ssl => 1, app => 0, args => "it_worked_ssl", formats => [ 'html', 'format' ] );
-
-$expected_format = 'html';
-handle_request( "/test ssl (app)" , "/test/ssl", 0, "it_worked_ssl" ); # 1 tests
-handle_request( "/test ssl (ssl)" , "/test/ssl", 1, "it_worked_ssl", ssl => 1 ); # 1 test
-handle_request( "/test ssl (user)", "/test/ssl", 0, "it_worked_ssl", username => 'test' ); # 3 tests
-# 17
-
-$expected_format = 'format';
-handle_request( "/test ssl (app)" , "/test/ssl.format", 0, "it_worked_ssl" ); # 1 tests
-handle_request( "/test ssl (ssl)" , "/test/ssl.format", 1, "it_worked_ssl", ssl => 1 ); # 1 test
-handle_request( "/test ssl (user)", "/test/ssl.format", 0, "it_worked_ssl", username => 'test' ); # 3 tests
-# 22
-
-DW::Routing->register_string( "/test/user", \&handler, user => 1, args => "it_worked_user", formats => [ 'html', 'format' ] );
-
-$expected_format = 'html';
-handle_request( "/test user (app)" , "/test/user", 0, "it_worked_user" ); # 1 tests
-handle_request( "/test user (ssl)" , "/test/user", 0, "it_worked_user", ssl => 1 ); # 1 test
-handle_request( "/test user (user)", "/test/user", 1, "it_worked_user", username => 'test' ); # 3 tests
-# 27
-
-$expected_format = 'format';
-handle_request( "/test user (app)" , "/test/user.format", 0, "it_worked_user" ); # 1 tests
-handle_request( "/test user (ssl)" , "/test/user.format", 0, "it_worked_user", ssl => 1 ); # 1 test
-handle_request( "/test user (user)", "/test/user.format", 1, "it_worked_user", username => 'test' ); # 3 tests
-# 32
-
-DW::Routing->register_string( "/test", \&handler, app => 1, args => "it_worked_app", formats => [ 'html', 'format' ] );
-DW::Routing->register_string( "/test", \&handler, ssl => 1, app => 0, args => "it_worked_ssl", formats => [ 'html', 'format' ] );
-DW::Routing->register_string( "/test", \&handler, user => 1, args => "it_worked_user", formats => [ 'html', 'format' ] );
-
-$expected_format = 'html';
-handle_request( "/test multi (app)" , "/test", 1, "it_worked_app" ); # 3 tests
-handle_request( "/test multi (ssl)" , "/test", 1, "it_worked_ssl", ssl => 1 ); # 3 tests
-handle_request( "/test multi (user)", "/test", 1, "it_worked_user", username => 'test' ); # 3 tests
-# 41
-
-$expected_format = 'format';
-handle_request( "/test multi (app)" , "/test.format", 1, "it_worked_app" ); # 3 tests
-handle_request( "/test multi (ssl)" , "/test.format", 1, "it_worked_ssl", ssl => 1 ); # 3 tests
-handle_request( "/test multi (user)", "/test.format", 1, "it_worked_user", username => 'test' ); # 3 tests
-# 50
-
-DW::Routing->register_string( "/test/all", \&handler, app => 1, user => 1, ssl => 1, format => 'json', args => "it_worked_multi", formats => [ 'json', 'format' ] );
-
-$expected_format = 'json';
-handle_request( "/test all (app)" , "/test/all", 1, "it_worked_multi"); # 3 tests
-handle_request( "/test all (ssl)" , "/test/all", 1, "it_worked_multi", ssl => 1 ); # 3 tests
-handle_request( "/test all (user)", "/test/all", 1, "it_worked_multi", username => 'test' ); # 3 tests
-# 59
-
-$expected_format = 'format';
-handle_request( "/test all (app)" , "/test/all.format", 1, "it_worked_multi"); # 3 tests
-handle_request( "/test all (ssl)" , "/test/all.format", 1, "it_worked_multi", ssl => 1 ); # 3 tests
-handle_request( "/test all (user)", "/test/all.format", 1, "it_worked_multi", username => 'test' ); # 3 tests
-# 68
-
-DW::Routing->register_regex( qr !^/r/app(/.+)$!, \&regex_handler, app => 1, args => ["/test", "it_worked_app"], formats => [ 'html', 'format' ] );
-
-$expected_format = 'html';
-handle_request( "/r/app (app)" , "/r/app/test", 1, "it_worked_app" ); # 3 tests
-handle_request( "/r/app (ssl)" , "/r/app/test", 0, "it_worked_app", ssl => 1 ); # 1 test
-handle_request( "/r/app (user)", "/r/app/test", 0, "it_worked_app", username => 'test' ); # 1 test
-# 74
-
-$expected_format = 'format';
-handle_request( "/r/app (app)" , "/r/app/test.format", 1, "it_worked_app" ); # 3 tests
-handle_request( "/r/app (ssl)" , "/r/app/test.format", 0, "it_worked_app", ssl => 1 ); # 1 test
-handle_request( "/r/app (user)", "/r/app/test.format", 0, "it_worked_app", username => 'test' ); # 1 test
-# 79
-
-DW::Routing->register_regex( qr !^/r/ssl(/.+)$!, \&regex_handler, ssl => 1, app => 0, args => ["/test", "it_worked_ssl"], formats => [ 'html', 'format' ] );
-
-$expected_format = 'html';
-handle_request( "/r/ssl (app)" , "/r/ssl/test", 0, "it_worked_ssl" ); # 1 tests
-handle_request( "/r/ssl (ssl)" , "/r/ssl/test", 1, "it_worked_ssl", ssl => 1 ); # 3 tests
-handle_request( "/r/ssl (user)", "/r/ssl/test", 0, "it_worked_ssl", username => 'test' ); # 1 test
-# 86
-
-$expected_format = 'format';
-handle_request( "/r/ssl (app)" , "/r/ssl/test.format", 0, "it_worked_ssl" ); # 1 tests
-handle_request( "/r/ssl (ssl)" , "/r/ssl/test.format", 1, "it_worked_ssl", ssl => 1 ); # 3 tests
-handle_request( "/r/ssl (user)", "/r/ssl/test.format", 0, "it_worked_ssl", username => 'test' ); # 1 test
-# 92
-
-DW::Routing->register_regex( qr !^/r/user(/.+)$!, \&regex_handler, user => 1, args => ["/test", "it_worked_user"], formats => [ 'html', 'format' ] );
-
-$expected_format = 'html';
-handle_request( "/r/user (app)" , "/r/user/test", 0, "it_worked_user" ); # 1 tests
-handle_request( "/r/user (ssl)" , "/r/user/test", 0, "it_worked_user", ssl => 1 ); # 1 test
-handle_request( "/r/user (user)", "/r/user/test", 1, "it_worked_user", username => 'test' ); # 3 tests
-# 98
-
-$expected_format = 'format';
-handle_request( "/r/user (app)" , "/r/user/test.format", 0, "it_worked_user" ); # 1 tests
-handle_request( "/r/user (ssl)" , "/r/user/test.format", 0, "it_worked_user", ssl => 1 ); # 1 test
-handle_request( "/r/user (user)", "/r/user/test.format", 1, "it_worked_user", username => 'test' ); # 3 tests
-# 104
-
-DW::Routing->register_regex( qr !^/r/multi(/.+)$!, \&regex_handler, app => 1, args => ["/test", "it_worked_app"], formats => [ 'html', 'format' ] );
-DW::Routing->register_regex( qr !^/r/multi(/.+)$!, \&regex_handler, ssl => 1, app => 0, args => ["/test", "it_worked_ssl"], formats => [ 'html', 'format' ] );
-DW::Routing->register_regex( qr !^/r/multi(/.+)$!, \&regex_handler, user => 1, args => ["/test", "it_worked_user"], formats => [ 'html', 'format' ] );
-
-$expected_format = 'html';
-handle_request( "/r/multi (app)" , "/r/multi/test", 1, "it_worked_app" ); # 3 tests
-handle_request( "/r/multi (ssl)" , "/r/multi/test", 1, "it_worked_ssl", ssl => 1 ); # 3 tests
-handle_request( "/r/multi (user)", "/r/multi/test", 1, "it_worked_user", username => 'test' ); # 3 tests
-# 116
-
-$expected_format = 'format';
-handle_request( "/r/multi (app)" , "/r/multi/test.format", 1, "it_worked_app" ); # 3 tests
-handle_request( "/r/multi (ssl)" , "/r/multi/test.format", 1, "it_worked_ssl", ssl => 1 ); # 3 tests
-handle_request( "/r/multi (user)", "/r/multi/test.format", 1, "it_worked_user", username => 'test' ); # 3 tests
-# 128
-
-DW::Routing->register_regex( qr !^/r/all(/.+)$!, \&regex_handler, app => 1, user => 1, ssl => 1, format => 'json', args => ["/test", "it_worked_all"], formats => [ 'json', 'format' ] );
-
-$expected_format = 'json';
-handle_request( "/r/all (app)" , "/r/all/test", 1, "it_worked_all" ); # 3 tests
-handle_request( "/r/all (ssl)" , "/r/all/test", 1, "it_worked_all", ssl => 1 ); # 3 tests
-handle_request( "/r/all (user)", "/r/all/test", 1, "it_worked_all", username => 'test' ); # 3 tests
-# 140
-
-$expected_format = 'format';
-handle_request( "/r/all (app)" , "/r/all/test.format", 1, "it_worked_all" ); # 3 tests
-handle_request( "/r/all (ssl)" , "/r/all/test.format", 1, "it_worked_all", ssl => 1 ); # 3 tests
-handle_request( "/r/all (user)", "/r/all/test.format", 1, "it_worked_all", username => 'test' ); # 3 tests
-# 152
-
-DW::Routing->register_string( "/test/app_implicit", \&handler, args => "it_worked_app", formats => [ 'html', 'format' ] );
-
-$expected_format = 'html';
-handle_request( "/test appapp_implicit (app)" , "/test/app_implicit", 1, "it_worked_app" ); # 3 tests
-handle_request( "/test appapp_implicit (ssl)" , "/test/app_implicit", 0, "it_worked_app", ssl => 1 ); # 1 test
-handle_request( "/test appapp_implicit (user)", "/test/app_implicit", 0, "it_worked_app", username => 'test' ); # 1 test
-# 157
-
-$expected_format = 'format';
-handle_request( "/test appapp_implicit (app)" , "/test/app_implicit.format", 1, "it_worked_app" ); # 3 tests
-handle_request( "/test appapp_implicit (ssl)" , "/test/app_implicit.format", 0, "it_worked_app", ssl => 1 ); # 1 test
-handle_request( "/test appapp_implicit (user)", "/test/app_implicit.format", 0, "it_worked_app", username => 'test' ); # 1 test
-# 162
-
-DW::Routing->register_regex( qr !^/r/app_implicit(/.+)$!, \&regex_handler, args => ["/test", "it_worked_app"], formats => [ 'html', 'format' ] );
-
-$expected_format = 'html';
-handle_request( "/r/app_implicit (app)" , "/r/app_implicit/test", 1, "it_worked_app" ); # 3 tests
-handle_request( "/r/app_implicit (ssl)" , "/r/app_implicit/test", 0, "it_worked_app", ssl => 1 ); # 1 test
-handle_request( "/r/app_implicit (user)", "/r/app_implicit/test", 0, "it_worked_app", username => 'test' ); # 1 test
-# 168
-
-$expected_format = 'format';
-handle_request( "/r/app_implicit (app)" , "/r/app_implicit/test.format", 1, "it_worked_app" ); # 3 tests
-handle_request( "/r/app_implicit (ssl)" , "/r/app_implicit/test.format", 0, "it_worked_app", ssl => 1 ); # 1 test
-handle_request( "/r/app_implicit (user)", "/r/app_implicit/test.format", 0, "it_worked_app", username => 'test' ); # 1 test
-# 174
-
-# test improper formats
-$expected_format = 'json';
-handle_request( "/test app (app) invalid" , "/test/app.json", 1, undef, expected_error => 404 ); # 1 test
-handle_request( "/r/all (app) invalid" , "/r/all/test.html", 1, undef, expected_error => 404 ); # 1 test
-# 176
-
-# test implied formats
-DW::Routing->register_string( "/test/app/implied_format", \&handler, app => 1, args => "it_worked_app_if" );
-
-$expected_format = 'html';
-handle_request( "/test app implied_format (app)" , "/test/app/implied_format", 1, "it_worked_app_if" ); # 3 tests
-
-$expected_format = 'json';
-handle_request( "/test app implied_format (app) invalid" , "/test/app/implied_format.json", 1, undef, expected_error => 404 ); # 1 test
-# 180
-
-# test all formats
-DW::Routing->register_string( "/test/app/all_format", \&handler, app => 1, args => "it_worked_app_af", formats => 1 );
-
-$expected_format = 'html';
-handle_request( "/test app implied_format (app)" , "/test/app/all_format", 1, "it_worked_app_af" ); # 3 tests
-
-$expected_format = 'json';
-handle_request( "/test app implied_format (app)" , "/test/app/all_format.json", 1, "it_worked_app_af" ); # 3 test
-# 186
-
-DW::Routing->register_string( "/xx3/index", \&handler, app => 1, args => "it_worked_redir" );
-
-$expected_format = 'html';
-handle_request( "/xx3" , "/xx3/", 1, "it_worked_redir" ); # 3 tests
-# 189
-
-handle_request( "/xx3" , "/xx3/index", 1, "it_worked_redir" ); # 3 tests
-# 192
-
-handle_redirect( '/xx3', '/xx3/' );
-# 194
-
-# test dying
-DW::Routing->register_string( "/test/die/all_format", \&died_handler, app => 1, formats => 1 );
-
-handle_server_error( "/test die implied_format (app)", "/test/die/all_format", "html" ); # 2 tests
-handle_server_error( "/test die .json format (app)", "/test/die/all_format.json", "json" ); # 2 tests
-handle_server_error( "/test die .html format (app)", "/test/die/all_format.html", "html" ); # 2 tests
-handle_server_error( "/test die .blah format (app)", "/test/die/all_format.blah", "blah" ); # 2 tests
-# 203 ( I know this doesn't add up. )
-
-DW::Routing->register_string( "/test/method/normal", \&handler, app => 1 );
-
-handle_request( "Method GET  - okay", "/test/method/normal", 1, undef, method => 'GET' );  # 3 tests
-handle_request( "Method POST - okay", "/test/method/normal", 1, undef, method => 'POST' );
-handle_request( "Method HEAD - okay", "/test/method/normal", 1, undef, method => 'HEAD' );
-handle_request( "Method PUT  - !ok",  "/test/method/normal", 1, undef, method => 'PUT', expected_error => 405 ); # 1 test
-# 213
-
-DW::Routing->register_string( "/test/method/all", \&handler, app => 1, methods => 1 );
-
-handle_request( "Method GET  - okay", "/test/method/all", 1, undef, method => 'GET' );  # 3 tests
-handle_request( "Method POST - okay", "/test/method/all", 1, undef, method => 'POST' );
-handle_request( "Method HEAD - okay", "/test/method/all", 1, undef, method => 'HEAD' );
-handle_request( "Method PUT  - okay", "/test/method/all", 1, undef, method => 'PUT' );
-handle_request( "Method FOO  - okay", "/test/method/all", 1, undef, method => 'FOO' );
-# 228
-
-DW::Routing->register_string( "/test/method/no_post", \&handler, app => 1, methods => { GET => 1, HEAD => 1, PUT => 1 } );
-
-handle_request( "Method GET  - okay", "/test/method/no_post", 1, undef, method => 'GET' );  # 3 tests
-handle_request( "Method POST - !ok",  "/test/method/no_post", 1, undef, method => 'POST', expected_error => 405 ); # 1 test
-handle_request( "Method HEAD - okay", "/test/method/no_post", 1, undef, method => 'HEAD' ); # 3 tests
-handle_request( "Method PUT  - okay", "/test/method/no_post", 1, undef, method => 'PUT' ); # 3 test
-# 238
-
-
-sub handle_redirect {
-    my ( $uri, $expected ) = @_;
-
-    $DW::Request::determined = 0;
-    $DW::Request::cur_req = undef;
-
-    my $req = HTTP::Request->new(GET=>"$uri");
-
-    my $opts = DW::Routing->get_call_opts( uri => $uri );
-
-    return fail( "Opts is undef" ) unless $opts;
-
-    my $hash = $opts->call_opts;
-    return fail( "No call opts" ) unless $hash && $hash->{sub};
-
-    is( $hash->{sub}, \&DW::Routing::_redirect_helper );
-    is( $hash->{args}, $expected );
-}
-
-sub handle_request {
-    my ( $name, $uri, $valid, $expected, %opts ) = @_;
-
-    $DW::Request::determined = 0;
-    $DW::Request::cur_req = undef;
-
-    my $method = $opts{method} || 'GET';
-
-    my $req = HTTP::Request->new($method=>"$uri");
-    my $r = DW::Request::Standard->new($req);
-
-    $result = undef;
-    $__name = $name;
-
-    my $ret = DW::Routing->call( %opts );
-    if ( ! $valid ) {
-        is( $ret, undef, "$name: wrong return" );
-        return 1;
-    }
-
-    my $expected_ret = $opts{expected_error} || $r->OK;
-    is( $ret, $expected_ret, "$name: wrong return" );
-    if ( $ret != $r->OK ) {
-        return 0;
-    }
-    is ( $result, $expected, "$name: handler set wrong value.");
-}
-
-sub handle_server_error {
-    my ( $name, $uri, $format, %opts ) = @_;
-
-    $DW::Request::determined = 0;
-    $DW::Request::cur_req = undef;
-
-    my $req = HTTP::Request->new( GET => "$uri" );
-    my $r = DW::Request::Standard->new( $req );
-
-    $result = undef;
-    $__name = $name;
-    eval { DW::Routing->call( %opts ) };
-
-    is( $r->status, $r->HTTP_SERVER_ERROR, "$name: wrong return" );
-    is( $r->content_type, {
-        html => "text/html",
-        json => "application/json",
-    }->{$format} || "text/plain", "$name: wrong returned content type for $format" );
-}
-
-sub handler {
-    my $r = DW::Request->get;
-    $result = $_[0]->args;
-    is ( $_[0]->format, $expected_format, "$__name: format wrong!" );
-    return $r->OK;
-}
-
-sub regex_handler {
-    my $r = DW::Request->get;
-    $result = $_[0]->args->[1];
-    is ( $_[0]->format, $expected_format, "$__name: format wrong!" );
-    is( $_[0]->subpatterns->[0], $_[0]->args->[0], "$__name: capture wrong!" );
-    return $r->OK;
-}
-
-sub died_handler {
-    die "deliberate die()";
-}
--------------------------------------------------------------------------------