Skip to content

Commit

Permalink
better helper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 3, 2012
1 parent f49c56c commit 9a525a1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -5,6 +5,7 @@ This file documents the revision history for Perl extension Mojolicious.
(mikemagowan, sri)
- Improved documentation.
- Improved tests.
- Fixed bug that prevented helper names from starting with "end". (Akron)
- Fixed empty frame handling in Mojo::Transaction::WebSocket.

2.92 2012-04-30
Expand Down
26 changes: 12 additions & 14 deletions lib/Mojo/Template.pm
Expand Up @@ -173,31 +173,29 @@ sub parse {
# Precompile
my $token_re = qr/
(
\Q$tag$replace\E # Replace
\Q$tag$replace\E # Replace
|
\Q$tag$expr$escp\E\s*\Q$cpen\E(?!\w) # Escaped expression (end)
\Q$tag$expr$escp\E\s*\Q$cpen\E(?!\w) # Escaped expression (end)
|
\Q$tag$expr$escp\E # Escaped expression
\Q$tag$expr$escp\E # Escaped expression
|
\Q$tag$expr\E\s*\Q$cpen\E(?!\w) # Expression (end)
\Q$tag$expr\E\s*\Q$cpen\E(?!\w) # Expression (end)
|
\Q$tag$expr\E # Expression
\Q$tag$expr\E # Expression
|
\Q$tag$cmnt\E\s*\Q$cpen\E(?!\w) # Comment (end)
\Q$tag$cmnt\E # Comment
|
\Q$tag$cmnt\E # Comment
\Q$tag\E\s*\Q$cpen\E(?!\w) # Code (end)
|
\Q$tag\E\s*\Q$cpen\E(?!\w) # Code (end)
\Q$tag\E # Code
|
\Q$tag\E # Code
\Q$cpst\E\s*\Q$trim$end\E # Trim end (start)
|
\Q$cpst\E\s*\Q$trim$end\E # Trim end (start)
\Q$trim$end\E # Trim end
|
\Q$trim$end\E # Trim end
\Q$cpst\E\s*\Q$end\E # End (start)
|
\Q$cpst\E\s*\Q$end\E # End (start)
|
\Q$end\E # End
\Q$end\E # End
)
/x;
my $cpen_re = qr/^(\Q$tag\E)(?:\Q$expr\E)?(?:\Q$escp\E)?\s*\Q$cpen\E(?!\w)/;
Expand Down
11 changes: 7 additions & 4 deletions t/mojolicious/lite_app.t
Expand Up @@ -38,7 +38,7 @@ app->defaults(default => 23);
helper test_helper => sub { shift->param(@_) };
helper test_helper2 => sub { shift->app->controller_class };
helper dead => sub { die $_[1] || 'works!' };
helper endpoint => sub { 'works!' };
helper endpoint => sub {'works!'};
is app->test_helper('foo'), undef, 'no value yet';
is app->test_helper2, 'Mojolicious::Controller', 'right value';

Expand Down Expand Up @@ -393,7 +393,7 @@ get '/helper' => sub { shift->render(handler => 'ep') } => 'helper';
app->helper(agent => sub { shift->req->headers->user_agent });

# GET /helper/endpoint
get '/helper/endpoint' => sub { shift->render('endpoint')};
get '/helper/endpoint' => 'endpoint';

# GET /eperror
get '/eperror' => sub { shift->render(handler => 'ep') } => 'eperror';
Expand Down Expand Up @@ -1147,7 +1147,7 @@ $t->get_ok('/helper', {'User-Agent' => 'Explorer'})->status_is(200)
$t->get_ok('/helper/endpoint')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is("works!");
->content_is("works!\nworks!\nworks!works!");

# GET /eperror
$t->get_ok('/eperror')->status_is(500)
Expand Down Expand Up @@ -1446,7 +1446,10 @@ app layout <%= content %><%= app->mode %>
(<%= agent %>)\
@@ endpoint.html.ep
<%= endpoint %>\
% endpoint;
%= endpoint
%== endpoint
<% endpoint; %><%= endpoint %><%== endpoint %>\
@@ eperror.html.ep
%= $c->foo('bar');
Expand Down

0 comments on commit 9a525a1

Please sign in to comment.