diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-05-08 22:21:52 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-05-08 22:21:52 +0000 |
commit | 2f253cfc85ffd55a8acb988e91f0bc5ab348124c (patch) | |
tree | 4734ccd522c71dd455879162006742002f8c1565 /t/offset.t | |
download | HTML-Parser-tarball-master.tar.gz |
HTML-Parser-3.71HEADHTML-Parser-3.71master
Diffstat (limited to 't/offset.t')
-rw-r--r-- | t/offset.t | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/t/offset.t b/t/offset.t new file mode 100644 index 0000000..840728d --- /dev/null +++ b/t/offset.t @@ -0,0 +1,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); + + |