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