Commit | Line | Data |
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 | |
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"; |
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 | |
31 | END { |
32 | print "not ok 1\n" unless $loaded; |
33 | } |
34 | |
35 | use Pod::Text; |
bc9c7511 |
36 | |
37 | $loaded = 1; |
38 | print "ok 1\n"; |
39 | |
40 | my $parser = Pod::Text->new or die "Cannot create parser\n"; |
41 | my $n = 2; |
42 | eval { binmode (\*DATA, ':encoding(utf-8)') }; |
43 | eval { binmode (\*STDOUT, ':encoding(utf-8)') }; |
44 | while (<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 | |
89 | This is S<some whitespace>. |
90 | ### |
91 | Test 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 | |
103 | Mi 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 | |
115 | See L<http://www.columbia.edu/kermit/utf8.html> |
116 | ### |
117 | I 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 | ### |