Add the original source packages to maemo, source lenny
[dh-make-perl] / dev / i386 / libhtml-parser-perl / libhtml-parser-perl-3.56 / t / filter.t
1 use Test::More tests => 3;
2
3 my $HTML = <<EOT;
4
5 <!DOCTYPE HTML>
6 <!-- comment
7 <h1>Foo</h1>
8 -->
9
10 <H1
11 >Bar</H1
12 >
13
14 <Table><tr><td>1<td>2<td>3
15 <tr>
16 </table>
17
18 <?process>
19
20 EOT
21
22 use HTML::Filter;
23 use SelectSaver;
24
25 my $tmpfile = "test-$$.htm";
26 die "$tmpfile already exists" if -e $tmpfile;
27
28 open(HTML, ">$tmpfile") or die "$!";
29
30 {
31     my $save = new SelectSaver(HTML);
32     HTML::Filter->new->parse($HTML)->eof;
33 }
34 close(HTML);
35
36 open(HTML, $tmpfile) or die "$!";
37 local($/) = undef;
38 my $FILTERED = <HTML>;
39 close(HTML);
40
41 #print $FILTERED;
42 is($FILTERED, $HTML);
43
44 {
45     package MyFilter;
46     @ISA=qw(HTML::Filter);
47     sub comment {}
48     sub output { push(@{$_[0]->{fhtml}}, $_[1]) }
49     sub filtered_html { join("", @{$_[0]->{fhtml}}) }
50 }
51
52 my $f2 = MyFilter->new->parse_file($tmpfile)->filtered_html;
53 unlink($tmpfile) or warn "Can't unlink $tmpfile: $!";
54
55 #diag $f2;
56
57 unlike($f2, qr/Foo/);
58 like($f2, qr/Bar/);
59
60