Upgrade to podlators-2.1.4
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / text-utf8.t
1 #!/usr/bin/perl -w
2 #
3 # text-utf8.t -- Test Pod::Text with UTF-8 input.
4 #
5 # Copyright 2002, 2004, 2006, 2007, 2008 by Russ Allbery <rra@stanford.edu>
6 #
7 # This program is free software; you may redistribute it and/or modify it
8 # under the same terms as Perl itself.
9
10 BEGIN {
11     chdir 't' if -d 't';
12     if ($ENV{PERL_CORE}) {
13         @INC = '../lib';
14     } else {
15         unshift (@INC, '../blib/lib');
16     }
17     unshift (@INC, '../blib/lib');
18     $| = 1;
19     print "1..3\n";
20
21     # UTF-8 support requires Perl 5.8 or later.
22     if ($] < 5.008) {
23         my $n;
24         for $n (1..3) {
25             print "ok $n # skip -- Perl 5.8 required for UTF-8 support\n";
26         }
27         exit;
28     }
29 }
30
31 END {
32     print "not ok 1\n" unless $loaded;
33 }
34
35 use Pod::Text;
36 use Pod::Simple;
37
38 $loaded = 1;
39 print "ok 1\n";
40
41 my $parser = Pod::Text->new or die "Cannot create parser\n";
42 my $n = 2;
43 eval { binmode (\*DATA, ':encoding(utf-8)') };
44 eval { binmode (\*STDOUT, ':encoding(utf-8)') };
45 while (<DATA>) {
46     next until $_ eq "###\n";
47     open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n";
48     eval { binmode (\*TMP, ':encoding(utf-8)') };
49     print TMP "=encoding UTF-8\n\n";
50     while (<DATA>) {
51         last if $_ eq "###\n";
52         print TMP $_;
53     }
54     close TMP;
55     open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n";
56     eval { binmode (\*OUT, ':encoding(utf-8)') };
57     $parser->parse_from_file ('tmp.pod', \*OUT);
58     close OUT;
59     open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
60     eval { binmode (\*TMP, ':encoding(utf-8)') };
61     my $output;
62     {
63         local $/;
64         $output = <TMP>;
65     }
66     close TMP;
67     unlink ('tmp.pod', 'out.tmp');
68     my $expected = '';
69     while (<DATA>) {
70         last if $_ eq "###\n";
71         $expected .= $_;
72     }
73     if ($output eq $expected) {
74         print "ok $n\n";
75     } else {
76         print "not ok $n\n";
77         print "Expected\n========\n$expected\nOutput\n======\n$output\n";
78     }
79     $n++;
80 }
81
82 # Below the marker are bits of POD and corresponding expected text output.
83 # This is used to test specific features or problems with Pod::Text.  The
84 # input and output are separated by lines containing only ###.
85
86 __DATA__
87
88 ###
89 =head1 Test of SE<lt>E<gt>
90
91 This is S<some whitespace>.
92 ###
93 Test of S<>
94     This is some whitespace.
95
96 ###
97
98 ###
99 =head1 I can eat glass
100
101 =over 4
102
103 =item Esperanto
104
105 Mi povas manĝi vitron, ĝi ne damaĝas min.
106
107 =item Braille
108
109 ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑
110
111 =item Hindi
112
113 मैं काँच खा सकता हूँ और मुझे उससे कोई चोट नहीं पहुंचती.
114
115 =back
116
117 See L<http://www.columbia.edu/kermit/utf8.html>
118 ###
119 I can eat glass
120     Esperanto
121         Mi povas manĝi vitron, ĝi ne damaĝas min.
122
123     Braille
124         ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑
125
126     Hindi
127         मैं काँच खा सकता हूँ और मुझे उससे कोई चोट नहीं पहुंचती.
128
129     See <http://www.columbia.edu/kermit/utf8.html>
130
131 ###