summaryrefslogtreecommitdiff
path: root/t/msie-compat.t
blob: a297f1edc7080c473db9d399f346148f353060c5 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!perl -w

use strict;
use HTML::Parser;

use Test::More tests => 4;

my $TEXT = "";
sub h
{
    my($event, $tagname, $text, @attr) = @_;
    for ($event, $tagname, $text, @attr) {
        if (defined) {
	    s/([\n\r\t])/sprintf "\\%03o", ord($1)/ge;
	}
	else {
	    $_ = "<undef>";
	}
    }

    $TEXT .= "[$event,$tagname,$text," . join(":", @attr) . "]\n";
}

my $p = HTML::Parser->new(default_h => [\&h, "event,tagname,text,\@attr"]);
$p->parse("<a>");
$p->parse("</a f>");
$p->parse("</a 'foo<>' 'bar>' x>");
$p->parse("</a \"foo<>\"");
$p->parse(" \"bar>\" x>");
$p->parse("</ foo bar>");
$p->parse("</ \"<>\" >");
$p->parse("<!--comment>text<!--comment><p");
$p->eof;

is($TEXT, <<'EOT');
[start_document,<undef>,,]
[start,a,<a>,]
[end,a,</a f>,]
[end,a,</a 'foo<>' 'bar>' x>,]
[end,a,</a "foo<>" "bar>" x>,]
[comment, foo bar,</ foo bar>,]
[comment, "<>" ,</ "<>" >,]
[comment,comment,<!--comment>,]
[text,<undef>,text,]
[comment,comment,<!--comment>,]
[comment,p,<p,]
[end_document,<undef>,,]
EOT

$TEXT = "";
$p->parse("<!comment>");
$p->eof;

is($TEXT, <<'EOT');
[start_document,<undef>,,]
[comment,comment,<!comment>,]
[end_document,<undef>,,]
EOT

$TEXT = "";
$p->parse(q(<a name=`foo bar`>));
$p->eof;

is($TEXT, <<'EOT');
[start_document,<undef>,,]
[start,a,<a name=`foo bar`>,name:`foo:bar`:bar`]
[end_document,<undef>,,]
EOT

$p->backquote(1);
$TEXT = "";
$p->parse(q(<a name=`foo bar`>));
$p->eof;

is($TEXT, <<'EOT');
[start_document,<undef>,,]
[start,a,<a name=`foo bar`>,name:foo bar]
[end_document,<undef>,,]
EOT