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