Debian lenny version packages
[pkg-perl] / deb-src / libhtml-parser-perl / libhtml-parser-perl-3.56 / t / magic.t
1 # Check that the magic signature at the top of struct p_state works and that we
2 # catch modifications to _hparser_xs_state gracefully
3
4 use Test::More tests => 5;
5
6 use HTML::Parser;
7
8 $p = HTML::Parser->new(api_version => 3);
9
10 $p->xml_mode(1);
11
12 # We should not be able to simply modify this stuff
13 eval {
14     ${$p->{_hparser_xs_state}} += 4;
15 };
16 like($@, qr/^Modification of a read-only value attempted/);
17
18
19 my $x = delete $p->{_hparser_xs_state};
20
21 eval {
22     $p->xml_mode(1);
23 };
24 like($@, qr/^Can't find '_hparser_xs_state'/);
25
26 $p->{_hparser_xs_state} = \($$x + 16);
27
28 eval {
29     $p->xml_mode(1);
30 };
31 like($@, $] >= 5.008 ? qr/^Lost parser state magic/ : qr/^Bad signature in parser state object/);
32
33 $p->{_hparser_xs_state} = 33;
34 eval {
35     $p->xml_mode(1);
36 };
37 like($@,  qr/^_hparser_xs_state element is not a reference/);
38
39 $p->{_hparser_xs_state} = $x;
40
41 ok($p->xml_mode(0));