Debian lenny version packages
[pkg-perl] / deb-src / libhtml-parser-perl / libhtml-parser-perl-3.56 / t / handler.t
1 # Test handler method
2
3 use Test::More tests => 11;
4
5 my $testno;
6
7 use HTML::Parser;
8 {
9     package MyParser;
10     use vars qw(@ISA);
11     @ISA=(HTML::Parser);
12     
13     sub foo
14     {
15         Test::More::is($_[1]{testno}, Test::More->builder->current_test + 1);
16     }
17
18     sub bar
19     {
20         Test::More::is($_[1], Test::More->builder->current_test + 1);
21     }
22 }
23
24 $p = MyParser->new(api_version => 3);
25
26 eval {
27     $p->handler(foo => "foo", "foo");
28 };
29
30 like($@, qr/^No handler for foo events/);
31
32 eval {
33    $p->handler(start => "foo", "foo");
34 };
35 like($@, qr/^Unrecognized identifier foo in argspec/);
36
37 my $h = $p->handler(start => "foo", "self,tagname");
38 ok(!defined($h));
39
40 $x = \substr("xfoo", 1);
41 $p->handler(start => $$x, "self,attr");
42 $p->parse("<a testno=4>");
43
44 $p->handler(start => \&MyParser::foo, "self,attr");
45 $p->parse("<a testno=5>");
46
47 $p->handler(start => "foo");
48 $p->parse("<a testno=6>");
49
50 $p->handler(start => "bar", "self,'7'");
51 $p->parse("<a>");
52
53 eval {
54     $p->handler(start => {}, "self");
55 };
56 like($@, qr/^Only code or array references allowed as handler/);
57
58 $a = [];
59 $p->handler(start => $a);
60 $h = $p->handler("start");
61 is($p->handler("start", "foo"), $a);
62
63 is($p->handler("start", \&MyParser::foo, ""), "foo");
64
65 is($p->handler("start"), \&MyParser::foo);
66
67