xref: /openbsd-src/gnu/usr.bin/perl/cpan/Pod-Simple/t/rtf_utf8.t (revision 5486feefcc8cb79b19e014ab332cc5dfd05b3b33)
1# t/rtf_utf8.t - Check that RTF works with UTF-8 input
2use strict;
3use warnings;
4use Test::More;
5
6if ($] < 5.008) {
7    plan skip_all => "Doesn't work before 5.8";
8}
9else {
10    plan tests => 5;
11}
12
13use File::Spec;
14use Cwd ();
15use File::Basename ();
16
17my $t_dir = File::Basename::dirname(Cwd::abs_path(__FILE__));
18
19my $expected = join "", <DATA>;
20
21for my $format (qw(RTF)) {
22    my $class = "Pod::Simple::RTF";
23    use_ok $class or next;
24    ok my $parser = $class->new, "Construct RTF parser";
25
26    my $output = '';
27    ok $parser->output_string(\$output), "Set RTF output string";
28    ok $parser->parse_file(File::Spec->catfile($t_dir, qw(corpus polish_utf8.txt))),
29        "Parse to RTF via parse_file()";
30    $output =~ s/\\info.*?author \[see doc\]\}/VARIANT TEXT DELETED/s;
31    $output =~ s/$/\n/;
32
33    my $msg = "got expected output";
34    if ($output eq $expected) {
35        pass($msg);
36    }
37    elsif ($ENV{PERL_TEST_DIFF}) {
38        fail($msg);
39        require File::Temp;
40        my $orig_file = File::Temp->new();
41        local $/ = "\n";
42        chomp $expected;
43        print $orig_file $expected, "\n";
44        close $orig_file || die "Can't close orig_file: $!";
45
46        chomp $output;
47        my $parsed_file = File::Temp->new();
48        print $parsed_file $output, "\n";
49        close $parsed_file || die "Can't close parsed_file";
50
51        my $diff = File::Temp->new();
52        system("$ENV{PERL_TEST_DIFF} $orig_file $parsed_file > $diff");
53
54        open my $fh, "<", $diff || die "Can't open $diff";
55        my @diffs = <$fh>;
56        diag(@diffs);
57    }
58    else {
59        eval { require Text::Diff; };
60        if ($@) {
61            is($output, $expected, $msg);
62            diag("Set environment variable PERL_TEST_DIFF=diff_tool or install"
63            . " Text::Diff to see just the differences.");
64        }
65        else {
66            fail($msg);
67            diag Text::Diff::diff(\$expected, \$output, { STYLE => 'Unified' });
68        }
69    }
70}
71
72__DATA__
73{\rtf1\ansi\deff0
74
75{\fonttbl
76{\f0\froman Times New Roman;}
77{\f1\fmodern Courier New;}
78{\f2\fswiss Arial;}
79}
80
81{\stylesheet
82{\snext0 Normal;}
83{\*\cs10 \additive Default Paragraph Font;}
84{\*\cs16 \additive \i \sbasedon10 pod-I;}
85{\*\cs17 \additive \i\lang1024\noproof \sbasedon10 pod-F;}
86{\*\cs18 \additive \b \sbasedon10 pod-B;}
87{\*\cs19 \additive \f1\lang1024\noproof\sbasedon10 pod-C;}
88{\s20\ql \li0\ri0\sa180\widctlpar\f1\fs18\lang1024\noproof\sbasedon0 \snext0 pod-codeblock;}
89{\*\cs21 \additive \lang1024\noproof \sbasedon10 pod-computerese;}
90{\*\cs22 \additive \i\lang1024\noproof\sbasedon10 pod-L-pod;}
91{\*\cs23 \additive \i\lang1024\noproof\sbasedon10 pod-L-url;}
92{\*\cs24 \additive \i\lang1024\noproof\sbasedon10 pod-L-man;}
93
94{\*\cs25 \additive \f1\lang1024\noproof\sbasedon0 pod-codelbock-plain;}
95{\*\cs26 \additive \f1\lang1024\noproof\sbasedon25 pod-codelbock-ital;}
96{\*\cs27 \additive \f1\lang1024\noproof\sbasedon25 pod-codelbock-bold;}
97{\*\cs28 \additive \f1\lang1024\noproof\sbasedon25 pod-codelbock-bold-ital;}
98
99{\s31\ql \keepn\sb90\sa180\f2\fs32\ul\sbasedon0 \snext0 pod-head1;}
100{\s32\ql \keepn\sb90\sa180\f2\fs28\ul\sbasedon0 \snext0 pod-head2;}
101{\s33\ql \keepn\sb90\sa180\f2\fs25\ul\sbasedon0 \snext0 pod-head3;}
102{\s34\ql \keepn\sb90\sa180\f2\fs22\ul\sbasedon0 \snext0 pod-head4;}
103}
104
105{\colortbl;\red255\green0\blue0;\red0\green0\blue255;}
106{VARIANT TEXT DELETED{\company [see doc]}{\operator [see doc]}
107}
108
109\deflang1033\plain\lang1033\widowctrl
110{\header\pard\qr\plain\f2\fs17
111W\uc1\u346?R\'d3D NOCNEJ CISZY \_\_ explicitly utf8 test document in Polish,
112p.\chpgn\par}
113\fs25
114
115
116
117{\pard\li0\s31\keepn\sb90\sa180\f2\fs32\ul{
118NAME
119}\par}
120
121{\pard\li0\sa180
122W\uc1\u346?R\'d3D NOCNEJ CISZY \_\_ explicitly utf8 test document
123in Polish
124\par}
125
126{\pard\li0\s31\keepn\sb90\sa180\f2\fs32\ul{
127DESCRIPTION
128}\par}
129
130{\pard\li0\sa180
131This is a test Pod document in UT\'468. Its content is the lyrics
132to the Polish Christmas carol "W\uc1\u347?r\'f3d nocnej ciszy", except
133it includes a few lines to test RT\'46 specially.
134\par}
135
136{\pard\li0\sa180
137\uc1\u-1280? is a character in the upper half of Plane 0, so should
138be negative in RT\'46 \uc1\u-10187\u-8904? is a character in Plane
1391, so should be expressed as a surrogate pair in RT\'46
140\par}
141
142{\pard\li0\sa180
143All the ASCII printables !"#$%&\'5c'()*+,\_./0123456789:;<=>?@ ABCDE\'46GHIJKLMNOPQRSTUVWXYZ[{
144\cs21\lang1024\noproof \'5c]^\'5f`} abcdefghijklmnopqrstuvwxyz\'7b|\'7d~
145\par}
146
147{\pard\li0\sa180
148W\uc1\u347?r\'f3d nocnej ciszy g\uc1\u322?os si\uc1\u281? rozchodzi:
149/ Wsta\uc1\u324?cie, pasterze, B\'f3g si\uc1\u281? nam rodzi! / Czym
150pr\uc1\u281?dzej si\uc1\u281? wybierajcie, / Do Betlejem pospieszajcie
151/ Przywita\uc1\u263? Pana.
152\par}
153
154{\pard\li0\sa180
155Poszli, znale\uc1\u378?li Dzieci\uc1\u261?tko w \uc1\u380?\uc1\u322?obie
156/ Z wszystkimi znaki danymi sobie. / Jako Bogu cze\uc1\u347?\uc1\u263?
157Mu dali, / A witaj\uc1\u261?c zawo\uc1\u322?ali / Z wielkiej rado\uc1\u347?ci:
158\par}
159
160{\pard\li0\sa180
161Ach, witaj Zbawco z dawno \uc1\u380?\uc1\u261?dany, / Wiele tysi\uc1\u281?cy
162lat wygl\uc1\u261?dany / Na Ciebie kr\'f3le, prorocy / Czekali, a
163Ty\uc1\u347? tej nocy / Nam si\uc1\u281? objawi\uc1\u322?.
164\par}
165
166{\pard\li0\sa180
167I my czekamy na Ciebie, Pana, / A skoro przyjdziesz na g\uc1\u322?os
168kap\uc1\u322?ana, / Padniemy na twarz przed Tob\uc1\u261?, / Wierz\uc1\u261?c,
169\uc1\u380?e\uc1\u347? jest pod os\uc1\u322?on\uc1\u261? / Chleba i
170wina.
171\par}
172
173{\pard\li0\s32\keepn\sb90\sa180\f2\fs28\ul{
174As Verbatim
175}\par}
176
177{\pard\li0\sa180
178And now as verbatim text:
179\par}
180
181{\pard\li0\plain\s20\sa180\f1\fs18\lang1024\noproof
182  \uc1\u-1280?  upper half, Plane 0\line
183  \uc1\u-10187\u-8904? Plane 1\line
184\line
185  All the ASCII printables\line
186   !"#$%&\'5c'()*+,-./0123456789:;<=>?@\line
187  ABCDE\'46GHIJKLMNOPQRSTUVWXYZ[\'5c]^\'5f`\line
188  abcdefghijklmnopqrstuvwxyz\'7b|\'7d~\line
189\line
190  W\uc1\u347?r\'f3d nocnej ciszy g\uc1\u322?os si\uc1\u281? rozchodzi:\line
191  Wsta\uc1\u324?cie, pasterze, B\'f3g si\uc1\u281? nam rodzi!\line
192  Czym pr\uc1\u281?dzej si\uc1\u281? wybierajcie,\line
193  Do Betlejem pospieszajcie\line
194  Przywita\uc1\u263? Pana.\line
195\line
196  Poszli, znale\uc1\u378?li Dzieci\uc1\u261?tko w \uc1\u380?\uc1\u322?obie\line
197  Z wszystkimi znaki danymi sobie.\line
198  Jako Bogu cze\uc1\u347?\uc1\u263? Mu dali,\line
199  A witaj\uc1\u261?c zawo\uc1\u322?ali\line
200  Z wielkiej rado\uc1\u347?ci:\line
201\line
202  Ach, witaj Zbawco z dawno \uc1\u380?\uc1\u261?dany,\line
203  Wiele tysi\uc1\u281?cy lat wygl\uc1\u261?dany\line
204  Na Ciebie kr\'f3le, prorocy\line
205  Czekali, a Ty\uc1\u347? tej nocy\line
206  Nam si\uc1\u281? objawi\uc1\u322?.\line
207\line
208  I my czekamy na Ciebie, Pana,\line
209  A skoro przyjdziesz na g\uc1\u322?os kap\uc1\u322?ana,\line
210  Padniemy na twarz przed Tob\uc1\u261?,\line
211  Wierz\uc1\u261?c, \uc1\u380?e\uc1\u347? jest pod os\uc1\u322?on\uc1\u261?\line
212  Chleba i wina.
213\par}
214
215{\pard\li0\sa180
216[end]
217\par}
218}
219