Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…3345

git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@1229 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information
abw committed Jun 17, 2009
1 parent 75a1ed9 commit 45e5cf4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/Template/Parser.pm
Expand Up @@ -320,7 +320,7 @@ sub split_text {
if ($chomp && $pre) {
# chomp off whitespace and newline preceding directive
if ($chomp == CHOMP_ALL) {
$pre =~ s{ (\n|^) [^\S\n]* \z }{}mx;
$pre =~ s{ (\r?\n|^) [^\S\n]* \z }{}mx;
}
elsif ($chomp == CHOMP_COLLAPSE) {
$pre =~ s{ (\s+) \z }{ }x;
Expand Down
76 changes: 44 additions & 32 deletions t/chomp.t
Expand Up @@ -37,6 +37,8 @@ my $dong = "!\n\n[%= dong =%]\n\n!";
my $dang = "Hello[%# blah blah blah -%]\n!";
my $winsux1 = "[% ding -%]\015\012[% dong %]";
my $winsux2 = "[% ding -%]\015\012\015\012[% dong %]";
my $winsux3 = "[% ding %]\015\012[%- dong %]";
my $winsux4 = "[% ding %]\015\012\015\012[%- dong %]";

my $blocks = {
foo => $foo,
Expand All @@ -47,6 +49,8 @@ my $blocks = {
dang => $dang,
winsux1 => $winsux1,
winsux2 => $winsux2,
winsux3 => $winsux3,
winsux4 => $winsux4,
};

# script may be being run in distribution root or 't' directory
Expand Down Expand Up @@ -95,28 +99,36 @@ match( $out, "Hello!", 'dang out' );

$out = '';
ok( $tt2->process('winsux1', $vars, \$out), 'winsux1' );
match( $out, "HelloWorld", 'winsux1 out' );
match( od($out), "HelloWorld", 'winsux1 out' );

$out = '';
ok( $tt2->process('winsux2', $vars, \$out), 'winsux2' );
match( od($out), 'Hello\015\012World', 'winsux2 out' );

$out = join(
'',
map {
my $ord = ord($_);
($ord > 127 || $ord < 32 )
? sprintf '\0%lo', $ord
: $_
}
split //, $out
);
$out = '';
ok( $tt2->process('winsux3', $vars, \$out), 'winsux3' );
match( od($out), "HelloWorld", 'winsux3 out' );

match( $out, 'Hello\015\012World', 'winsux2 out' );
$out = '';
ok( $tt2->process('winsux4', $vars, \$out), 'winsux4' );
match( od($out), 'Hello\015\012World', 'winsux4 out' );

$out = '';
ok( $tt2->process('dos_newlines', $vars, \$out), 'dos_newlines' );
match( $out, "HelloWorld", 'dos_newlines out' );

sub od{
join(
'',
map {
my $ord = ord($_);
($ord > 127 || $ord < 32 )
? sprintf '\0%lo', $ord
: $_
}
split //, shift()
);
}

#------------------------------------------------------------------------
# tests with the PRE_CHOMP option set
Expand All @@ -128,24 +140,24 @@ $tt2 = Template->new({
});

$out = '';
ok( $tt2->process('foo', $vars, \$out), $tt2->error() );
match( $out, "3.14\n" );
ok( $tt2->process('foo', $vars, \$out), 'pre pi' );
match( $out, "3.14\n", 'pre pi match' );

$out = '';
ok( $tt2->process('bar', $vars, \$out), $tt2->error() );
match( $out, "2.718" );
ok( $tt2->process('bar', $vars, \$out), 'pre e' );
match( $out, "2.718", 'pre e match' );

$out = '';
ok( $tt2->process('baz', $vars, \$out), $tt2->error() );
match( $out, "\n1.618\n" );
ok( $tt2->process('baz', $vars, \$out), 'pre phi' );
match( $out, "\n1.618\n", 'pre phi match' );

$out = '';
ok( $tt2->process('ding', $vars, \$out), $tt2->error() );
match( $out, "!Hello!" );
ok( $tt2->process('ding', $vars, \$out), 'pre hello' );
match( $out, "!Hello!", 'pre hello match' );

$out = '';
ok( $tt2->process('dong', $vars, \$out), $tt2->error() );
match( $out, "! World !" );
ok( $tt2->process('dong', $vars, \$out), 'pre world' );
match( $out, "! World !", 'pre world match' );


#------------------------------------------------------------------------
Expand All @@ -158,24 +170,24 @@ $tt2 = Template->new({
});

$out = '';
ok( $tt2->process('foo', $vars, \$out), $tt2->error() );
match( $out, "\n3.14" );
ok( $tt2->process('foo', $vars, \$out), 'post pi' );
match( $out, "\n3.14", 'post pi match' );

$out = '';
ok( $tt2->process('bar', $vars, \$out), $tt2->error() );
match( $out, "2.718" );
ok( $tt2->process('bar', $vars, \$out), 'post e' );
match( $out, "2.718", 'post e match' );

$out = '';
ok( $tt2->process('baz', $vars, \$out), $tt2->error() );
match( $out, "\n1.618\n" );
ok( $tt2->process('baz', $vars, \$out), 'post phi' );
match( $out, "\n1.618\n", 'post phi match' );

$out = '';
ok( $tt2->process('ding', $vars, \$out), $tt2->error() );
match( $out, "!Hello!" );
ok( $tt2->process('ding', $vars, \$out), 'post hello' );
match( $out, "!Hello!", 'post hello match' );

$out = '';
ok( $tt2->process('dong', $vars, \$out), $tt2->error() );
match( $out, "! World !" );
ok( $tt2->process('dong', $vars, \$out), 'post world' );
match( $out, "! World !", 'post world match' );


my $tt = [
Expand Down

0 comments on commit 45e5cf4

Please sign in to comment.