blob: 120f79bb29703f32badca7b20c12db6b4226b493 (
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
61
62
63
64
65
66
67
68
69
70
|
use Test::More tests => 1;
use strict;
use HTML::Parser;
my $html = <<'EOT';
<html>
<title>This is a <nice> title</title>
<!--comment-->
<script language="perl">while (<DATA>) { & }</script>
<FORM>
<textarea name="foo" cols=50 rows=10>
foo
<foo>
<!--comment-->
&
foo
</FORM>
</textarea>
</FORM>
</html>
EOT
my $dump = "";
sub tdump {
my @a = @_;
for (@a) {
$_ = "<undef>" unless defined;
s/\n/\\n/g;
}
$dump .= join("|", @a) . "\n";
}
my $p = HTML::Parser->new(default_h => [\&tdump, "event,text,dtext,is_cdata"]);
$p->parse($html)->eof;
#diag $dump;
is($dump, <<'EOT');
start_document||<undef>|<undef>
start|<html>|<undef>|<undef>
text|\n|\n|
start|<title>|<undef>|<undef>
text|This is a <nice> title|This is a <nice> title|
end|</title>|<undef>|<undef>
text|\n|\n|
comment|<!--comment-->|<undef>|<undef>
text|\n|\n|
start|<script language="perl">|<undef>|<undef>
text|while (<DATA>) { & }|while (<DATA>) { & }|1
end|</script>|<undef>|<undef>
text|\n\n|\n\n|
start|<FORM>|<undef>|<undef>
text|\n\n|\n\n|
start|<textarea name="foo" cols=50 rows=10>|<undef>|<undef>
text|\n\nfoo\n<foo>\n<!--comment-->\n&\nfoo\n</FORM>\n\n|\n\nfoo\n<foo>\n<!--comment-->\n&\nfoo\n</FORM>\n\n|
end|</textarea>|<undef>|<undef>
text|\n\n|\n\n|
end|</FORM>|<undef>|<undef>
text|\n\n|\n\n|
end|</html>|<undef>|<undef>
text|\n|\n|
end_document||<undef>|<undef>
EOT
|