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