1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
use strict;
use Test::More tests => 5;
use FindBin;
use File::Spec;
use lib File::Spec->catfile($FindBin::Bin, 'lib');
use HTML::Truncate;
my $ht = HTML::Truncate->new();
my $html = join('', <DATA>);
{
my $char_count = 50;
$ht->chars($char_count);
ok( $ht->chars() == $char_count, "Chars is reset to $char_count" );
ok( my $trunc = $ht->truncate($html), "Truncating HTML" );
is( $trunc, _with_pre(),
"Truncation of <pre> version matches expectations" );
}
{
# Swap tags, run otherwise same HTML through
$html =~ s,(</?)pre,${1}p,g;
ok( my $trunc = $ht->truncate($html), "Truncating HTML" );
is( $trunc, _with_p(),
"Truncation of <p> version matches expectations" );
}
sub _with_pre {
return q{<div>
<pre>
Some indentation <b>with <i>tags inside</i></b>
An…</pre></div>};
}
sub _with_p {
return q{<div>
<p>
Some indentation <b>with <i>tags inside</i></b> And another line…</p></div>};
}
__DATA__
<div>
<pre>
Some indentation <b>with <i>tags inside</i></b>
And another line
</pre>
</div>
|