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