File: 06_scrub_file.t

package info (click to toggle)
libhtml-scrubber-perl 0.19-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 292 kB
  • sloc: perl: 422; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,804 bytes parent folder | download | duplicates (3)
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
# perl Makefile.PL && nmake realclean && cls && perl Makefile.PL && nmake test

use strict;
use File::Temp qw/ tempfile tempdir /;
use Test::More tests => 10;
BEGIN { $^W = 1 }

use_ok('HTML::Scrubber');

my $s    = HTML::Scrubber->new;
my $html = q[<html><body><p>hi<br>start <!--comment--> mid1 <?html pi> mid2 <?xml pi?> end</body></html>];

isa_ok( $s, 'HTML::Scrubber' );

my $tmpdir = tempdir( CLEANUP => 1 );

SKIP: {
    skip "no writable temporary directory found", 6
        unless length $tmpdir
        and -d $tmpdir;

    my $template = 'html-scrubber-XXXX';
    my ( $tfh, $tmpfile ) = tempfile( $template, DIR => $tmpdir, SUFFIX => '.html' );
    my $r = $s->scrub( $html, $tmpfile );
    $r = "Error: \$@=$@ \$!=$!" unless $r;
    is( $r, 1, "scrub(\$html,\$tmpfile=$tmpfile)" );

    open my $filis, "+>", $tmpfile or die "can't write to $tmpfile";

    $r = $s->scrub( $html, $filis );
    $r = "Error: \$@=$@ \$!=$!" unless $r;

    is( $r, 1, q[scrub($html, $filis)] );

    seek $filis, 0, 0;
    $r = join '', readline $filis;
    is( $r, "histart  mid1  mid2  end", '$filis has the right stuff' );
    is( close($filis), 1, q[close($filis)] );

    my ( $tfh2, $tmpfile2 ) = tempfile( $template, DIR => $tmpdir, SUFFIX => '.html' );
    $r = $s->scrub_file( $tmpfile, "$tmpfile2" );
    $r = "Error: \$@=$@ \$!=$!" unless $r;

    is( $r, 1, qq[scrub_file(\$tmpfile,"\$tmpfile2"=$tmpfile2)] );

    open $filis, "+>", $tmpfile2 or die "can't write to $tmpfile";
    $r = $s->scrub_file( $tmpfile, $filis );
    $r = "Error: \$@=$@ \$!=$!" unless $r;

    is( $r, 1, q[scrub_file($tmpfile, $filis)] );
    seek $filis, 0, 0;
    $r = join '', readline $filis;
    is( $r, "histart  mid1  mid2  end", '$filis has the right stuff' );
    is( close($filis), 1, q[close($filis)] );

}