1#!perl -w
2
3use strict;
4use warnings;
5use utf8;
6
7use HTML::Parser ();
8use Test::More tests => 2;
9
10my @parsed;
11my $p
12    = HTML::Parser->new(api_version => 3, start_h => [\@parsed, 'tag, attr'],);
13
14my @warn;
15$SIG{__WARN__} = sub {
16    push(@warn, $_[0]);
17};
18
19$p->parse("\xEF\xBB\xBF<head>Hi there</head>");
20$p->eof;
21
22#use Encode;
23$p->parse("\xEF\xBB\xBF<head>Hi there</head>" . chr(0x263A));
24$p->eof;
25
26$p->parse("\xFF\xFE<head>Hi there</head>");
27$p->eof;
28
29$p->parse("\xFE\xFF<head>Hi there</head>");
30$p->eof;
31
32$p->parse("\0\0\xFF\xFE<head>Hi there</head>");
33$p->eof;
34
35$p->parse("\xFE\xFF\0\0<head>Hi there</head>");
36$p->eof;
37
38for (@warn) {
39    s/line (\d+)/line ##/g;
40}
41
42is(join("", @warn), <<EOT);
43Parsing of undecoded UTF-8 will give garbage when decoding entities at $0 line ##.
44Parsing of undecoded UTF-8 will give garbage when decoding entities at $0 line ##.
45Parsing of undecoded UTF-16 at $0 line ##.
46Parsing of undecoded UTF-16 at $0 line ##.
47Parsing of undecoded UTF-32 at $0 line ##.
48Parsing of undecoded UTF-32 at $0 line ##.
49EOT
50
51@warn = ();
52
53$p = HTML::Parser->new(api_version => 3, start_h => [\@parsed, 'tag'],);
54
55$p->parse("\xEF\xBB\xBF<head>Hi there</head>");
56$p->eof;
57ok(!@warn);
58