Upgrade to podlators-2.0.3
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / text-options.t
1 #!/usr/bin/perl -w
2 # $Id: text-options.t,v 1.6 2006-01-28 22:31:50 eagle Exp $
3 #
4 # text-options.t -- Additional tests for Pod::Text options.
5 #
6 # Copyright 2002, 2004, 2006 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     open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n";
49     $parser->parse_from_file ('tmp.pod', \*OUT);
50     close OUT;
51     open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
52     my $output;
53     {
54         local $/;
55         $output = <TMP>;
56     }
57     close TMP;
58     unlink ('tmp.pod', 'out.tmp');
59     my $expected = '';
60     while (<DATA>) {
61         last if $_ eq "###\n";
62         $expected .= $_;
63     }
64     if ($output eq $expected) {
65         print "ok $n\n";
66     } else {
67         print "not ok $n\n";
68         print "Expected\n========\n$expected\nOutput\n======\n$output\n";
69     }
70     $n++;
71 }
72
73 # Below the marker are bits of POD and corresponding expected text output.
74 # This is used to test specific features or problems with Pod::Text.  The
75 # input and output are separated by lines containing only ###.
76
77 __DATA__
78
79 ###
80 alt 1
81 ###
82 =head1 SAMPLE
83
84 =over 4
85
86 =item F
87
88 Paragraph.
89
90 =item Bar
91
92 =item B
93
94 Paragraph.
95
96 =item Longer
97
98 Paragraph.
99
100 =back
101
102 ###
103
104 ==== SAMPLE ====
105
106 :   F   Paragraph.
107
108 :   Bar
109 :   B   Paragraph.
110
111 :   Longer
112         Paragraph.
113
114 ###
115
116 ###
117 margin 4
118 ###
119 =head1 SAMPLE
120
121 This is some body text that is long enough to be a paragraph that wraps,
122 thereby testing margins with wrapped paragraphs.
123
124  This is some verbatim text.
125
126 =over 6
127
128 =item Test
129
130 This is a test of an indented paragraph.
131
132 This is another indented paragraph.
133
134 =back
135 ###
136     SAMPLE
137         This is some body text that is long enough to be a paragraph that
138         wraps, thereby testing margins with wrapped paragraphs.
139
140          This is some verbatim text.
141
142         Test  This is a test of an indented paragraph.
143
144               This is another indented paragraph.
145
146 ###
147
148 ###
149 code 1
150 ###
151 This is some random text.
152 This is more random text.
153
154 This is some random text.
155 This is more random text.
156
157 =head1 SAMPLE
158
159 This is POD.
160
161 =cut
162
163 This is more random text.
164 ###
165 This is some random text.
166 This is more random text.
167
168 This is some random text.
169 This is more random text.
170
171 SAMPLE
172     This is POD.
173
174
175 This is more random text.
176 ###
177
178 ###
179 sentence 1
180 ###
181 =head1 EXAMPLE
182
183 Whitespace around C<<  this.  >> must be ignored per perlpodspec.  >>
184 needs to eat all of the space in front of it.
185
186 =cut
187 ###
188 EXAMPLE
189     Whitespace around "this." must be ignored per perlpodspec.  >> needs to
190     eat all of the space in front of it.
191
192 ###