Commit | Line | Data |
---|---|---|
ebb9462d | 1 | #!perl |
43c344fe JH |
2 | # Test that Pod::LaTeX works |
3 | # This test relies on the DATA filehandle | |
4 | # DATA contains the latex that is used for comparison | |
5 | # and the pod that was used to generate it. The two | |
6 | # are separated by '=pod' | |
7 | # Note that if the translator is adjusted the output tex | |
8 | # will probably not match what is currently there. You | |
9 | # will need to adjust it to match (assuming it is correct). | |
10 | ||
7e2c3868 | 11 | use Test; |
43c344fe JH |
12 | use strict; |
13 | ||
ebb9462d | 14 | BEGIN { plan tests => 177 } |
7e2c3868 | 15 | |
43c344fe JH |
16 | use Pod::LaTeX; |
17 | ||
7e2c3868 JH |
18 | # The link parsing changed between v0.22 and v0.30 of Pod::ParseUtils |
19 | use Pod::ParseUtils; | |
20 | my $linkver = $Pod::ParseUtils::VERSION; | |
21 | ||
43c344fe | 22 | # Set up an END block to remove the test output file |
7e2c3868 JH |
23 | END { |
24 | unlink "test.tex"; | |
25 | }; | |
43c344fe JH |
26 | |
27 | ok(1); | |
28 | ||
29 | # First thing to do is to read the expected output from | |
30 | # the DATA filehandle and store it in a scalar. | |
31 | # Do this until we read an =pod | |
32 | my @reference; | |
33 | while (my $line = <DATA>) { | |
34 | last if $line =~ /^=pod/; | |
35 | push(@reference,$line); | |
36 | } | |
37 | ||
38 | # Create a new parser | |
39 | my $parser = Pod::LaTeX->new; | |
40 | ok($parser); | |
41 | $parser->Head1Level(1); | |
42 | # Add the preamble but remember not to compare the timestamps | |
43 | $parser->AddPreamble(1); | |
44 | $parser->AddPostamble(1); | |
45 | ||
46 | # For a laugh add a table of contents | |
47 | $parser->TableOfContents(1); | |
48 | ||
49 | # Create an output file | |
50 | open(OUTFH, "> test.tex" ) or die "Unable to open test tex file: $!\n"; | |
51 | ||
52 | # Read from the DATA filehandle and write to a new output file | |
53 | # Really want to write this to a scalar | |
54 | $parser->parse_from_filehandle(\*DATA,\*OUTFH); | |
55 | ||
56 | close(OUTFH) or die "Error closing OUTFH test.tex: $!\n"; | |
57 | ||
58 | # Now read in OUTFH and compare | |
59 | open(INFH, "< test.tex") or die "Unable to read test tex file: $!\n"; | |
60 | my @output = <INFH>; | |
61 | ||
62 | ok(@output, @reference); | |
63 | for my $i (0..$#reference) { | |
64 | next if $reference[$i] =~ /^%%/; # skip timestamp comments | |
7e2c3868 JH |
65 | |
66 | # if we are running a new version of Pod::ParseUtils we need | |
67 | # to change the link text. This is a kluge until we drop support | |
68 | # for older versions of Pod::ParseUtils | |
69 | if ($linkver < 0.29 && $output[$i] =~ /manpage/) { | |
70 | # convert our expectations from new to old new format | |
71 | $reference[$i] =~ s/Standard link: \\emph\{Pod::LaTeX\}/Standard link: the \\emph\{Pod::LaTeX\} manpage/; | |
72 | $reference[$i] =~ s/\\textsf\{sec\} in \\emph\{Pod::LaTeX\}/the section on \\textsf\{sec\} in the \\emph\{Pod::LaTeX\} manpage/; | |
73 | } | |
43c344fe JH |
74 | ok($output[$i], $reference[$i]); |
75 | } | |
76 | ||
77 | close(INFH) or die "Error closing INFH test.tex: $!\n"; | |
78 | ||
79 | ||
80 | __DATA__ | |
81 | \documentclass{article} | |
7e2c3868 JH |
82 | \usepackage[T1]{fontenc} |
83 | \usepackage{textcomp} | |
43c344fe | 84 | |
7e2c3868 | 85 | %% Latex generated from POD in document (unknown) |
43c344fe | 86 | %% Using the perl module Pod::LaTeX |
7e2c3868 | 87 | %% Converted on Sat Apr 5 21:16:02 2003 |
43c344fe JH |
88 | |
89 | ||
90 | \usepackage{makeidx} | |
91 | \makeindex | |
92 | ||
93 | ||
94 | \begin{document} | |
95 | ||
96 | \tableofcontents | |
97 | ||
98 | \section{Introduction\label{Introduction}\index{Introduction}} | |
99 | \begin{itemize} | |
100 | ||
101 | \item | |
102 | ||
103 | Always check the return codes of system calls. Good error messages should | |
104 | go to STDERR, include which program caused the problem, what the failed | |
105 | system call and arguments were, and (\textbf{very important}) should contain | |
106 | the standard system error message for what went wrong. Here's a simple | |
107 | but sufficient example: | |
108 | ||
109 | \begin{verbatim} | |
110 | opendir(D, $dir) or die "can't opendir $dir: $!"; | |
111 | \end{verbatim} | |
112 | ||
113 | \item | |
114 | ||
115 | Line up your transliterations when it makes sense: | |
116 | ||
117 | \begin{verbatim} | |
118 | tr [abc] | |
119 | [xyz]; | |
120 | \end{verbatim} | |
121 | ||
122 | ||
123 | The above should be aligned since it includes an embedded tab. | |
124 | ||
125 | ||
126 | \item | |
127 | ||
128 | Think about reusability. Why waste brainpower on a one-shot when you | |
129 | might want to do something like it again? Consider generalizing your | |
130 | code. Consider writing a module or object class. Consider making your | |
131 | code run cleanly with \texttt{use strict} and \texttt{-w} (or \texttt{use warnings} in | |
132 | Perl 5.6) in effect. Consider giving away your code. Consider changing | |
133 | your whole world view. Consider... oh, never mind. | |
134 | ||
135 | ||
136 | \item | |
137 | ||
138 | Be consistent. | |
139 | ||
140 | ||
141 | \item | |
142 | ||
143 | Be nice. | |
144 | ||
145 | \end{itemize} | |
146 | \section{Links\label{Links}\index{Links}} | |
147 | ||
148 | ||
149 | This link should just include one word: \textsf{Pod::LaTeX} | |
150 | ||
151 | ||
152 | ||
153 | This link should include the text \texttt{test} even though | |
154 | it refers to \texttt{Pod::LaTeX}: \textsf{test}. | |
155 | ||
156 | ||
157 | ||
9c6ed6d7 | 158 | Standard link: \emph{Pod::LaTeX}. |
43c344fe JH |
159 | |
160 | ||
161 | ||
9c6ed6d7 | 162 | Now refer to an external section: \textsf{sec} in \emph{Pod::LaTeX} |
43c344fe JH |
163 | |
164 | \section{Lists\label{Lists}\index{Lists}} | |
165 | ||
166 | ||
167 | Test description list with long lines | |
168 | ||
169 | \begin{description} | |
170 | ||
ebb9462d | 171 | \item[{Some short text}] \mbox{} |
43c344fe JH |
172 | |
173 | Some additional para. | |
174 | ||
175 | \begin{itemize} | |
176 | ||
177 | \item | |
178 | ||
179 | Nested itemized list | |
180 | ||
181 | ||
182 | \item | |
183 | ||
184 | Second item | |
185 | ||
186 | \end{itemize} | |
187 | ||
ebb9462d | 188 | \item[{some longer text than that}] \mbox{} |
43c344fe JH |
189 | |
190 | and again. | |
191 | ||
192 | ||
ebb9462d | 193 | \item[{this text is even longer and greater than}] \textbf{40 characters} |
43c344fe JH |
194 | |
195 | Some more content for the item. | |
196 | ||
197 | ||
ebb9462d | 198 | \item[{this is some text with \textit{something across}}] \textbf{the 40 char boundary} |
43c344fe JH |
199 | |
200 | This is item content. | |
201 | ||
ebb9462d RGS |
202 | |
203 | \item[{square [ bracket in item}] \mbox{} | |
204 | ||
205 | Square bracket content | |
206 | ||
43c344fe | 207 | \end{description} |
7e2c3868 JH |
208 | |
209 | ||
210 | And this should be an enumerated list without any cruft after the numbers or additional numbers at all. | |
211 | ||
212 | \begin{enumerate} | |
213 | ||
214 | \item | |
215 | ||
216 | item 1 | |
217 | ||
218 | ||
219 | \item | |
220 | ||
221 | item 2 | |
222 | ||
223 | \end{enumerate} | |
43c344fe JH |
224 | \section{Escapes\label{Escapes}\index{Escapes}} |
225 | ||
226 | ||
227 | Test some normal escapes such as $<$ (lt) and $>$ (gt) and $|$ (verbar) and | |
228 | \texttt{\~{}} (tilde) and \& (amp) as well as $<$ (Esc lt) and $|$ (Esc | |
7e2c3868 | 229 | verbar) and \textfractionsolidus{} (Esc sol) and $>$ (Esc gt) and \& (Esc amp) |
43c344fe JH |
230 | and " (Esc quot) and even $\alpha$ (Esc alpha). |
231 | ||
232 | \section{For blocks\label{For_blocks}\index{For blocks}} | |
233 | Some latex code \textbf{here}. | |
234 | ||
235 | ||
236 | ||
237 | Some text that should appear. | |
238 | ||
239 | ||
240 | ||
241 | Some more text that should appear | |
242 | ||
243 | Some latex in a \textsf{begin block} | |
244 | ||
245 | and some more | |
246 | ||
247 | \begin{equation} | |
248 | a = \frac{3}{2} | |
249 | \end{equation} | |
250 | ||
251 | ||
252 | ||
253 | Back to pod. | |
254 | ||
255 | \printindex | |
256 | ||
257 | \end{document} | |
258 | =pod | |
259 | ||
260 | =head1 Introduction | |
261 | ||
262 | =over 4 | |
263 | ||
264 | =item * | |
265 | ||
266 | Always check the return codes of system calls. Good error messages should | |
267 | go to STDERR, include which program caused the problem, what the failed | |
268 | system call and arguments were, and (B<very important>) should contain | |
269 | the standard system error message for what went wrong. Here's a simple | |
270 | but sufficient example: | |
271 | ||
272 | opendir(D, $dir) or die "can't opendir $dir: $!"; | |
273 | ||
274 | =item * | |
275 | ||
276 | Line up your transliterations when it makes sense: | |
277 | ||
278 | tr [abc] | |
279 | [xyz]; | |
280 | ||
281 | The above should be aligned since it includes an embedded tab. | |
282 | ||
283 | =item * | |
284 | ||
285 | Think about reusability. Why waste brainpower on a one-shot when you | |
286 | might want to do something like it again? Consider generalizing your | |
287 | code. Consider writing a module or object class. Consider making your | |
288 | code run cleanly with C<use strict> and C<-w> (or C<use warnings> in | |
289 | Perl 5.6) in effect. Consider giving away your code. Consider changing | |
290 | your whole world view. Consider... oh, never mind. | |
291 | ||
292 | =item * | |
293 | ||
294 | Be consistent. | |
295 | ||
296 | =item * | |
297 | ||
298 | Be nice. | |
299 | ||
300 | =back | |
301 | ||
302 | =head1 Links | |
303 | ||
304 | This link should just include one word: L<Pod::LaTeX|Pod::LaTeX> | |
305 | ||
306 | This link should include the text C<test> even though | |
307 | it refers to C<Pod::LaTeX>: L<test|Pod::LaTeX>. | |
308 | ||
309 | Standard link: L<Pod::LaTeX>. | |
310 | ||
311 | Now refer to an external section: L<Pod::LaTeX/"sec"> | |
312 | ||
313 | ||
314 | =head1 Lists | |
315 | ||
316 | Test description list with long lines | |
317 | ||
318 | =over 4 | |
319 | ||
320 | =item Some short text | |
321 | ||
322 | Some additional para. | |
323 | ||
324 | =over 4 | |
325 | ||
326 | =item * | |
327 | ||
328 | Nested itemized list | |
329 | ||
330 | =item * | |
331 | ||
332 | Second item | |
333 | ||
334 | =back | |
335 | ||
336 | =item some longer text than that | |
337 | ||
338 | and again. | |
339 | ||
340 | =item this text is even longer and greater than 40 characters | |
341 | ||
342 | Some more content for the item. | |
343 | ||
344 | =item this is some text with I<something across> the 40 char boundary | |
345 | ||
346 | This is item content. | |
347 | ||
ebb9462d RGS |
348 | =item square [ bracket in item |
349 | ||
350 | Square bracket content | |
351 | ||
43c344fe JH |
352 | =back |
353 | ||
7e2c3868 JH |
354 | And this should be an enumerated list without any cruft after the numbers or additional numbers at all. |
355 | ||
356 | =over 4 | |
357 | ||
358 | =item 1) | |
359 | ||
360 | item 1 | |
361 | ||
362 | =item 2. | |
363 | ||
364 | item 2 | |
365 | ||
366 | =back | |
367 | ||
43c344fe JH |
368 | =head1 Escapes |
369 | ||
370 | Test some normal escapes such as < (lt) and > (gt) and | (verbar) and | |
371 | ~ (tilde) and & (amp) as well as E<lt> (Esc lt) and E<verbar> (Esc | |
372 | verbar) and E<sol> (Esc sol) and E<gt> (Esc gt) and E<amp> (Esc amp) | |
373 | and E<quot> (Esc quot) and even E<alpha> (Esc alpha). | |
374 | ||
375 | =head1 For blocks | |
376 | ||
377 | =for latex | |
378 | Some latex code \textbf{here}. | |
379 | ||
380 | Some text that should appear. | |
381 | ||
382 | =for comment | |
383 | Should not print anything | |
384 | ||
385 | Some more text that should appear | |
386 | ||
387 | =begin latex | |
388 | ||
389 | Some latex in a \textsf{begin block} | |
390 | ||
391 | and some more | |
392 | ||
393 | \begin{equation} | |
394 | a = \frac{3}{2} | |
395 | \end{equation} | |
396 | ||
397 | =end latex | |
398 | ||
399 | Back to pod. | |
400 | ||
401 | =cut |