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/handler.t | |
download | HTML-Parser-tarball-master.tar.gz |
HTML-Parser-3.71HEADHTML-Parser-3.71master
Diffstat (limited to 't/handler.t')
-rw-r--r-- | t/handler.t | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/t/handler.t b/t/handler.t new file mode 100644 index 0000000..8d7bbc5 --- /dev/null +++ b/t/handler.t @@ -0,0 +1,67 @@ +# Test handler method + +use Test::More tests => 11; + +my $testno; + +use HTML::Parser; +{ + package MyParser; + use vars qw(@ISA); + @ISA=(HTML::Parser); + + sub foo + { + Test::More::is($_[1]{testno}, Test::More->builder->current_test + 1); + } + + sub bar + { + Test::More::is($_[1], Test::More->builder->current_test + 1); + } +} + +$p = MyParser->new(api_version => 3); + +eval { + $p->handler(foo => "foo", "foo"); +}; + +like($@, qr/^No handler for foo events/); + +eval { + $p->handler(start => "foo", "foo"); +}; +like($@, qr/^Unrecognized identifier foo in argspec/); + +my $h = $p->handler(start => "foo", "self,tagname"); +ok(!defined($h)); + +$x = \substr("xfoo", 1); +$p->handler(start => $$x, "self,attr"); +$p->parse("<a testno=4>"); + +$p->handler(start => \&MyParser::foo, "self,attr"); +$p->parse("<a testno=5>"); + +$p->handler(start => "foo"); +$p->parse("<a testno=6>"); + +$p->handler(start => "bar", "self,'7'"); +$p->parse("<a>"); + +eval { + $p->handler(start => {}, "self"); +}; +like($@, qr/^Only code or array references allowed as handler/); + +$a = []; +$p->handler(start => $a); +$h = $p->handler("start"); +is($p->handler("start", "foo"), $a); + +is($p->handler("start", \&MyParser::foo, ""), "foo"); + +is($p->handler("start"), \&MyParser::foo); + + |