This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Pod-Simple to CPAN version 3.18
[perl5.git] / cpan / Pod-Simple / t / fcodes_s.t
1 # fcodes S
2 BEGIN {
3     if($ENV{PERL_CORE}) {
4         chdir 't';
5         @INC = '../lib';
6     }
7 }
8
9 use strict;
10 use Test;
11 BEGIN { plan tests => 80 };
12
13 #use Pod::Simple::Debug (6);
14
15 ok 1;
16
17 use Pod::Simple::XMLOutStream;
18 print "# Pod::Simple version $Pod::Simple::VERSION\n";
19 my $x = 'Pod::Simple::XMLOutStream';
20 sub e ($$) { $x->_duo(@_) }
21
22 $Pod::Simple::XMLOutStream::ATTR_PAD   = ' ';
23 $Pod::Simple::XMLOutStream::SORT_ATTRS = 1; # for predictably testable output
24
25
26 print "# S as such...\n";
27
28 ok( $x->_out("=pod\n\nI like S<bric-a-brac>.\n"),
29  =>  '<Document><Para>I like <S>bric-a-brac</S>.</Para></Document>' );
30 ok( $x->_out("=pod\n\nI like S<bric-a-brac a gogo >.\n"),
31  =>  '<Document><Para>I like <S>bric-a-brac a gogo </S>.</Para></Document>' );
32 ok( $x->_out("=pod\n\nI like S<< bric-a-brac a gogo >>.\n"),
33  =>  '<Document><Para>I like <S>bric-a-brac a gogo</S>.</Para></Document>' );
34
35 my $unless_ascii = (chr(65) eq 'A') ? '' :
36  "Skip because not in ASCIIland";
37
38 skip( $unless_ascii,
39     $x->_out( sub { $_[0]->nbsp_for_S(1) },
40     "=pod\n\nI like S<bric-a-brac a gogo>.\n"),
41 '<Document><Para>I like bric-a-brac&#160;a&#160;gogo.</Para></Document>'
42 );
43 skip( $unless_ascii,
44     $x->_out( sub { $_[0]->nbsp_for_S(1) },
45     qq{=pod\n\nI like S<L</"bric-a-brac a gogo">>.\n}),
46 '<Document><Para>I like <L content-implicit="yes" section="bric-a-brac a gogo" type="pod">&#34;bric-a-brac&#160;a&#160;gogo&#34;</L>.</Para></Document>'
47 );
48 skip( $unless_ascii,
49     $x->_out( sub { $_[0]->nbsp_for_S(1) },
50     qq{=pod\n\nI like S<L<Stuff like that|/"bric-a-brac a gogo">>.\n}),
51 '<Document><Para>I like <L section="bric-a-brac a gogo" type="pod">Stuff&#160;like&#160;that</L>.</Para></Document>'
52 );
53 skip( $unless_ascii,
54     $x->_out( sub { $_[0]->nbsp_for_S(1) },
55     qq{=pod\n\nI like S<L<Stuff I<like that>|/"bric-a-brac a gogo">>.\n}),
56 '<Document><Para>I like <L section="bric-a-brac a gogo" type="pod">Stuff&#160;<I>like&#160;that</I></L>.</Para></Document>'
57 );
58
59 &ok( $x->_duo( sub { $_[0]->nbsp_for_S(1) },
60   "=pod\n\nI like S<bric-a-brac a gogo>.\n",
61   "=pod\n\nI like bric-a-bracE<160>aE<160>gogo.\n",
62 ));
63 &ok(
64   map {my $z = $_; $z =~ s/content-implicit="yes" //g; $z }
65   $x->_duo( sub { $_[0]->nbsp_for_S(1) },
66     qq{=pod\n\nI like S<L</"bric-a-brac a gogo">>.\n},
67     qq{=pod\n\nI like L<"bric-a-bracE<160>aE<160>gogo"|/"bric-a-brac a gogo">.\n},
68 ));
69 &ok( $x->_duo( sub { $_[0]->nbsp_for_S(1) },
70     qq{=pod\n\nI like S<L<Stuff like that|"bric-a-brac a gogo">>.\n},
71     qq{=pod\n\nI like L<StuffE<160>likeE<160>that|"bric-a-brac a gogo">.\n},
72 ));
73 &ok(
74   map {my $z = $_; $z =~ s/content-implicit="yes" //g; $z }
75   $x->_duo( sub { $_[0]->nbsp_for_S(1) },
76     qq{=pod\n\nI like S<L<Stuff I<like that>|"bric-a-brac a gogo">>.\n},
77     qq{=pod\n\nI like L<StuffE<160>I<likeE<160>that>|"bric-a-brac a gogo">.\n},
78 ));
79
80 use Pod::Simple::Text;
81 $x = Pod::Simple::Text->new;
82 $x->preserve_whitespace(1);
83 # RT#25679
84 ok(
85   $x->_out(<<END
86 =head1 The Tk::mega manpage showed me how C<< SE<lt> > foo >> is being rendered
87
88 Both pod2text and pod2man S<    > lose the rest of the line
89
90 =head1 Do they always S<    > lose the rest of the line?
91
92 =cut
93 END
94   ),
95   <<END
96 The Tk::mega manpage showed me how S< > foo is being rendered
97
98     Both pod2text and pod2man      lose the rest of the line
99
100 Do they always      lose the rest of the line?
101
102 END
103 );
104
105 $x = 'Pod::Simple::Text';
106 # Test text output of links.
107 ok(
108     $x->_out(qq{=pod\n\nL<Net::Ping>\n}),
109     "    Net::Ping\n\n"
110 );
111
112 ok(
113     $x->_out(qq{=pod\n\nBe sure to read the L<Net::Ping> docs\n}),
114     "    Be sure to read the Net::Ping docs\n\n"
115 );
116
117 ok(
118     $x->_out(qq{=pod\n\nL<http://www.perl.com>\n}),
119     "    http://www.perl.com\n\n"
120 );
121
122 ok(
123     $x->_out(qq{=pod\n\nL<crontab(5)>\n}),
124     "    crontab(5)\n\n"
125 );
126
127 ok(
128     $x->_out(qq{=pod\n\nL<Net::Ping/Ping-pong>\n}),
129     qq{    "Ping-pong" in Net::Ping\n\n}
130 );
131
132 ok(
133     $x->_out(qq{=pod\n\nL</"Object Methods">\n}),
134     qq{    "Object Methods"\n\n}
135 );
136
137 ok(
138     $x->_out(qq{=pod\n\nL</Object Methods>\n}),
139     qq{    "Object Methods"\n\n}
140 );
141
142 ok(
143     $x->_out(qq{=pod\n\nL<"Object Methods">\n}),
144     qq{    "Object Methods"\n\n}
145 );
146
147 ok(
148     $x->_out(qq{=pod\n\nL<Net::Ping/Ping-E<112>ong>\n}),
149     qq{    "Ping-pong" in Net::Ping\n\n}
150 );
151
152 ok(
153     $x->_out(qq{=pod\n\nL<news:comp.lang.perl.misc>\n}),
154     "    news:comp.lang.perl.misc\n\n"
155 );
156
157 ok(
158     $x->_out(qq{=pod\n\nL<http://www.perl.org>\n}),
159     "    http://www.perl.org\n\n"
160 );
161
162 ok(
163     $x->_out(qq{=pod\n\nSee L<http://www.perl.org>\n}),
164     "    See http://www.perl.org\n\n"
165 );
166
167 ok(
168     $x->_out(qq{=pod\n\nL<http://www.perl.org/CPAN/authors/id/S/SB/SBURKE/>\n}),
169     "    http://www.perl.org/CPAN/authors/id/S/SB/SBURKE/\n\n"
170 );
171
172 ok(
173     $x->_out(qq{=pod\n\nL<news:compE<46>lang.perl.misc>\n}),
174     "    news:comp.lang.perl.misc\n\n"
175 );
176
177 ok(
178     $x->_out(qq{=pod\n\nL<http://wwwE<46>perl.org>\n}),
179     "    http://www.perl.org\n\n"
180 );
181
182 ok(
183     $x->_out(qq{=pod\n\nL<things|crontab(5)>\n}),
184     "    things\n\n"
185 );
186
187 ok(
188     $x->_out(qq{=pod\n\nL<things|crontab(5)/ENVIRONMENT>\n}),
189     "    things\n\n"
190 );
191
192 ok(
193     $x->_out(qq{=pod\n\nL<Perl Error Messages|perldiag>\n}),
194     "    Perl Error Messages\n\n"
195 );
196
197 ok(
198     $x->_out(qq{=pod\n\nL<Perl\nError\nMessages|perldiag>\n}),
199     "    Perl Error Messages\n\n"
200 );
201
202 ok(
203     $x->_out(qq{=pod\n\nL<Perl\nError\t  Messages|perldiag>\n}),
204     "    Perl Error Messages\n\n"
205 );
206
207 ok(
208     $x->_out(qq{=pod\n\nL<perl.org|http://www.perl.org>\n}),
209     "    perl.org <http://www.perl.org>\n\n"
210 );
211
212 ok(
213     $x->_out(qq{=pod\n\nSee L<perl.org|http://www.perl.org>\n}),
214     "    See perl.org <http://www.perl.org>\n\n"
215 );
216
217
218 # Test HTML output of links.
219 use Pod::Simple::HTML;
220 my $PERLDOC = "http://search.cpan.org/perldoc";
221 my $MANURL = "http://man.he.net/man";
222 sub x ($) {
223     Pod::Simple::HTML->_out(
224         sub {  $_[0]->bare_output(1)  },
225         "=pod\n\n$_[0]",
226     )
227 }
228
229 ok(
230     x(qq{L<Net::Ping>\n}),
231     qq{\n<p><a href="$PERLDOC?Net%3A%3APing" class="podlinkpod"\n>Net::Ping</a></p>\n}
232 );
233
234 ok(
235     x(qq{Be sure to read the L<Net::Ping> docs\n}),
236     qq{\n<p>Be sure to read the <a href="$PERLDOC?Net%3A%3APing" class="podlinkpod"\n>Net::Ping</a> docs</p>\n}
237 );
238
239 ok(
240     x(qq{L<http://www.perl.com>\n}),
241     qq{\n<p><a href="http://www.perl.com" class="podlinkurl"\n>http://www.perl.com</a></p>\n}
242 );
243
244 ok(
245     x(qq{L<crontab(5)>\n}),
246     qq{\n<p><a href="${MANURL}5/crontab" class="podlinkman"\n>crontab(5)</a></p>\n}
247 );
248
249 ok(
250     x(qq{L<Net::Ping/Ping-pong>\n}),
251     qq{\n<p><a href="$PERLDOC?Net%3A%3APing#Ping-pong" class="podlinkpod"\n>&#34;Ping-pong&#34; in Net::Ping</a></p>\n}
252 );
253
254 ok(
255     x(qq{L</"Object Methods">\n}),
256     qq{\n<p><a href="#Object_Methods" class="podlinkpod"\n>&#34;Object Methods&#34;</a></p>\n}
257 );
258
259 ok(
260     x(qq{L</Object Methods>\n}),
261     qq{\n<p><a href="#Object_Methods" class="podlinkpod"\n>&#34;Object Methods&#34;</a></p>\n}
262 );
263
264 ok(
265     x(qq{L<"Object Methods">\n}),
266     qq{\n<p><a href="#Object_Methods" class="podlinkpod"\n>&#34;Object Methods&#34;</a></p>\n}
267 );
268
269 ok(
270     x(qq{L<Net::Ping/Ping-E<112>ong>\n}),
271     qq{\n<p><a href="$PERLDOC?Net%3A%3APing#Ping-pong" class="podlinkpod"\n>&#34;Ping-pong&#34; in Net::Ping</a></p>\n}
272 );
273
274 ok(
275     x(qq{L<news:comp.lang.perl.misc>\n}),
276     qq{\n<p><a href="news:comp.lang.perl.misc" class="podlinkurl"\n>news:comp.lang.perl.misc</a></p>\n}
277 );
278
279 ok(
280     x(qq{L<http://www.perl.org>\n}),
281     qq{\n<p><a href="http://www.perl.org" class="podlinkurl"\n>http://www.perl.org</a></p>\n}
282 );
283
284 ok(
285     x(qq{See L<http://www.perl.org>\n}),
286     qq{\n<p>See <a href="http://www.perl.org" class="podlinkurl"\n>http://www.perl.org</a></p>\n}
287 );
288
289 ok(
290     x(qq{L<http://www.perl.org/CPAN/authors/id/S/SB/SBURKE/>\n}),
291     qq{\n<p><a href="http://www.perl.org/CPAN/authors/id/S/SB/SBURKE/" class="podlinkurl"\n>http://www.perl.org/CPAN/authors/id/S/SB/SBURKE/</a></p>\n}
292 );
293
294 ok(
295     x(qq{L<news:compE<46>lang.perl.misc>\n}),
296     qq{\n<p><a href="news:comp.lang.perl.misc" class="podlinkurl"\n>news:comp.lang.perl.misc</a></p>\n}
297 );
298
299 ok(
300     x(qq{L<http://wwwE<46>perl.org>\n}),
301     qq{\n<p><a href="http://www.perl.org" class="podlinkurl"\n>http://www.perl.org</a></p>\n}
302 );
303
304 ok(
305     x(qq{L<things|crontab(5)>\n}),
306     qq{\n<p><a href="${MANURL}5/crontab" class="podlinkman"\n>things</a></p>\n}
307 );
308
309 ok(
310     x(qq{L<things|crontab(5)/ENVIRONMENT>\n}),
311     qq{\n<p><a href="${MANURL}5/crontab" class="podlinkman"\n>things</a></p>\n}
312 );
313
314 ok(
315     x(qq{L<Perl Error Messages|perldiag>\n}),
316     qq{\n<p><a href="$PERLDOC?perldiag" class="podlinkpod"\n>Perl Error Messages</a></p>\n}
317 );
318
319 ok(
320     x(qq{L<Perl\nError\nMessages|perldiag>\n}),
321     qq{\n<p><a href="$PERLDOC?perldiag" class="podlinkpod"\n>Perl Error Messages</a></p>\n}
322 );
323
324 ok(
325     x(qq{L<Perl\nError\t  Messages|perldiag>\n}),
326     qq{\n<p><a href="$PERLDOC?perldiag" class="podlinkpod"\n>Perl Error Messages</a></p>\n}
327 );
328
329 ok(
330     x(qq{L<perl.org|http://www.perl.org>\n}),
331     qq{\n<p><a href="http://www.perl.org" class="podlinkurl"\n>perl.org</a></p>\n}
332 );
333
334 ok(
335     x(qq{See L<perl.org|http://www.perl.org>\n}),
336     qq{\n<p>See <a href="http://www.perl.org" class="podlinkurl"\n>perl.org</a></p>\n}
337 );
338
339 # Test link output in XHTML.
340 use Pod::Simple::XHTML;
341 sub o ($) {
342     my $p = Pod::Simple::XHTML->new;
343     $p->html_header("");
344     $p->html_footer("");
345     my $results = '';
346     $p->output_string( \$results ); # Send the resulting output to a string
347     $p->parse_string_document("=pod\n\n$_[0]");
348     return $results;
349 }
350
351 ok(
352     o(qq{L<Net::Ping>}),
353     qq{<p><a href="$PERLDOC?Net::Ping">Net::Ping</a></p>\n\n}
354 );
355
356 ok(
357     o(qq{Be sure to read the L<Net::Ping> docs}),
358     qq{<p>Be sure to read the <a href="$PERLDOC?Net::Ping">Net::Ping</a> docs</p>\n\n}
359 );
360
361 ok(
362     o(qq{L<http://www.perl.com>}),
363     qq{<p><a href="http://www.perl.com">http://www.perl.com</a></p>\n\n}
364 );
365
366 ok(
367     o(qq{L<crontab(5)>}),
368     qq{<p><a href="${MANURL}5/crontab">crontab(5)</a></p>\n\n}
369 );
370
371 ok(
372     o(qq{L<Net::Ping/Ping-pong>}),
373     qq{<p><a href="$PERLDOC?Net::Ping#Ping-pong">&quot;Ping-pong&quot; in Net::Ping</a></p>\n\n}
374 );
375
376 ok(
377     o(qq{L</"Object Methods">}),
378     qq{<p><a href="#Object-Methods">&quot;Object Methods&quot;</a></p>\n\n}
379 );
380
381 ok(
382     o(qq{L</Object Methods>}),
383     qq{<p><a href="#Object-Methods">&quot;Object Methods&quot;</a></p>\n\n}
384 );
385
386 ok(
387     o(qq{L<"Object Methods">}),
388     qq{<p><a href="#Object-Methods">&quot;Object Methods&quot;</a></p>\n\n}
389 );
390
391 ok(
392     o(qq{L<Net::Ping/Ping-E<112>ong>}),
393     qq{<p><a href="$PERLDOC?Net::Ping#Ping-pong">&quot;Ping-pong&quot; in Net::Ping</a></p>\n\n}
394 );
395
396 ok(
397     o(qq{L<news:comp.lang.perl.misc>}),
398     qq{<p><a href="news:comp.lang.perl.misc">news:comp.lang.perl.misc</a></p>\n\n}
399 );
400
401 ok(
402     o(qq{L<http://www.perl.org>}),
403     qq{<p><a href="http://www.perl.org">http://www.perl.org</a></p>\n\n}
404 );
405
406 ok(
407     o(qq{See L<http://www.perl.org>}),
408     qq{<p>See <a href="http://www.perl.org">http://www.perl.org</a></p>\n\n}
409 );
410
411 ok(
412     o(qq{L<http://www.perl.org/CPAN/authors/id/S/SB/SBURKE/>}),
413     qq{<p><a href="http://www.perl.org/CPAN/authors/id/S/SB/SBURKE/">http://www.perl.org/CPAN/authors/id/S/SB/SBURKE/</a></p>\n\n}
414 );
415
416 ok(
417     o(qq{L<news:compE<46>lang.perl.misc>}),
418     qq{<p><a href="news:comp.lang.perl.misc">news:comp.lang.perl.misc</a></p>\n\n}
419 );
420
421 ok(
422     o(qq{L<http://wwwE<46>perl.org>}),
423     qq{<p><a href="http://www.perl.org">http://www.perl.org</a></p>\n\n}
424 );
425
426 ok(
427     o(qq{L<things|crontab(5)>}),
428     qq{<p><a href="${MANURL}5/crontab">things</a></p>\n\n}
429 );
430
431 ok(
432     o(qq{L<things|crontab(5)/ENVIRONMENT>}),
433     qq{<p><a href="${MANURL}5/crontab">things</a></p>\n\n}
434 );
435
436 ok(
437     o(qq{L<Perl Error Messages|perldiag>}),
438     qq{<p><a href="$PERLDOC?perldiag">Perl Error Messages</a></p>\n\n}
439 );
440
441 ok(
442     o(qq{L<Perl\nError\nMessages|perldiag>}),
443     qq{<p><a href="$PERLDOC?perldiag">Perl Error Messages</a></p>\n\n}
444 );
445
446 ok(
447     o(qq{L<Perl\nError\t  Messages|perldiag>}),
448     qq{<p><a href="$PERLDOC?perldiag">Perl Error Messages</a></p>\n\n}
449 );
450
451 ok(
452     o(qq{L<perl.org|http://www.perl.org>}),
453     qq{<p><a href="http://www.perl.org">perl.org</a></p>\n\n}
454 );
455
456 ok(
457     o(qq{See L<perl.org|http://www.perl.org>}),
458     qq{<p>See <a href="http://www.perl.org">perl.org</a></p>\n\n}
459 );
460
461 print "# Wrapping up... one for the road...\n";
462 ok 1;
463 print "# --- Done with ", __FILE__, " --- \n";
464