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
|
use Test::More tests => 47;
use strict;
use HTML::Parser;
my @expected;
my $p = HTML::Parser->new(api_version => 3,
unbroken_text => 1,
default_h => [\@expected, '@{event, text}'],
);
my $doc = <<'EOT';
<title>Hi</title>
<h1>Ho ho</h1>
<--comment->
EOT
$p->parse($doc)->eof;
#use Data::Dump; Data::Dump::dump(@expected);
for my $i (1..length($doc)) {
my @t;
$p->handler(default => \@t);
$p->parse(chunk($doc, $i));
# check that we got the same stuff
#diag "X:", join(":", @t);
#diag "Y:", join(":", @expected);
is(join(":", @t), join(":", @expected));
}
sub chunk {
my $str = shift;
my $size = shift || 1;
sub {
my $res = substr($str, 0, $size);
#diag "...$res";
substr($str, 0, $size) = "";
$res;
}
}
# Test croking behaviour
$p->handler(default => []);
eval {
$p->parse(sub { die "Hi" });
};
like($@, qr/^Hi/);
|