File: pre.t

package info (click to toggle)
libhtml-truncate-perl 0.20-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 2,339; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (4)
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&#8230;</pre></div>};
}

sub _with_p {
    return q{<div>

<p>
   Some indentation <b>with <i>tags        inside</i></b> And another line&#8230;</p></div>};
}

__DATA__
<div>

<pre>
   Some indentation <b>with <i>tags        inside</i></b>
   And another line
</pre>

</div>