Debian Codegraph @

texmf-dist/doc/latex/inlinedef/inlinetest.tex

raw
1 %%
2 %% This is file `inlinetest.tex',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% inlinedef.dtx (with options: `testsuite')
8 %%
9 %% Copyright 2008 Stephen D. Hicks <[email protected]>.
10 %%
11 %% This program may be distributed and/or modified under the
12 %% conditions of the LaTeX Project Public License, either version 1.3
13 %% of this license or (at your option) any later version.
14 %% The latest version of this license is in
15 %% http://www.latex-project.org/lppl.txt and
16 %% version 1.3 or later is part of all distributions of LaTeX
17 %% version 2005/12/01 or later.
18 %%
19 %% This work has the LPPL maintenance status `maintained'.
20 %%
21 %% The Current Maintainer of this work is Stephen D. Hicks
22 %%
23 %% This work consists of the files
24 %% README
25 %% inlinedef.dtx
26 %% inlinedef.ins
27 %% inlinedef.pdf
28 %% and the derived files
29 %% inlinedef.sty
30 %% inlinetest.tex
31 %%
32 %% Any modified versions of this file must be renamed
33 %% with new filenames distinct from those in this work.
34 %%
35 %% This generated file may be distributed as long as the
36 %% original source files, as listed above, are part of the
37 %% same distribution. (The sources need not necessarily be
38 %% in the same archive or directory.)
39 %%
40 \documentclass{minimal}
41 \usepackage{inlinedef}%
42 [2008/07/10 v1.0 Inlined expansions within definitions]
43 \makeatletter
44 \errorcontextlines=10
45 \def\WantError#1#2#3{%
46 \let\WE@packageerror\PackageError
47 \def\PackageError##1##2##3{%
48 \protected@edef\@goterror{##2}\protected@edef\@wanterror{#2}%
49 \edef\@goterror{\xa\detokenize\xa{\@goterror}}%
50 \edef\@wanterror{\xa\detokenize\xa{\@wanterror}}%
51 \protected@edef\@gotpackage{##1}\protected@edef\@wantpackage{#1}%
52 \edef\@gotpackage{\xa\detokenize\xa{\@gotpackage}}%
53 \edef\@wantpackage{\xa\detokenize\xa{\@wantpackage}}%
54 \global\let\PackageError\WE@packageerror
55 \@tempswafalse
56 \ifx\@gotpackage\@wantpackage\else\message{^^J(arg 1 differs)^^J}\@tempswatrue\fi
57 \ifx\@goterror\@wanterror\else\message{^^J(arg 2 differs)^^J}\@tempswatrue\fi
58 \ifx#3##3\else\message{^^J(arg 3 differs)^^J}\@tempswatrue\fi
59 \if@tempswa\PackageError{inlinedef (test)}{wrong error}\@eha\PackageError{##1}{##2}##3\fi
60 }%
61 }
62
63 \def\CheckError{%
64 \ifx\PackageError\WE@packageerror\else
65 \PackageError{inlinedef (test)}{expected error not thrown}\@eha\fi
66 \global\let\PackageError\WE@packageerror
67 }
68 \newcommand\CheckDefinition[1][]{\@CheckDefinition{#1}}
69 \def\@CheckDefinition#1#2#3#{\@checkdefn{#1}#2{#3}}
70 \def\@checkdefn#1#2#3#4{#1\def\@reserveda#3{#4}\ifx#2\@reserveda\else
71 \message{^^J^^J\meaning#2^^J(got)vs(wanted)^^J\meaning\@reserveda^^J^^J}
72 \PackageError{inlinedef (test)}{definition of \detokenize{#2}didn't match}\@eha\fi
73 }
74 \let\eha\@eha\let\ehd\@ehd
75 \makeatother
76 \catcode`\#=12
77 \def\pound{#}
78 \catcode`\#=6
79
80 \def\WantSuperNoMatch#1#2#3{%
81 \WantError{inlinedef}{Cannot use \protect\Super\space in
82 \protect#1\space because\MessageBreak
83 parameter lists don't match:\MessageBreak
84 `#3' (new) != `#2' (old)}\eha
85 }
86 \def\WantStarNoMatch#1#2#3{%
87 \WantError{inlinedef}{Cannot use \protect\Inline* auto-expansion in
88 \protect#1\MessageBreak because
89 parameter lists don't match:\MessageBreak
90 `#3' (new) != `#2' (old)}\eha
91 }
92 \def\WantNoMatchBang#1#2#3{%
93 \WantError{inlinedef}{Parameter lists for
94 \protect#1\space don't match:\MessageBreak
95 `#3' (new) != `#2' (old)\MessageBreak
96 Use !-form of \protect\Inline\space to ignore this}\eha
97 }
98 \def\WantOnlyDefGdef{%
99 \WantError{inlinedef}{Only \protect\def\space and \protect\gdef\space are
100 allowed after \protect\Inline,\MessageBreak but some other type of
101 definition was found}\eha
102 }
103 \def\WantNoDefGdef{%
104 \WantError{inlinedef}{No \protect\def\space or \protect\gdef\space found
105 after \protect\Inline}\ehd
106 }
107 \def\WantSuperNoRedef#1{%
108 \WantError{inlinedef}{Cannot use \protect\Super\space in \protect#1\space
109 because \MessageBreak it hasn't been defined yet}\eha
110 }
111 % I. Basic stuff
112 % A. Simple definition
113 \let\a\undefined
114 \Inline\def\a{b}
115 \CheckDefinition\a{b}
116
117 % B. Simple redefinition
118 \def\a{b}
119 \Inline\def\a{d}
120 \CheckDefinition\a{d}
121
122 % C. Erroneous redefinition (needs !)
123 \def\a{b}
124 \WantNoMatchBang\a{}{\pound1}
125 \Inline\def\a#1{c}
126 \CheckError
127 \CheckDefinition\a{b} % shouldn't have changed
128
129 \def\a{b}
130 \Inline!\def\a#1{c}
131 \CheckDefinition\a#1{c}
132
133 % D. Local/global definition
134 \def\a{b}
135 \begingroup
136 \Inline\def\a{c}
137 \endgroup
138 \CheckDefinition\a{b}
139
140 \begingroup
141 \Inline\gdef\a{c}
142 \endgroup
143 \CheckDefinition\a{c}
144
145 {\Inline\global\def\a{d}}
146 \CheckDefinition\a{d}
147
148 % E. Collecting arguments
149 \Inline\long\def\a{e}
150 \CheckDefinition[\long]\a{e}
151
152 \Inline\outer\def\a{f}
153 \edef\a{\meaning\a}
154 \edef\b{\detokenize{\outer macro:->f}}
155 \xa\CheckDefinition\xa\a\xa{\b}
156
157 \Inline\long\outer\def\a{g}
158 \edef\a{\meaning\a}
159 \edef\b{\string\long\string\outer\space\detokenize{macro:->g}}
160 \xa\CheckDefinition\xa\a\xa{\b}
161
162 \def\a{g}
163 \Inline!\long\def\a#1{h}
164 \CheckDefinition[\long]\a#1{h}
165
166 % II. Special tokens
167 % A. Recursion
168 \def\a{b}
169 \Inline\def\a{a\a c}
170 \CheckDefinition\a{a\a c}
171
172 % B. Expansion
173 \def\a{b}
174 \Inline\def\a{a\Expand\a c}
175 \CheckDefinition\a{abc}
176
177 \def\a{b}
178 \Inline\def\a{\Expand a\Expand\a\Expand c}
179 \CheckDefinition\a{abc}
180
181 \def\a{\b}
182 \def\b{c}
183 \Inline\def\a{a\Expand\a c}
184 \CheckDefinition\a{a\b c}
185
186 \toks0{b}\toks1{d}
187 \Inline\def\a{a\the\toks0c\the\toks1e}
188 \CheckDefinition\a{a\the\toks0c\the\toks1e}
189
190 \Inline\def\a{a\Expand{\the\toks0}c\Expand{\the\toks1}e}
191 \CheckDefinition\a{abcde}
192
193 \Inline\def\a{\Expand{a\the\toks0}c\Expand{\the\toks1}e}
194 \CheckDefinition\a{a\the\toks0cde}
195
196 \Inline\def\a{\Expand{\expandafter a\the\toks0}c\Expand{\the\toks1e}}
197 \CheckDefinition\a{abcde}
198
199 % C. MultiExpand
200 \def\x{\y}
201 \def\y{\z}
202 \def\z{0}
203 \Inline\def\a{a\MultiExpand0\x b}
204 \CheckDefinition\a{a\x b}
205
206 \Inline\def\a{a\MultiExpand1\x b}
207 \CheckDefinition\a{a\y b}
208
209 \Inline\def\a{a\MultiExpand2\x b}
210 \CheckDefinition\a{a\z b}
211
212 \Inline\def\a{a\MultiExpand3\x b}
213 \CheckDefinition\a{a0b}
214
215 \Inline\def\a{a\MultiExpand{10}\x b}
216 \CheckDefinition\a{a0b}
217
218 % i. use with \expandafter
219 \Inline\def\a{a\MultiExpand2{\expandafter\expandafter\x\x}b}
220 \CheckDefinition\a{a\y\y b}
221
222 \Inline\def\a{a\MultiExpand1{\expandafter\expandafter\x\x}b}
223 \CheckDefinition\a{a\expandafter\y\x b}
224
225 \Inline\def\a{a\MultiExpand2{\expandafter\expandafter\expandafter\x\x}b}
226 \CheckDefinition\a{a\x\z b}
227
228 \Inline\def\a{a\MultiExpand3{\expandafter\expandafter\expandafter\x\x}b}
229 \CheckDefinition\a{a\y\z b}
230
231 \Inline\def\a{a\MultiExpand4{\expandafter\expandafter\expandafter\x\x}b}
232 \CheckDefinition\a{a\z\z b}
233
234 \Inline\def\a{a\MultiExpand5{\expandafter\expandafter\expandafter\x\x}b}
235 \CheckDefinition\a{a0\z b}
236
237 % D. UnsafeExpand
238 \def\x{b\Super c}
239 \Inline\def\a{a\Expand\x d}
240 \CheckDefinition\a{ab\Super cd}
241
242 \def\a{0}
243 \Inline\def\a{a\UnsafeExpand\x d}
244 \CheckDefinition\a{ab0cd}
245
246 \def\a{b\Super d}
247 \Inline\def\a{a\UnsafeExpand\a e}
248 \CheckDefinition\a{abb\Super dde}
249
250 \def\a{b\Super d}
251 \Inline**\def\a{a\a e}
252 \CheckDefinition\a{abb\Super dde}
253
254 % Would be nice if we could catch TeX capacity exceeded errors...
255 % Then try \def\a{b\a d}\Inline**\def\a{a\a e}
256
257 \def\x#1{b#1d}
258 \Inline\def\a{a\x ce}
259 \CheckDefinition\a{a\x ce}
260
261 \Inline\def\a{a\UnsafeExpand\x ce}
262 \CheckDefinition\a{abcde}
263
264 % E. NoExpand
265 \Inline\def\a{a\NoExpand\Expand\x b}
266 \CheckDefinition\a{a\Expand\x b}
267
268 \Inline*\def\a{a\NoExpand\a b}
269 \CheckDefinition\a{a\a b}
270
271 \Inline**\def\a{a\NoExpand\a b}
272 \CheckDefinition\a{a\a b}
273
274 \Inline\def\a{a\NoExpand{\Expand\x\Expand\y}b}
275 \CheckDefinition\a{a\Expand\x\Expand\y b}
276
277 % F. Super
278 \def\a{bcd}
279 \Inline\def\a{a\Super e}
280 \CheckDefinition\a{abcde}
281
282 \def\a#1{b#1d}
283 \Inline\def\a#1{a\Super e}
284 \CheckDefinition\a#1{ab#1de}
285
286 \def\a#1{b#1d}
287 \Inline*\def\a#1{a\Super e}
288 \CheckDefinition\a#1{ab#1de}
289
290 \def\a#1{b#1d}
291 \Inline**\def\a#1{a\Super e}
292 \CheckDefinition\a#1{ab#1de}
293
294 % G. Recurse
295 \def\a{q}
296 \Inline\def\a{a\Recurse b}
297 \CheckDefinition\a{a\a b}
298
299 \Inline*\def\a{a\Recurse b}
300 \CheckDefinition\a{a\a b}
301
302 \Inline**\def\a{a\Recurse b}
303 \CheckDefinition\a{a\a b}
304
305 % III. Tricky parsing
306 % A. Spaces
307 \def\a{b c d}
308 \Inline\def\a{a \Super e}
309 \CheckDefinition\a{a b c de}
310
311 \def\a{b c d}
312 \Inline\def\a{a \Expand\a e}
313 \CheckDefinition\a{a b c de}
314
315 \def\a{b c d}
316 \Inline\def\a{a \Expand{\a} e}
317 \CheckDefinition\a{a b c d e}
318
319 \Inline\def\a{a\NoExpand{\Expand\x\Expand\y} b}
320 \xa\CheckDefinition\xa\a\xa{\xa a\xa\Expand\xa\x\xa\Expand\xa\y\space b}
321
322 % B. Grouping
323 \def\a{b{c d}e}
324 \Inline\def\a{{a\Super}f\Super}
325 \CheckDefinition\a{{ab{c d}e}fb{c d}e}
326
327 \Inline\def\a{{ }{}}
328 \Inline\def\a{{\Expand\a\a}{} {{\Super}{}}}
329 \CheckDefinition\a{{{ }{}\a}{} {{{ }{}}{}}}
330
331 % C. Parameters
332 \def\a#1bcd#2{[#1...#2]}
333 \Inline\def\a#1bcd#2{a\Super b}
334 \CheckDefinition\a#1bcd#2{a[#1...#2]b}
335
336 \def\a#1\##2{y}
337 \Inline\def\a#1\##2{x\UnsafeExpand\a{#1}\#{#2}z}
338 \CheckDefinition\a#1\##2{xyz}
339
340 \def\a#1\##2{#1y#2}
341 \Inline\def\a#1\##2{x\UnsafeExpand\a{#1}\#{#2}z}
342 \CheckDefinition\a#1\##2{x#1y#2z}
343
344 % i. spaces!
345 \def\a #1 {y}
346 \Inline\def\a#1 {x\Super z}
347 \CheckDefinition\a#1 {xyz}
348
349 \xa\def\xa\a\space{y}
350 \xa\Inline\xa\def\xa\a\space{x\Super z}
351 \xa\CheckDefinition\xa\a\space{xyz}
352
353 % ii. funky catcodes
354 %%%% This test fails.
355 %\begingroup
356 % \catcode`&=6
357 % \def\a&1{b#1d}
358 % \Inline\def\a#1{a\Super e}
359 % \CheckDefinition\a#1{b&1d}
360 %\endgroup
361
362 % D. Active characters
363 \begingroup
364 \catcode`A=13
365 \defA#1{b#1d}
366 \Inline\defA#1{aAe}
367 \CheckDefinitionA#1{aAe}
368
369 \defA#1{b#1d}
370 \Inline*\defA#1{aAe}
371 \CheckDefinitionA#1{ab#1de}
372 \endgroup
373
374 % IV. Auto-expansion
375
376 \def\a#1{y}
377 \Inline\def\a#1{x\a z}
378 \CheckDefinition\a#1{x\a z}
379
380 \def\a#1{y}
381 \Inline*\def\a#1{x\a z}
382 \CheckDefinition\a#1{xyz}
383
384 \def\a#1{y}
385 \Inline**\def\a#1{x\a{#1}z}
386 \CheckDefinition\a#1{xyz}
387
388 % A. With delimited arguments
389 \def\a[#1]#2{#1y#2}
390 \Inline*\def\a[#1]#2{x\a z}
391 \CheckDefinition\a[#1]#2{x#1y#2z}
392
393 \def\a[#1]#2{#1y#2}
394 \Inline**\def\a[#1]#2{x\a[#1]{#2}z}
395 \CheckDefinition\a[#1]#2{x#1y#2z}
396
397 % V. Errors
398
399 \def\bar#1{d #1 f}
400 \def\x{b}
401
402 \WantSuperNoMatch\a{\pound1}{.\pound1}
403 \def\a#1{x}
404 \Inline!\def\a.#1{y\Super}
405 \CheckError
406 \CheckDefinition\a#1{x}
407
408 \WantStarNoMatch\a{\pound1}{.\pound1}
409 \def\a#1{x}
410 \Inline*!\def\a.#1{y\a}
411 \CheckError
412 \CheckDefinition\a#1{x}
413
414 \def\a#1{x}
415 \Inline!\def\a.#1{y} % ok
416 \CheckDefinition\a.#1{y}
417
418 \WantOnlyDefGdef
419 \def\foo{a}
420 \Inline\edef\foo{b}
421 \CheckError
422 \CheckDefinition\foo{a}
423 \let\foo\undefined
424
425 \WantOnlyDefGdef
426 \Inline\global\outer\xdef{}
427 \CheckError
428
429 \WantOnlyDefGdef
430 \Inline\global\outer\abc\space vbcda s \newcommand{}
431 \CheckError
432
433 \WantNoDefGdef
434 \Inline\let\relax\relax
435 \CheckError
436
437 \WantNoDefGdef
438 \Inline{}
439 \CheckError
440
441 \WantSuperNoRedef\foo
442 \Inline\def\foo#1{a \Expand\x\space cd #1 fg \x\space i\Super}
443 \CheckError
444
445 \WantNoMatchBang\a{}{\pound1}
446 \def\a{b}
447 \Inline\def\a#1{a\a c}
448 \CheckError
449
450 % Miscellaneous (read: "old") tests
451
452 \def\test#1{d #1 f}
453 \Inline\def\test#1{a \Expand\x\space c\Super g \x\space i}
454 \CheckDefinition\test#1{a b\space cd #1 fg \x\space i}
455
456 \Inline*\def\bar#1{a \Expand\x\space c\bar g \x\space i}
457 \CheckDefinition\bar#1{a b\space cd #1 fg \x\space i}
458
459 \def\bar#1{d #1 f}
460 \Inline**\def\bar#1{a \Expand\x\space c\bar{#1}g \x\space i}
461 \CheckDefinition\bar#1{a b\space cd #1 fg \x\space i}
462
463 \Inline\def\foo#1{a \Expand\x\space cd #1 fg \x\space i}
464 \CheckDefinition\foo#1{a b\space cd #1 fg \x\space i}
465
466 \def\a{b}
467 \Inline!\def\a#1{a\Expand\a c}
468 \CheckDefinition\a#1{abc}
469
470 \def\a{b}
471 \Inline!**\def\a#1{a\a c}
472 \CheckDefinition\a#1{abc}
473
474 \Inline\def\a#1{a\a c}
475 \CheckDefinition\a#1{a\a c}
476
477 \Inline\def\a#1{a\Recurse c}
478 \CheckDefinition\a#1{a\a c}
479
480 \Inline!\def\a{a\NoExpand{b\Super c}d}
481 \CheckDefinition\a{ab\Super cd}
482
483 \Inline*\def\a{gh\a jk}
484 \CheckDefinition\a{ghab\Super cdjk}
485
486 % SURPRISE! unsafe expansion...
487 \def\a{ab\Super cd}
488 \Inline**\def\a{gh\a jk}
489 \CheckDefinition\a{ghabab\Super cdcdjk}
490
491 \def\a{ab\Super cd}
492 \Inline\def\a{gh\UnsafeExpand\a jk}
493 \CheckDefinition\a{ghabab\Super cdcdjk}
494
495 \def\x{\x a} % This is a fun one...!
496 \Inline\def\a{\MultiExpand{5}\x}
497 \CheckDefinition\a{\x aaaaa}
498
499 \message{^^JAll tests completed.^^J}
500
501 \begin{document}
502 \end{document}
503
504
505 \endinput
506 %%
507 %% End of file `inlinetest.tex'.