File: offset.t

package info (click to toggle)
libhtml-parser-perl 3.55-1%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 528 kB
  • ctags: 192
  • sloc: ansic: 1,986; perl: 1,935; makefile: 43
file content (58 lines) | stat: -rw-r--r-- 1,176 bytes parent folder | download | duplicates (7)
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
use strict;
use HTML::Parser ();
use Test::More tests => 1;

my $HTML = <<'EOT';

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html40/strict.dtd">

<foo bar baz=3>heisan
</foo> <?process>
<!-- comment -->
<xmp>xmp</xmp>

EOT

my $p = HTML::Parser->new(api_version => 3);

my $sum_len = 0;
my $count = 0;
my $err;

$p->handler(default =>
	    sub {
		my($offset, $length, $offset_end, $line, $col, $text) = @_;
		my $copy = $text;
		$copy =~ s/\n/\\n/g;
		substr($copy, 30) = "..." if length($copy) > 32;
		#diag sprintf ">>> %d.%d %s", $line, $col, $copy;
		if ($offset != $sum_len) {
		   diag "offset mismatch $offset vs $sum_len";
		   $err++;
                }
		if ($offset_end != $offset + $length) {
		   diag "offset_end $offset_end wrong";
		   $err++;
                }
		if ($length != length($text)) {
		   diag "length mismatch";
		   $err++;
		}
                if (substr($HTML, $offset, $length) ne $text) {
		   diag "content mismatch";
		   $err++;
		}
		$sum_len += $length;
		$count++;
	    },
	    'offset,length,offset_end,line,column,text');

for (split(//, $HTML)) {
   $p->parse($_);
}
$p->eof;

ok($count > 5 && !$err);