summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/cpan/Pod-Simple/t/enc-chars.t
blob: 65b4259df20dd24ecd43f6935af33a8578c70c36 (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
# tell parser the source POD has already been decoded from bytes to chars
# =encoding line should be ignored
# utf8 characters should come through unscathed

BEGIN {
    if($ENV{PERL_CORE}) {
        chdir 't';
        @INC = '../lib';
    }

    use Config;
    if ($Config::Config{'extensions'} !~ /\bEncode\b/) {
      print "1..0 # Skip: Encode was not built\n";
      exit 0;
    }
}

use strict;
use Test;
BEGIN { plan tests => 3 };

use Pod::Simple::DumpAsXML;
use Pod::Simple::XMLOutStream;


my $parser = Pod::Simple::XMLOutStream->new;
$parser->parse_characters(1);
my $output = '';
$parser->output_string( \$output );
$parser->parse_string_document(qq{

=encoding bogocode

=head1 DESCRIPTION

Confirm that if we tell the parser to expect character data, it avoids all
the code paths that might attempt to decode the source from bytes to chars.

The r\x{101}in in \x{15E}pain \x{FB02}oods the plain

});

ok(1); # parsed without exception

if($output =~ /POD ERRORS/) {
  ok(0);
}
else {
  ok(1); # no errors
}

$output =~ s{&#(\d+);}{chr($1)}eg;

if($output =~ /The r\x{101}in in \x{15E}pain \x{FB02}oods the plain/) {
  ok(1); # data was not messed up
}
else {
  ok(0);
}

exit;