| 1 |
\documentclass{article} |
| 2 |
|
| 3 |
\usepackage[a4paper,margin=1in]{geometry} |
| 4 |
\usepackage{jvlisting} |
| 5 |
\usepackage{multicol} |
| 6 |
|
| 7 |
\newcommand{\testbreak}{\vskip0pt plus 10cm\penalty-100\vskip0pt plus-10cm |
| 8 |
\bigskip} |
| 9 |
\newenvironment{test}[1]{\testbreak\begingroup\textbf{Test~#1}}% |
| 10 |
{\par\endgroup} |
| 11 |
\newenvironment{testpages}[1]{\parskip0pt |
| 12 |
\vskip2pt\hrule\begin{minipage}[c][#1\baselineskip]{1\linewidth}% |
| 13 |
\begin{multicols}{2}\parskip1ex}% |
| 14 |
{\end{multicols}\end{minipage}\vskip3pt\hrule} |
| 15 |
\parindent0pt |
| 16 |
\parskip1ex |
| 17 |
|
| 18 |
\newwrite\outfile |
| 19 |
|
| 20 |
\begin{document} |
| 21 |
|
| 22 |
\begin{center} |
| 23 |
\bf Test Cases for the jvlisting Package |
| 24 |
\end{center} |
| 25 |
|
| 26 |
|
| 27 |
This document contains test cases to exercise different features of |
| 28 |
the \verb|jvlisting| \LaTeX\ package. |
| 29 |
|
| 30 |
|
| 31 |
\begin{test}{1.1} (printing of special characters). |
| 32 |
The following two lines should be the same |
| 33 |
\setlength{\listingindent}{0pt} |
| 34 |
\setlength{\listingskipamount}{0pt} |
| 35 |
\begin{listing} |
| 36 |
start %\{}~``''$ end |
| 37 |
\end{listing} |
| 38 |
\verb|start %\{}~``''$ end| |
| 39 |
\end{test} |
| 40 |
|
| 41 |
|
| 42 |
\begin{test}{1.2} (ligatures). |
| 43 |
The following two lines should be the same |
| 44 |
\setlength{\listingindent}{0pt} |
| 45 |
\setlength{\listingskipamount}{0pt} |
| 46 |
\begin{listing} |
| 47 |
start ?` !` end |
| 48 |
\end{listing} |
| 49 |
\verb|start ?` !` end| |
| 50 |
\end{test} |
| 51 |
|
| 52 |
|
| 53 |
\begin{test}{2.1} (indentation). |
| 54 |
The following five lines should align horizontally. |
| 55 |
\setlength{\listingskipamount}{0pt} |
| 56 |
\begin{listing} |
| 57 |
|line1| |
| 58 |
\end{listing} |
| 59 |
\begin{listing} |
| 60 |
|line2| |
| 61 |
\end{listing} |
| 62 |
\begin{listing} |line3| |
| 63 |
|line4| |
| 64 |
|line5|\end{listing} |
| 65 |
\end{test} |
| 66 |
|
| 67 |
|
| 68 |
\begin{test}{2.2} (decreasing indentation level). |
| 69 |
The left end of the following lines should align horizontally. |
| 70 |
\begin{listing} |line0 |
| 71 |
|line1 |
| 72 |
|line2 |
| 73 |
|line3 |
| 74 |
\end{listing} |
| 75 |
\end{test} |
| 76 |
|
| 77 |
|
| 78 |
\begin{test}{2.3} (increasing indentation level). |
| 79 |
The right end of the following lines should align horizontally. |
| 80 |
\begin{listing} |
| 81 |
xxline1| |
| 82 |
xline2| |
| 83 |
line3| |
| 84 |
\end{listing} |
| 85 |
\end{test} |
| 86 |
|
| 87 |
|
| 88 |
\begin{test}{2.4} (\verb|\listingindent|). |
| 89 |
The following two lines should align horizontally. |
| 90 |
\setlength{\listingskipamount}{0pt} |
| 91 |
|
| 92 |
\hskip3cm\texttt{|line1|} |
| 93 |
|
| 94 |
\setlength{\listingindent}{3cm} |
| 95 |
\begin{listing} |
| 96 |
|line2| |
| 97 |
\end{listing} |
| 98 |
\end{test} |
| 99 |
|
| 100 |
|
| 101 |
\begin{test}{3.1} (\verb|\listingskipamount|, part~1). |
| 102 |
The lines of the listing should vertically align with the lines to the |
| 103 |
right. |
| 104 |
|
| 105 |
\setlength{\listingskipamount}{0pt} |
| 106 |
\begin{minipage}{.4\linewidth} |
| 107 |
line1 line1 line1 line1 line1 |
| 108 |
\begin{listing} |
| 109 |
line2 line2 line2 line2 line2 |
| 110 |
line3 line3 line3 line3 line3 |
| 111 |
\end{listing} |
| 112 |
line4 line4 line4 line4 line4 |
| 113 |
\end{minipage}% |
| 114 |
\begin{minipage}{.6\linewidth} |
| 115 |
line1 \\ |
| 116 |
line2 \\ |
| 117 |
line3 \\ |
| 118 |
line4 |
| 119 |
\end{minipage} |
| 120 |
\end{test} |
| 121 |
|
| 122 |
|
| 123 |
\begin{test}{3.2} (\verb|\listingskipamount|, part~2). |
| 124 |
The lines of the listing should vertically align with the lines to the |
| 125 |
right. |
| 126 |
|
| 127 |
\begin{minipage}{.4\linewidth} |
| 128 |
line1 line1 line1 line1 line1 |
| 129 |
\setlength{\listingskipamount}{1\baselineskip} |
| 130 |
\begin{listing} |
| 131 |
line3 line3 line3 line3 line3 |
| 132 |
\end{listing} |
| 133 |
line5 line5 line5 line5 line5 |
| 134 |
\end{minipage}% |
| 135 |
\begin{minipage}{.6\linewidth} |
| 136 |
line1 \\ |
| 137 |
line2 \\ |
| 138 |
line3 \\ |
| 139 |
line4 \\ |
| 140 |
line5 |
| 141 |
\end{minipage} |
| 142 |
\end{test} |
| 143 |
|
| 144 |
|
| 145 |
\begin{test}{3.3} (no extra parskip before/after listings). |
| 146 |
The lines of the listing should vertically align with the lines to the |
| 147 |
right. |
| 148 |
|
| 149 |
\begin{minipage}{.4\linewidth}\parskip12pt |
| 150 |
\setlength{\listingskipamount}{0pt} |
| 151 |
line1 line1 line1 line1 line1 |
| 152 |
\begin{listing} |
| 153 |
line2 line2 line2 line2 line2 |
| 154 |
line3 line3 line3 line3 line3 |
| 155 |
line4 line4 line4 line4 line4 |
| 156 |
\end{listing} |
| 157 |
line5 line5 line5 line5 line5 |
| 158 |
|
| 159 |
line7 |
| 160 |
\end{minipage}% |
| 161 |
\begin{minipage}{.6\linewidth}\parskip1\baselineskip |
| 162 |
line1 |
| 163 |
|
| 164 |
line3 |
| 165 |
|
| 166 |
line5 |
| 167 |
|
| 168 |
line7 |
| 169 |
\end{minipage} |
| 170 |
\end{test} |
| 171 |
|
| 172 |
|
| 173 |
\begin{test}{4.1} (page breaks). |
| 174 |
The columns should be of equal height (four rows each). |
| 175 |
\setlength{\listingskipamount}{0pt}% |
| 176 |
\begin{testpages}{6} |
| 177 |
Some text \dots \\ |
| 178 |
\dots\ before the listing. |
| 179 |
\begin{listing} |
| 180 |
line1 |
| 181 |
line2 |
| 182 |
line3 |
| 183 |
line4 |
| 184 |
line5 |
| 185 |
line6 |
| 186 |
\end{listing} |
| 187 |
\end{testpages} |
| 188 |
\end{test} |
| 189 |
|
| 190 |
|
| 191 |
\begin{test}{4.2} (page breaks, \verb|\listingpenalty|). |
| 192 |
The column break should be immediately before \verb|line1|. |
| 193 |
\setlength{\listingskipamount}{0pt}% |
| 194 |
\listingpenalty=10000 |
| 195 |
\begin{testpages}{6} |
| 196 |
Some text \dots \\ |
| 197 |
\dots\ before the listing. |
| 198 |
\begin{listing} |
| 199 |
line1 |
| 200 |
line2 |
| 201 |
line3 |
| 202 |
line4 |
| 203 |
line5 |
| 204 |
line6 |
| 205 |
\end{listing} |
| 206 |
\end{testpages} |
| 207 |
\end{test} |
| 208 |
|
| 209 |
|
| 210 |
\begin{test}{4.3} (page breaks, \verb|\prelistingpenalty|). |
| 211 |
The column break should {\em not} be immediately before \verb|line1|. |
| 212 |
\setlength{\listingskipamount}{0pt}% |
| 213 |
\prelistingpenalty=10000 |
| 214 |
\begin{testpages}{3} |
| 215 |
Some text \dots \\ |
| 216 |
\dots\ before \dots \\ |
| 217 |
\dots the listing. |
| 218 |
\begin{listing} |
| 219 |
line1 |
| 220 |
line2 |
| 221 |
\end{listing} |
| 222 |
\end{testpages} |
| 223 |
\end{test} |
| 224 |
|
| 225 |
|
| 226 |
\begin{test}{4.4} (page breaks, \verb|\postlistingpenalty|). |
| 227 |
The column break should {\em not} be immediately after \verb|line3|. |
| 228 |
\setlength{\listingskipamount}{0pt}% |
| 229 |
\postlistingpenalty=10000 |
| 230 |
\begin{testpages}{3} |
| 231 |
\begin{listing} |
| 232 |
line1 |
| 233 |
line2 |
| 234 |
line3 |
| 235 |
\end{listing} |
| 236 |
Some text \dots \\ |
| 237 |
\dots\ after the listing. |
| 238 |
\end{testpages} |
| 239 |
\end{test} |
| 240 |
|
| 241 |
|
| 242 |
\begin{test}{5} (\verb|\filelisting|) |
| 243 |
The following two listings should look the same. |
| 244 |
\immediate\openout\outfile=tmp.txt |
| 245 |
\immediate\write\outfile{line1} |
| 246 |
\immediate\write\outfile{line2} |
| 247 |
\immediate\write\outfile{line3} |
| 248 |
\immediate\closeout\outfile |
| 249 |
|
| 250 |
\begin{minipage}{.5\linewidth} |
| 251 |
\begin{listing} |
| 252 |
line1 |
| 253 |
line2 |
| 254 |
line3 |
| 255 |
\end{listing} |
| 256 |
\end{minipage}% |
| 257 |
\begin{minipage}{.5\linewidth} |
| 258 |
\filelisting{tmp.txt} |
| 259 |
\end{minipage} |
| 260 |
\end{test} |
| 261 |
|
| 262 |
|
| 263 |
\begin{test}{6.1} (\verb|\listingstarthook|, prepending a character) |
| 264 |
The following two lines should be the same. |
| 265 |
\setlength{\listingskipamount}{0pt}% |
| 266 |
\begin{listing} |
| 267 |
xtest |
| 268 |
\end{listing} |
| 269 |
\def\listingstarthook#1{#1x\ignorespaces}% |
| 270 |
\begin{listing} |
| 271 |
test |
| 272 |
\end{listing} |
| 273 |
\end{test} |
| 274 |
|
| 275 |
\begin{test}{6.2} (\verb|\listingstarthook|, prepending a line) |
| 276 |
The following listing should have two lines. |
| 277 |
\setlength{\listingskipamount}{0pt}% |
| 278 |
{\obeylines |
| 279 |
\gdef\listingstarthook#1{#1{ }{ }{ }{ }line1 |
| 280 |
}}% |
| 281 |
\begin{listing} |
| 282 |
line2 |
| 283 |
\end{listing} |
| 284 |
\global\let\listingstarthook=\undefined |
| 285 |
\end{test} |
| 286 |
|
| 287 |
\begin{test}{6.3} (\verb|\listingstarthook|, removing the first line) |
| 288 |
The following listing should have two lines. |
| 289 |
\setlength{\listingskipamount}{0pt}% |
| 290 |
{\obeylines |
| 291 |
\gdef\listingstarthook#1#2 |
| 292 |
{#1}}% |
| 293 |
\begin{listing} |
| 294 |
this should not be shown |
| 295 |
line1 |
| 296 |
line2 |
| 297 |
\end{listing} |
| 298 |
\global\let\listingstarthook=\undefined |
| 299 |
\end{test} |
| 300 |
|
| 301 |
\begin{test}{6.4} (\verb|\listingstarthook|, conditionally removing the first line) |
| 302 |
The following listing should have two lines. |
| 303 |
\setlength{\listingskipamount}{0pt}% |
| 304 |
{\catcode`\#=12\gdef\hash{#}} |
| 305 |
{\obeylines |
| 306 |
\gdef\skiptoeol#1#2 |
| 307 |
{\noindent\hbox to0pt{\hss (a line was removed)\hskip-\textwidth}#1}} |
| 308 |
\def\x#1#2#3{\if#3 \def\next{\x{#1}{#2#3}}\else |
| 309 |
\expandafter\ifx\hash#3\def\next{\skiptoeol{#1}}\else |
| 310 |
\def\next{#1#2#3}\fi\fi\next} |
| 311 |
\def\listingstarthook#1{\x{#1}{}} |
| 312 |
\begin{listing} |
| 313 |
#line0 |
| 314 |
line1 |
| 315 |
line2 |
| 316 |
\end{listing} |
| 317 |
The following listing should have three lines. |
| 318 |
\begin{listing} |
| 319 |
line0 |
| 320 |
line1 |
| 321 |
line2 |
| 322 |
\end{listing} |
| 323 |
\end{test} |
| 324 |
|
| 325 |
\newcommand{\writetofile}[1]{\immediate\write\outfile{#1}} |
| 326 |
\NewListingEnvironment{filetestlisting}{0}{}% |
| 327 |
{\immediate\openout\outfile=tmp.txt}{\writetofile}% |
| 328 |
{\immediate\closeout\outfile} |
| 329 |
|
| 330 |
\begin{test}{7.1} (writing listings to file) |
| 331 |
The following two lines should be the same. |
| 332 |
\setlength{\listingskipamount}{0pt}% |
| 333 |
\begin{listing} |
| 334 |
a line with ``quotes'', \slashes and potential ligatures: ` ?` !` ' |
| 335 |
\end{listing} |
| 336 |
\begin{filetestlisting} |
| 337 |
a line with ``quotes'', \slashes and potential ligatures: ` ?` !` ' |
| 338 |
\end{filetestlisting} |
| 339 |
\filelisting{tmp.txt} |
| 340 |
\end{test} |
| 341 |
|
| 342 |
\newcommand{\copytypeset}[1]{\ListingTypesetLine{#1}% |
| 343 |
{\DisableLigatureFix\immediate\write\outfile{#1}}} |
| 344 |
\NewListingEnvironment{copylisting}{0}{\prelistingskip}% |
| 345 |
{\immediate\openout\outfile=tmp.txt\listingfont}{\copytypeset}% |
| 346 |
{\immediate\closeout\outfile\postlistingskip} |
| 347 |
|
| 348 |
\begin{test}{7.2} (simultaneously typesetting and writing to a file) |
| 349 |
The following four lines should be the same. |
| 350 |
\setlength{\listingskipamount}{0pt}% |
| 351 |
\begin{copylisting} |
| 352 |
a line with ``quotes'', \slashes and potential ligatures: ` ?` !` ' |
| 353 |
a line with ``quotes'', \slashes and potential ligatures: ` ?` !` ' |
| 354 |
\end{copylisting} |
| 355 |
\filelisting{tmp.txt} |
| 356 |
\end{test} |
| 357 |
|
| 358 |
\end{document} |