Skip to content

Commit

Permalink
better template tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 1, 2014
1 parent ce1a62e commit 794de43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/Mojo/Template.pm
Expand Up @@ -221,9 +221,9 @@ sub parse {
}

# Optimize successive text lines ending with newlines
push @tree, \@token and next
if grep { _reject($_) } $tree[-1] // [], \@token;
$tree[-1][1] .= $token[1];
my $previous = $tree[-1] // [];
if (_text($previous) && _text(\@token)) { $previous->[1] .= $token[1] }
else { push @tree, \@token }
}

return $self;
Expand Down Expand Up @@ -252,7 +252,7 @@ sub _line {
return qq{#line @{[shift]} "$name"};
}

sub _reject { @{$_[0]} != 2 || $_[0][0] ne 'text' || $_[0][1] !~ /\n$/ }
sub _text { @{$_[0]} == 2 && $_[0][0] eq 'text' && $_[0][1] =~ /\n$/ }

sub _trim {
my ($self, $line) = @_;
Expand Down
8 changes: 5 additions & 3 deletions t/mojo/template.t
Expand Up @@ -1009,11 +1009,13 @@ test
123
456\
789\\
0
987
654
321
EOF
is $mt->tree->[0][1], "test\n123\n", 'optimized text lines';
$mt->build->compile;
is $mt->interpret, "test\n123\n456789\\\n0\n", 'just text';
$output = $mt->build->compile || $mt->interpret;
is $output, "test\n123\n456789\\\n987\n654\n321\n", 'just text';

# Scoped scalar
$mt = Mojo::Template->new;
Expand Down

0 comments on commit 794de43

Please sign in to comment.