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