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