File: magic.t

package info (click to toggle)
libhtml-parser-perl 3.56-1%2Blenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 536 kB
  • ctags: 192
  • sloc: ansic: 1,985; perl: 1,935; makefile: 43
file content (41 lines) | stat: -rw-r--r-- 870 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Check that the magic signature at the top of struct p_state works and that we
# catch modifications to _hparser_xs_state gracefully

use Test::More tests => 5;

use HTML::Parser;

$p = HTML::Parser->new(api_version => 3);

$p->xml_mode(1);

# We should not be able to simply modify this stuff
eval {
    ${$p->{_hparser_xs_state}} += 4;
};
like($@, qr/^Modification of a read-only value attempted/);


my $x = delete $p->{_hparser_xs_state};

eval {
    $p->xml_mode(1);
};
like($@, qr/^Can't find '_hparser_xs_state'/);

$p->{_hparser_xs_state} = \($$x + 16);

eval {
    $p->xml_mode(1);
};
like($@, $] >= 5.008 ? qr/^Lost parser state magic/ : qr/^Bad signature in parser state object/);

$p->{_hparser_xs_state} = 33;
eval {
    $p->xml_mode(1);
};
like($@,  qr/^_hparser_xs_state element is not a reference/);

$p->{_hparser_xs_state} = $x;

ok($p->xml_mode(0));