diff options
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); + + |