7 use lib "$FindBin::Bin/../lib";
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
13 use Test::More tests => 33*$iters;
14 use Catalyst::Test 'TestApp';
16 use Catalyst::Request;
18 if ( $ENV{CAT_BENCHMARK} ) {
20 Benchmark::timethis( $iters, \&run_tests );
30 ok( my $response = request('http://localhost/action/regexp/10/hello'),
32 ok( $response->is_success, 'Response Successful 2xx' );
33 is( $response->content_type, 'text/plain', 'Response Content-Type' );
34 is( $response->header('X-Catalyst-Action'),
35 '^action/regexp/(\d+)/(\w+)$', 'Test Action' );
37 $response->header('X-Test-Class'),
38 'TestApp::Controller::Action::Regexp',
43 qr/^bless\( .* 'Catalyst::Request' \)$/s,
44 'Content is a serialized Catalyst::Request'
49 ok( my $response = request('http://localhost/action/regexp/hello/10'),
51 ok( $response->is_success, 'Response Successful 2xx' );
52 is( $response->content_type, 'text/plain', 'Response Content-Type' );
53 is( $response->header('X-Catalyst-Action'),
54 '^action/regexp/(\w+)/(\d+)$', 'Test Action' );
56 $response->header('X-Test-Class'),
57 'TestApp::Controller::Action::Regexp',
62 qr/^bless\( .* 'Catalyst::Request' \)$/s,
63 'Content is a serialized Catalyst::Request'
68 ok( my $response = request('http://localhost/action/regexp/mandatory'),
70 ok( $response->is_success, 'Response Successful 2xx' );
71 is( $response->content_type, 'text/plain', 'Response Content-Type' );
72 is( $response->header('X-Catalyst-Action'),
73 '^action/regexp/(mandatory)(/optional)?$', 'Test Action' );
75 $response->header('X-Test-Class'),
76 'TestApp::Controller::Action::Regexp',
79 my $content = $response->content;
80 my $req = eval $content;
82 is( scalar @{ $req->captures }, 2, 'number of captures' );
83 is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' );
84 ok( !defined $req->captures->[ 1 ], 'optional capture' );
88 ok( my $response = request('http://localhost/action/regexp/mandatory/optional'),
90 ok( $response->is_success, 'Response Successful 2xx' );
91 is( $response->content_type, 'text/plain', 'Response Content-Type' );
92 is( $response->header('X-Catalyst-Action'),
93 '^action/regexp/(mandatory)(/optional)?$', 'Test Action' );
95 $response->header('X-Test-Class'),
96 'TestApp::Controller::Action::Regexp',
99 my $content = $response->content;
100 my $req = eval $content;
102 is( scalar @{ $req->captures }, 2, 'number of captures' );
103 is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' );
104 is( $req->captures->[ 1 ], '/optional', 'optional capture' );
107 # test localregex in the root controller
109 ok( my $response = request('http://localhost/localregex'),
111 ok( $response->is_success, 'Response Successful 2xx' );
112 is( $response->content_type, 'text/plain', 'Response Content-Type' );
113 is( $response->header('X-Catalyst-Action'),
114 '^localregex$', 'Test Action' );
116 $response->header('X-Test-Class'),
117 'TestApp::Controller::Root',