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