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 6fcb370 commit a557f84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/Template.pm
Expand Up @@ -198,8 +198,8 @@ sub parse {
\Q$end\E # End
)
/x;
my $cpen_re = qr/^(\Q$tag\E)(?:\Q$expr\E)?(?:\Q$escp\E)?\s*\Q$cpen\E(?!\w)/;
my $end_re = qr/^(?:(?<!\w)(\Q$cpst\E)\s*)?(\Q$trim\E)?\Q$end\E$/;
my $cpen_re = qr/^(\Q$tag\E)(?:\Q$expr\E)?(?:\Q$escp\E)?\s*\Q$cpen\E/;
my $end_re = qr/^(?:(\Q$cpst\E)\s*)?(\Q$trim\E)?\Q$end\E$/;

# Split lines
my $state = 'text';
Expand Down
10 changes: 4 additions & 6 deletions t/mojo/template.t
Expand Up @@ -145,24 +145,22 @@ is $output, "% my \$number = 23;\nThe number is <%= \$number %>.\n",
'mixed lines have been replaced';

# Helper starting with "end"
$mt = Mojo::Template->new(
prepend => 'no warnings "redefine"; sub endpoint { "works!" }');
$mt = Mojo::Template->new(prepend => 'sub endpoint { "works!" }');
$output = $mt->render(<<'EOF');
% endpoint;
%= endpoint
%== endpoint
<% endpoint; %><%= endpoint %><%== endpoint %>\
<% endpoint; %><%= endpoint %><%== endpoint =%>
EOF
is $output, "works!\nworks!\nworks!works!", 'helper worked';

# Helper ending with "begin"
$mt = Mojo::Template->new(
prepend => 'no warnings "redefine"; sub funbegin { "works too!" }');
$mt = Mojo::Template->new(prepend => 'sub funbegin { "works too!" }');
$output = $mt->render(<<'EOF');
% funbegin;
%= funbegin
%== funbegin
<% funbegin; %><%= funbegin %><%== funbegin %>\
<% funbegin; %><%= funbegin %><%== funbegin =%>\
EOF
is $output, "works too!\nworks too!\nworks too!works too!", 'helper worked';

Expand Down

0 comments on commit a557f84

Please sign in to comment.