Upgrade to podlators-2.0.2
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / text-options.t
1 #!/usr/bin/perl -w
2 # $Id: text-options.t,v 1.5 2006-01-20 21:20:58 eagle Exp $
3 #
4 # text-options.t -- Additional tests for Pod::Text options.
5 #
6 # Copyright 2002, 2004 by Russ Allbery <rra@stanford.edu>
7 #
8 # This program is free software; you may redistribute it and/or modify it
9 # under the same terms as Perl itself.
10
11 BEGIN {
12     chdir 't' if -d 't';
13     if ($ENV{PERL_CORE}) {
14         @INC = '../lib';
15     } else {
16         unshift (@INC, '../blib/lib');
17     }
18     unshift (@INC, '../blib/lib');
19     $| = 1;
20     print "1..5\n";
21 }
22
23 END {
24     print "not ok 1\n" unless $loaded;
25 }
26
27 use Pod::Text;
28
29 $loaded = 1;
30 print "ok 1\n";
31
32 my $n = 2;
33 while (<DATA>) {
34     my %options;
35     next until $_ eq "###\n";
36     while (<DATA>) {
37         last if $_ eq "###\n";
38         my ($option, $value) = split;
39         $options{$option} = $value;
40     }
41     open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n";
42     while (<DATA>) {
43         last if $_ eq "###\n";
44         print TMP $_;
45     }
46     close TMP;
47     my $parser = Pod::Text->new (%options) or die "Cannot create parser\n";
48     $parser->parse_from_file ('tmp.pod', 'out.tmp');
49     open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
50     my $output;
51     {
52         local $/;
53         $output = <TMP>;
54     }
55     close TMP;
56     unlink ('tmp.pod', 'out.tmp');
57     my $expected = '';
58     while (<DATA>) {
59         last if $_ eq "###\n";
60         $expected .= $_;
61     }
62     if ($output eq $expected) {
63         print "ok $n\n";
64     } else {
65         print "not ok $n\n";
66         print "Expected\n========\n$expected\nOutput\n======\n$output\n";
67     }
68     $n++;
69 }
70
71 # Below the marker are bits of POD and corresponding expected text output.
72 # This is used to test specific features or problems with Pod::Text.  The
73 # input and output are separated by lines containing only ###.
74
75 __DATA__
76
77 ###
78 alt 1
79 ###
80 =head1 SAMPLE
81
82 =over 4
83
84 =item F
85
86 Paragraph.
87
88 =item Bar
89
90 =item B
91
92 Paragraph.
93
94 =item Longer
95
96 Paragraph.
97
98 =back
99
100 ###
101
102 ==== SAMPLE ====
103
104 :   F   Paragraph.
105
106 :   Bar
107 :   B   Paragraph.
108
109 :   Longer
110         Paragraph.
111
112 ###
113
114 ###
115 margin 4
116 ###
117 =head1 SAMPLE
118
119 This is some body text that is long enough to be a paragraph that wraps,
120 thereby testing margins with wrapped paragraphs.
121
122  This is some verbatim text.
123
124 =over 6
125
126 =item Test
127
128 This is a test of an indented paragraph.
129
130 This is another indented paragraph.
131
132 =back
133 ###
134     SAMPLE
135         This is some body text that is long enough to be a paragraph that
136         wraps, thereby testing margins with wrapped paragraphs.
137
138          This is some verbatim text.
139
140         Test  This is a test of an indented paragraph.
141
142               This is another indented paragraph.
143
144 ###
145
146 ###
147 code 1
148 ###
149 This is some random text.
150 This is more random text.
151
152 This is some random text.
153 This is more random text.
154
155 =head1 SAMPLE
156
157 This is POD.
158
159 =cut
160
161 This is more random text.
162 ###
163 This is some random text.
164 This is more random text.
165
166 This is some random text.
167 This is more random text.
168
169 SAMPLE
170     This is POD.
171
172
173 This is more random text.
174 ###
175
176 ###
177 sentence 1
178 ###
179 =head1 EXAMPLE
180
181 Whitespace around C<<  this.  >> must be ignored per perlpodspec.  >>
182 needs to eat all of the space in front of it.
183
184 =cut
185 ###
186 EXAMPLE
187     Whitespace around "this." must be ignored per perlpodspec.  >> needs to
188     eat all of the space in front of it.
189
190 ###