1use strict;
2use warnings;
3
4use Test::More tests => 1;
5
6use Pod::Simple::JustPod;
7
8my @orig = <DATA>;
9my $parsed;
10
11my $parser = Pod::Simple::JustPod->new();
12$parser->output_string(\$parsed);
13$parser->parse_lines(@orig, undef);
14
15my $orig = join "", @orig;
16
17my $msg = "Verify parsed pod sufficiently matches original";
18if ($parsed eq $orig) {
19    pass($msg);
20}
21elsif ($ENV{PERL_TEST_DIFF}) {
22    fail($msg);
23    require File::Temp;
24    my $orig_file = File::Temp->new();
25    local $/ = "\n";
26    chomp $orig;
27    print $orig_file $orig, "\n";
28    close $orig_file || die "Can't close orig_file: $!";
29
30    chomp $parsed;
31    my $parsed_file = File::Temp->new();
32    print $parsed_file $parsed, "\n";
33    close $parsed_file || die "Can't close parsed_file";
34
35    my $diff = File::Temp->new();
36    system("$ENV{PERL_TEST_DIFF} $orig_file $parsed_file > $diff");
37
38    open my $fh, "<", $diff || die "Can't open $diff";
39    my @diffs = <$fh>;
40    diag(@diffs);
41}
42else {
43    eval { require Text::Diff; };
44    if ($@) {
45        is($parsed, $orig, $msg);
46        diag("Set environment variable PERL_TEST_DIFF=diff_tool or install"
47           . " Text::Diff to see just the differences.");
48    }
49    else {
50        fail($msg);
51        diag Text::Diff::diff(\$orig, \$parsed, { STYLE => 'Unified' });
52    }
53}
54
55# The data is adapted from a test file from pod2lators.  Extra spaces are
56# added in places to make sure they get retained, and some extra tests
57__DATA__
58=pod
59
60=encoding  ASCII
61
62=head1 NAME
63
64basic.pod - Test of various basic POD features in translators.
65
66=head1 HEADINGS
67
68Try a few different levels of headings, with embedded formatting codes and
69other interesting bits.
70
71=head1 This C<is> a "level 1" heading
72
73=head2  ``Level'' "2 I<heading>
74
75=head3  Level 3 B<heading I<with C<weird F<stuff "" (double quote)>>>>
76
77=head4  Level "4 C<heading>
78
79=head5  Level "5 B<heading>
80
81=head6  Level "6 I<heading>
82
83Now try again with B<intermixed> F<text>.
84
85=head1 This C<is> a "level 1" heading
86
87Text.
88
89=head2 ``Level'' 2 I<heading>
90
91Text.
92
93=head3 Level 3 B<heading I<with C<weird F<stuff>>>>
94
95Text.
96
97=head4 Level "4 C<heading>
98
99Text.
100
101=head5  Level "5 B<heading>
102
103Text.
104
105=head6  Level "6 I<heading>
106
107Text.
108
109=head1 LINKS
110
111These are all taken from the Pod::Parser tests.
112
113Try out I<LOTS> of different ways of specifying references:
114
115Reference the L<manpage/section>
116
117Reference the L<"manpage"/section>
118
119Reference the L<manpage/"section">
120
121Now try it using the new "|" stuff ...
122
123Reference the L<thistext|manpage/section>|
124
125Reference the L<thistext | manpage / section>|
126
127Reference the L<thistext| manpage/ section>|
128
129Reference the L<thistext |manpage /section>|
130
131Reference the L<thistext|manpage/"section">|
132
133Reference the L<thistext|
134manpage/
135section>|
136
137And then throw in a few new ones of my own.
138
139L<foo>
140
141L<foo|bar>
142
143L<foo/bar>
144
145L<foo/"baz boo">
146
147L</bar>
148
149L</"baz boo">
150
151L</baz boo>
152
153L<foo bar/baz boo>
154
155L<"boo var baz">
156
157L<bar baz>
158
159L</boo>, L</bar>, and L</baz>
160
161L<fooZ<>bar>
162
163L<Testing I<italics>|foo/bar>
164
165L<foo/I<Italic> text>
166
167L<fooE<verbar>barZ<>/Section C<with> I<B<other> markup>>
168
169=head1 OVER AND ITEMS
170
171Taken from Pod::Parser tests, this is a test to ensure that multiline
172=item paragraphs get indented appropriately.
173
174=over 4
175
176=item This
177is
178a
179test.
180
181=back
182
183There should be whitespace now before this line.
184
185Taken from Pod::Parser tests, this is a test to ensure the nested =item
186paragraphs get indented appropriately.
187
188=over  2
189
190=item  1
191
192First section.
193
194=over 2
195
196=item a
197
198this is item a
199
200=item b
201
202this is item b
203
204=back
205
206=item 2
207
208Second section.
209
210=over 2
211
212=item  a
213
214this is item a
215
216=item b
217
218this is item b
219
220=item c
221
222=item d
223
224This is item c & d.
225
226=back
227
228=back
229
230Now some additional weirdness of our own.  Make sure that multiple tags
231for one paragraph are properly compacted.
232
233=over 4
234
235=item  "foo"
236
237=item B<bar>
238
239=item C<baz>
240
241There shouldn't be any spaces between any of these item tags; this idiom
242is used in perlfunc.
243
244=item   Some longer item text
245
246Just to make sure that we test paragraphs where the item text doesn't fit
247in the margin of the paragraph (and make sure that this paragraph fills a
248few lines).
249
250Let's also make it multiple paragraphs to be sure that works.
251
252=back
253
254Test use of =over without =item as a block "quote" or block paragraph.
255
256=over 4
257
258This should be indented four spaces but otherwise formatted the same as
259any other regular text paragraph.  Make sure it's long enough to see the
260results of the formatting.....
261
262=back
263
264Now try the same thing nested, and make sure that the indentation is reset
265back properly.
266
267=over 4
268
269=over 4
270
271This paragraph should be doubly indented.
272
273=back
274
275This paragraph should only be singly indented.
276
277=over 4
278
279=item
280
281This is an item in the middle of a block-quote, which should be allowed.
282
283=item
284
285We're also testing tagless item commands.
286
287=back
288
289Should be back to the single level of indentation.
290
291=back
292
293Should be back to regular indentation.
294
295Now also check the transformation of * into real bullets for man pages.
296
297=over
298
299=item *
300
301An item.  We're also testing using =over without a number, and making sure
302that item text wraps properly.
303
304=item  *
305
306Another item.
307
308=back
309
310and now test the numbering of item blocks.
311
312=over 4
313
314=item  1.
315
316First item.
317
318=item 2.
319
320Second item.
321
322=back
323
324=head1   FORMATTING    CODES
325
326Another test taken from Pod::Parser.
327
328This is a test to see if I can do not only C<$self> and C<method()>, but
329also C<< $self->method() >> and C<< $self->{FIELDNAME} >> and
330C<< $Foo <=> $Bar >> without resorting to escape sequences. If
331I want to refer to the right-shift operator I can do something
332like C<<< $x >> 3 >>> or even C<<<< $y >> 5 >>>>.
333
334Now for the grand finale of C<< $self->method()->{FIELDNAME} = {FOO=>BAR} >>.
335And I also want to make sure that newlines work like this
336C<<<
337$self->{FOOBAR} >> 3 and [$b => $a]->[$a <=> $b]
338>>>
339
340Of course I should still be able to do all this I<with> escape sequences
341too: C<$self-E<gt>method()> and C<$self-E<gt>{FIELDNAME}> and
342C<{FOO=E<gt>BAR}>.
343
344Dont forget C<$self-E<gt>method()-E<gt>{FIELDNAME} = {FOO=E<gt>BAR}>.
345
346And make sure that C<0> works too!
347
348Now, if I use << or >> as my delimiters, then I have to use whitespace.
349So things like C<<$self->method()>> and C<<$self->{FIELDNAME}>> wont end
350up doing what you might expect since the first > will still terminate
351the first < seen.
352
353Lets make sure these work for empty ones too, like C<<<  >>>,
354C<<<<
355>>>>, and C<< >> >> (just to be obnoxious)
356
357The statement: C<This is dog kind's I<finest> hour!> is a parody of a
358quotation from Winston Churchill.
359
360The following tests are added to those:
361
362Make sure that a few othZ<>er odd I<Z<>things> still work.  This should be
363a vertical bar:  E<verbar>.  Here's a test of a few more special escapes
364that have to be supported:
365
366=over 3
367
368=item  E<amp>
369
370An ampersand.
371
372=item E<apos>
373
374An apostrophe.
375
376=item E<lt>
377
378A less-than sign.
379
380=item E<gt>
381
382A greater-than sign.
383
384=item E<quot>
385
386A double quotation mark.
387
388=item E<sol>
389
390A forward slash.
391
392=back
393
394Try to get this bit of text over towards the edge so S<|that all of this
395text inside SE<lt>E<gt> won't|> be wrapped.  Also test the
396|sameE<nbsp>thingE<nbsp>withE<nbsp>non-breakingS< spaces>.|
397
398There is a soft hyE<shy>phen in hyphen at hy-phen.
399
400This is a test of an X<index entry>index entry.
401
402=head1 VERBATIM
403
404Throw in a few verbatim paragraphs.
405
406    use Term::ANSIColor;
407    print color 'bold blue';
408    print "This text is bold blue.\n";
409    print color 'reset';
410    print "This text is normal.\n";
411    print colored ("Yellow on magenta.\n", 'yellow on_magenta');
412    print "This text is normal.\n";
413    print colored ['yellow on_magenta'], "Yellow on magenta.\n";
414
415    use Term::ANSIColor qw(uncolor);
416    print uncolor '01;31', "\n";
417
418But this isn't verbatim (make sure it wraps properly), and the next
419paragraph is again:
420
421    use Term::ANSIColor qw(:constants);
422    print BOLD, BLUE, "This text is in bold blue.\n", RESET;
423
424    use Term::ANSIColor qw(:constants); $Term::ANSIColor::AUTORESET = 1; print BOLD BLUE "This text is in bold blue.\n"; print "This text is normal.\n";
425
426(Ugh, that's obnoxiously long.)  Try different spacing:
427
428	Starting with a tab.
429Not
430starting
431with
432a
433tab.  But this should still be verbatim.
434 As should this.
435
436This isn't.
437
438 This is.  And this:	is an internal tab.  It should be:
439                    |--| <= lined up with that.
440
441(Tricky, but tabs should be expanded before the translator starts in on
442the text since otherwise text with mixed tabs and spaces will get messed
443up.)
444
445    And now we test verbatim paragraphs right before a heading.  Older
446    versions of Pod::Man generated two spaces between paragraphs like this
447    and the heading.  (In order to properly test this, one may have to
448    visually inspect the nroff output when run on the generated *roff
449    text, unfortunately.)
450
451=head1 CONCLUSION
452
453That's all, folks!
454
455=cut
456