Debian lenny version packages
[pkg-perl] / deb-src / libhtml-parser-perl / libhtml-parser-perl-3.56 / t / offset.t
1 use strict;
2 use HTML::Parser ();
3 use Test::More tests => 1;
4
5 my $HTML = <<'EOT';
6
7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
8  "http://www.w3.org/TR/html40/strict.dtd">
9
10 <foo bar baz=3>heisan
11 </foo> <?process>
12 <!-- comment -->
13 <xmp>xmp</xmp>
14
15 EOT
16
17 my $p = HTML::Parser->new(api_version => 3);
18
19 my $sum_len = 0;
20 my $count = 0;
21 my $err;
22
23 $p->handler(default =>
24             sub {
25                 my($offset, $length, $offset_end, $line, $col, $text) = @_;
26                 my $copy = $text;
27                 $copy =~ s/\n/\\n/g;
28                 substr($copy, 30) = "..." if length($copy) > 32;
29                 #diag sprintf ">>> %d.%d %s", $line, $col, $copy;
30                 if ($offset != $sum_len) {
31                    diag "offset mismatch $offset vs $sum_len";
32                    $err++;
33                 }
34                 if ($offset_end != $offset + $length) {
35                    diag "offset_end $offset_end wrong";
36                    $err++;
37                 }
38                 if ($length != length($text)) {
39                    diag "length mismatch";
40                    $err++;
41                 }
42                 if (substr($HTML, $offset, $length) ne $text) {
43                    diag "content mismatch";
44                    $err++;
45                 }
46                 $sum_len += $length;
47                 $count++;
48             },
49             'offset,length,offset_end,line,column,text');
50
51 for (split(//, $HTML)) {
52    $p->parse($_);
53 }
54 $p->eof;
55
56 ok($count > 5 && !$err);
57
58