summaryrefslogtreecommitdiff
path: root/t/filter.t
blob: 3b18f9ec71cb61059940dde07e5ba059d1892d3c (plain)
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
59
60
use Test::More tests => 3;

my $HTML = <<EOT;

<!DOCTYPE HTML>
<!-- comment
<h1>Foo</h1>
-->

<H1
>Bar</H1
>

<Table><tr><td>1<td>2<td>3
<tr>
</table>

<?process>

EOT

use HTML::Filter;
use SelectSaver;

my $tmpfile = "test-$$.htm";
die "$tmpfile already exists" if -e $tmpfile;

open(HTML, ">$tmpfile") or die "$!";

{
    my $save = new SelectSaver(HTML);
    HTML::Filter->new->parse($HTML)->eof;
}
close(HTML);

open(HTML, $tmpfile) or die "$!";
local($/) = undef;
my $FILTERED = <HTML>;
close(HTML);

#print $FILTERED;
is($FILTERED, $HTML);

{
    package MyFilter;
    @ISA=qw(HTML::Filter);
    sub comment {}
    sub output { push(@{$_[0]->{fhtml}}, $_[1]) }
    sub filtered_html { join("", @{$_[0]->{fhtml}}) }
}

my $f2 = MyFilter->new->parse_file($tmpfile)->filtered_html;
unlink($tmpfile) or warn "Can't unlink $tmpfile: $!";

#diag $f2;

unlike($f2, qr/Foo/);
like($f2, qr/Bar/);