Test utf8_mode.
gisle
19 years ago
10 | 10 | use Test qw(plan ok); |
11 | 11 | use HTML::Parser; |
12 | 12 | |
13 | plan tests => 75; | |
13 | plan tests => 87; | |
14 | 14 | |
15 | 15 | my @warn; |
16 | 16 | $SIG{__WARN__} = sub { |
117 | 117 | print $fh <<EOT; |
118 | 118 | \x{FEFF} |
119 | 119 | <title>\x{263A} Love! </title> |
120 | <h1>&hearts Love \x{2665}<h1> | |
120 | <h1 id=&hearts\x{2665}>&hearts Love \x{2665}<h1> | |
121 | 121 | EOT |
122 | 122 | close($fh) || die; |
123 | 123 | |
125 | 125 | @parsed = (); |
126 | 126 | $p->parse_file($file); |
127 | 127 | ok(@parsed, "11"); |
128 | ok($parsed[6][0], "start"); | |
129 | ok($parsed[6][8]{id}, "\x{2665}\xE2\x99\xA5"); | |
128 | 130 | ok($parsed[7][0], "text"); |
129 | 131 | ok($parsed[7][1], "&hearts Love \xE2\x99\xA5"); |
130 | 132 | ok($parsed[7][2], "\x{2665} Love \xE2\x99\xA5"); # expected garbage |
137 | 139 | open($fh, "<:utf8", $file) || die; |
138 | 140 | $p->parse_file($fh); |
139 | 141 | ok(@parsed, "11"); |
142 | ok($parsed[6][0], "start"); | |
143 | ok($parsed[6][8]{id}, "\x{2665}\x{2665}"); | |
140 | 144 | ok($parsed[7][0], "text"); |
141 | 145 | ok($parsed[7][1], "&hearts Love \x{2665}"); |
142 | 146 | ok($parsed[7][2], "\x{2665} Love \x{2665}"); |
143 | ok($parsed[10][3], (-s $file) - 3 * 2); | |
147 | ok($parsed[10][3], (-s $file) - 2 * 4); | |
144 | 148 | ok(@warn, 0); |
145 | 149 | |
150 | @warn = (); | |
151 | @parsed = (); | |
152 | open($fh, "<:raw", $file) || die; | |
153 | $p->utf8_mode(1); | |
154 | $p->parse_file($fh); | |
155 | ok(@parsed, "11"); | |
156 | ok($parsed[6][0], "start"); | |
157 | ok($parsed[6][8]{id}, "\x{2665}\x{2665}"); | |
158 | ok($parsed[7][0], "text"); | |
159 | ok($parsed[7][1], "&hearts Love \xE2\x99\xA5"); | |
160 | ok($parsed[7][2], "\x{2665} Love \x{2665}"); | |
161 | ok($parsed[10][3], -s $file); | |
162 | ok(@warn, 0); | |
163 | ||
164 | ||
146 | 165 | unlink($file); |