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/callback.t | |
download | HTML-Parser-tarball-master.tar.gz |
HTML-Parser-3.71HEADHTML-Parser-3.71master
Diffstat (limited to 't/callback.t')
-rw-r--r-- | t/callback.t | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/t/callback.t b/t/callback.t new file mode 100644 index 0000000..7a456cf --- /dev/null +++ b/t/callback.t @@ -0,0 +1,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/); |