xref: /openbsd-src/gnu/usr.bin/perl/cpan/Pod-Simple/t/cbacks.t (revision 5486feefcc8cb79b19e014ab332cc5dfd05b3b33)
1b39c5158Smillertuse strict;
2256a93a4Safresh1use warnings;
3*5486feefSafresh1use Test::More tests => 6;
4b39c5158Smillert
5b39c5158Smillertmy $d;
6b39c5158Smillert#use Pod::Simple::Debug (\$d, 0);
7b39c5158Smillert
8b39c5158Smillertuse Pod::Simple::XMLOutStream;
9b39c5158Smillertuse Pod::Simple::DumpAsXML;
10b39c5158Smillertuse Pod::Simple::DumpAsText;
11b39c5158Smillert
12b39c5158Smillertmy @from = (
13b39c5158Smillert 'Pod::Simple::XMLOutStream'
14b39c5158Smillert  => '<Document><head1>I LIKE PIE</head1></Document>',
15b39c5158Smillert
16b39c5158Smillert 'Pod::Simple::DumpAsXML'
17b39c5158Smillert  => "<Document>\n  <head1>\n    I LIKE PIE\n  </head1>\n</Document>\n",
18b39c5158Smillert
19b39c5158Smillert 'Pod::Simple::DumpAsText'
20b39c5158Smillert  => "++Document\n  ++head1\n    * \"I LIKE PIE\"\n  --head1\n--Document\n",
21b39c5158Smillert
22b39c5158Smillert);
23b39c5158Smillert
24b39c5158Smillert
25b39c5158Smillert# Might as well test all the classes...
26b39c5158Smillertwhile(@from) {
27b39c5158Smillert  my($x => $expected) = splice(@from, 0,2);
28b39c5158Smillert  my $more = '';
29b39c5158Smillert  print "#Testing via class $x, version ", $x->VERSION(), "\n";
30b39c5158Smillert  my $p = $x->new;
31b39c5158Smillert  my($got, $exp);
32*5486feefSafresh1  is scalar($got = $x->_out(
33b39c5158Smillert    # Mutor:
34b39c5158Smillert    sub {
35b39c5158Smillert     $_[0]->code_handler(sub { $more .= $_[1] . ":" . $_[0] . "\n"       } );
36b39c5158Smillert     $_[0]->cut_handler( sub { $more .= "~" . $_[1] . ":" .  $_[0]. "\n" } );
37898184e3Ssthen     $_[0]->pod_handler( sub { $more .= "+" . $_[1] . ":" .  $_[0]. "\n" } );
38898184e3Ssthen     $_[0]->whiteline_handler(
39898184e3Ssthen                         sub { $more .= "=" . $_[1] . ":" .  $_[0]. "\n" } );
40b39c5158Smillert    } => join "\n",
41898184e3Ssthen    " ", # space outside pod
42b39c5158Smillert    "\t# This is handy...",
43898184e3Ssthen    "=pod text",
44898184e3Ssthen    "\t", # tab inside pod
45898184e3Ssthen    "=cut more text",
46898184e3Ssthen    "\t", # tab outside pod
47898184e3Ssthen    "=pod",
48898184e3Ssthen    " \t ", # spaces and tabs inside pod
49b39c5158Smillert    "=head1 I  LIKE   PIE",
50898184e3Ssthen    " ", # space inside pod
51b39c5158Smillert    "=cut",
52b39c5158Smillert    "use Test::Harness;",
53b39c5158Smillert    "runtests(sort glob 't/*.t');",
54b39c5158Smillert    "",
55b39c5158Smillert    "",
56b39c5158Smillert   ))
57b39c5158Smillert    => scalar($exp = $expected);
58b39c5158Smillert  ;
59b39c5158Smillert  unless($got eq $exp) {
60b39c5158Smillert    print '# Got vs exp:\n# ', Pod::Simple::BlackBox::pretty($got),
61b39c5158Smillert     "\n# ",Pod::Simple::BlackBox::pretty($exp),"\n";
62b39c5158Smillert  }
63b39c5158Smillert
64*5486feefSafresh1  is scalar($got = $more), scalar($exp = join "\n" =>
65b39c5158Smillert   "1: ",
66b39c5158Smillert   "2:\t# This is handy...",
67898184e3Ssthen   "=4:\t",
68898184e3Ssthen   "+3:=pod text",
69898184e3Ssthen   "~5:=cut more text",
70898184e3Ssthen   "6:\t",
71898184e3Ssthen   "=8: \t ",
72898184e3Ssthen   "+7:=pod",
73898184e3Ssthen   "=10: ",
74898184e3Ssthen   "~11:=cut",
75898184e3Ssthen   "12:use Test::Harness;",
76898184e3Ssthen   "13:runtests(sort glob 't/*.t');",
77898184e3Ssthen   "14:",
78b39c5158Smillert   "",
79b39c5158Smillert  );
80b39c5158Smillert  unless($got eq $exp) {
81b39c5158Smillert   print '# Got vs exp:\n# ', Pod::Simple::BlackBox::pretty($got),
82b39c5158Smillert    "\n# ",Pod::Simple::BlackBox::pretty($exp),"\n";
83b39c5158Smillert  }
84b39c5158Smillert}
85