1# tell parser the source POD has already been decoded from bytes to chars
2# =encoding line should be ignored
3# utf8 characters should come through unscathed
4
5BEGIN {
6    if($ENV{PERL_CORE}) {
7        chdir 't';
8        @INC = '../lib';
9    }
10
11    use Config;
12    if ($Config::Config{'extensions'} !~ /\bEncode\b/) {
13      print "1..0 # Skip: Encode was not built\n";
14      exit 0;
15    }
16}
17
18use strict;
19use warnings;
20use Test;
21BEGIN { plan tests => 5 };
22
23use Pod::Simple::DumpAsXML;
24use Pod::Simple::XMLOutStream;
25
26my $parser = Pod::Simple::XMLOutStream->new;
27$parser->parse_characters(1);
28my $output = '';
29$parser->output_string( \$output );
30$parser->parse_string_document(qq{
31
32=encoding bogocode
33
34=head1 DESCRIPTION
35
36Confirm that if we tell the parser to expect character data, it avoids all
37the code paths that might attempt to decode the source from bytes to chars.
38
39The r\x{101}in in \x{15E}pain \x{FB02}oods the plain
40
41});
42
43ok(1); # parsed without exception
44
45if($output =~ /POD ERRORS/) {
46  ok(0);
47}
48else {
49  ok(1); # no errors
50}
51
52$output =~ s{&#(\d+);}{chr($1)}eg;
53
54if($output =~ /The r\x{101}in in \x{15E}pain \x{FB02}oods the plain/) {
55  ok(1); # data was not messed up
56}
57else {
58  ok(0);
59}
60
61##############################################################################
62# Test multiple =encoding declarations.
63$parser = Pod::Simple::XMLOutStream->new;
64$output = '';
65$parser->output_string( \$output );
66$parser->parse_string_document(qq{
67
68=pod
69
70=encoding UTF-8
71
72=encoding UTF-8
73
74=head1 DESCRIPTION
75
76Confirm that the parser detects multiple encodings and complains.
77});
78
79# Should have an error.
80ok($output =~ /POD ERRORS/);
81ok($output =~ /Cannot have multiple =encoding directives/);
82
83exit;
84