Upgrade to podlators-2.2.0
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / text-utf8.t
CommitLineData
bc9c7511 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
10BEGIN {
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";
2504ae52 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 }
bc9c7511 29}
30
31END {
32 print "not ok 1\n" unless $loaded;
33}
34
35use Pod::Text;
bc9c7511 36
37$loaded = 1;
38print "ok 1\n";
39
40my $parser = Pod::Text->new or die "Cannot create parser\n";
41my $n = 2;
42eval { binmode (\*DATA, ':encoding(utf-8)') };
43eval { binmode (\*STDOUT, ':encoding(utf-8)') };
44while (<DATA>) {
45 next until $_ eq "###\n";
46 open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n";
47 eval { binmode (\*TMP, ':encoding(utf-8)') };
48 print TMP "=encoding UTF-8\n\n";
49 while (<DATA>) {
50 last if $_ eq "###\n";
51 print TMP $_;
52 }
53 close TMP;
54 open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n";
bc9c7511 55 $parser->parse_from_file ('tmp.pod', \*OUT);
56 close OUT;
57 open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
58 eval { binmode (\*TMP, ':encoding(utf-8)') };
59 my $output;
60 {
61 local $/;
62 $output = <TMP>;
63 }
64 close TMP;
65 unlink ('tmp.pod', 'out.tmp');
66 my $expected = '';
67 while (<DATA>) {
68 last if $_ eq "###\n";
69 $expected .= $_;
70 }
71 if ($output eq $expected) {
72 print "ok $n\n";
73 } else {
74 print "not ok $n\n";
75 print "Expected\n========\n$expected\nOutput\n======\n$output\n";
76 }
77 $n++;
78}
79
80# Below the marker are bits of POD and corresponding expected text output.
81# This is used to test specific features or problems with Pod::Text. The
82# input and output are separated by lines containing only ###.
83
84__DATA__
85
86###
87=head1 Test of SE<lt>E<gt>
88
89This is S<some whitespace>.
90###
91Test of S<>
92 This is some whitespace.
93
94###
95
96###
97=head1 I can eat glass
98
99=over 4
100
101=item Esperanto
102
103Mi povas manĝi vitron, ĝi ne damaĝas min.
104
105=item Braille
106
107⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑
108
109=item Hindi
110
111मैं काँच खा सकता हूँ और मुझे उससे कोई चोट नहीं पहुंचती.
112
113=back
114
115See L<http://www.columbia.edu/kermit/utf8.html>
116###
117I can eat glass
118 Esperanto
119 Mi povas manĝi vitron, ĝi ne damaĝas min.
120
121 Braille
122 ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑
123
124 Hindi
125 मैं काँच खा सकता हूँ और मुझे उससे कोई चोट नहीं पहुंचती.
126
127 See <http://www.columbia.edu/kermit/utf8.html>
128
129###