blob: 08b9171d3ab8d2e878001f0ef3c6617dcf3169bf (
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
|
\documentclass{article}
\usepackage{lisp-on-tex}
\usepackage{qstest}
\IncludeTests{*}
\def\parserTestCallBack#1#2{\gdef\parsedResult{#1{#2}}}
\begin{document}
\LogTests{lgout}{*}{*}
\makeatletter
\begin{qstest}{Parser Test}{\@lispread}
\begin{qstest}{cons and list}{\@lispread,\@tlabel@cons}
% dot pair
\def\subtestDot#1#2{\Expect{#1}{\@tlabel@cons}\subtestDotValue#2\relax\relax}%
\def\subtestDotValue#1#2{%
\expandafter\Expect\expandafter{#1}{\@tlabel@int{0}}%
\expandafter\Expect\expandafter{#2}{\@tlabel@int{1}}}%
\setbox0=\hbox{\@lispread\parserTestCallBack(:0.:1)}%
\expandafter\subtestDot\parsedResult
\Expect*{\the\wd0}{0.0pt}%
% list
\def\subtestListI#1#2{\Expect{#1}{\@tlabel@cons}\subtestListValueI#2\relax\relax}%
\def\subtestListValueI#1#2{%
\expandafter\Expect\expandafter{#1}{\@tlabel@int{1}}%
\expandafter\subtestListII#2\relax\relax}%
\def\subtestListII#1#2{\Expect{#1}{\@tlabel@cons}\subtestListValueII#2\relax\relax}%
\def\subtestListValueII#1#2{%
\expandafter\Expect\expandafter{#1}{\@tlabel@int{2}}%
\expandafter\Expect\expandafter{#2}{\@tlabel@nil{}}}%
\setbox0=\hbox{\@lispread\parserTestCallBack(:1 :2)}%
\expandafter\subtestListI\parsedResult
\Expect*{\the\wd0}{0.0pt}%
% list with dot
\def\subtestListDotI#1#2{\Expect{#1}{\@tlabel@cons}\subtestListDotValueI#2\relax\relax}%
\def\subtestListDotValueI#1#2{%
\expandafter\Expect\expandafter{#1}{\@tlabel@int{1}}%
\expandafter\subtestListDotII#2\relax\relax}%
\def\subtestListDotII#1#2{\Expect{#1}{\@tlabel@cons}\subtestListDotValueII#2\relax\relax}%
\def\subtestListDotValueII#1#2{%
\expandafter\Expect\expandafter{#1}{\@tlabel@int{2}}%
\expandafter\Expect\expandafter{#2}{\@tlabel@int{3}}}%
\setbox0=\hbox{\@lispread\parserTestCallBack(:1 :2.:3)}%
\expandafter\subtestListDotI\parsedResult
\Expect*{\the\wd0}{0.0pt}%
\end{qstest}
\def\parserTest#1#2{%
\setbox0=\hbox{\@lispread\parserTestCallBack#1}%
\expandafter\Expect\expandafter{\parsedResult}{#2}%
\Expect*{\the\wd0}{0.0pt}%
}
\begin{qstest}{integer}{\@lispread,\@tlabel@int}
\parserTest{:42}{\@tlabel@int{42}}
\parserTest{:-42}{\@tlabel@int{-42}}
\end{qstest}
\begin{qstest}{string}{\@lispread,\@tlabel@string}
\parserTest{'This is a {{example}} of \TeX : $f^{2x}_s(y)$'}
{\@tlabel@string{This is a {{example}} of \TeX : $f^{2x}_s(y)$}}
\end{qstest}
\begin{qstest}{symbol}{\@lispread,\@tlabel@symbol}
\parserTest{\symbol}{\@tlabel@symbol{\symbol}}
\end{qstest}
\begin{qstest}{bool}{\@lispread,\@tlabel@bool}
\parserTest{/t}{\@tlabel@bool{t}}
\parserTest{/f}{\@tlabel@bool{f}}
\end{qstest}
\begin{qstest}{nil}{\@lispread,\@tlabel@nil}
\parserTest{()}{\@tlabel@nil{}}
\end{qstest}
\begin{qstest}{parser-module}{\@lispread}
\def\@mod@read@dummy#1#2{\gdef#1{\@tlabel@testdummy{#2}}}
\parserTest{+{dummy::testValue}}{\@tlabel@testdummy{testValue}}
\end{qstest}
\begin{qstest}{dimen}{\@lispread,\@tlabel@dimen}
\parserTest{!123.45pt}{\@tlabel@dimen{123.45pt}}
\end{qstest}
\begin{qstest}{skip}{\@lispread,\@tlabel@skip}
\parserTest{@123.45pt plus 1fil minus 0.5pt}
{\@tlabel@skip{123.45pt plus 1.0fil minus 0.5pt}}
\end{qstest}
\end{qstest}
\begin{qstest}{Evaluation}{\@lispeval}
\begin{qstest}{self-evaluating form}{\@lispeval}
\def\selfEvalTest#1{%
\def\selfEvalTarget{#1}%
\setbox0=\hbox{\lispeval\selfEvalTarget\selfEvalResult}%
\Expect*{\the\wd0}{0.0pt}%
\expandafter\expandafter\expandafter\Expect\expandafter\expandafter\expandafter{%
\expandafter\selfEvalTarget\expandafter}\expandafter{\selfEvalResult}}%
\selfEvalTest{\@tlabel@string{foo}}
\selfEvalTest{\@tlabel@int{42}}
\selfEvalTest{\@tlabel@bool{t}}
\selfEvalTest{\@tlabel@dimen{12.3pt}}
\selfEvalTest{\@tlabel@skip{12.3pt plus 1.0 fil minus 0.5pt}}
\selfEvalTest{\@tlabel@nil{}}
\selfEvalTest{\@tlabel@func{\dummy}}
\selfEvalTest{\@tlabel@closure{{\x:\@@unused}{\y{\@ylabel@int{1}}}\@tlabel@int{0}}}
\selfEvalTest{\@tlabel@macro{{\x:\@@unused}{}\@tlabel@int{0}}}
\selfEvalTest{\@tlabel@envfunc{\dummy}}
\selfEvalTest{\@tlabel@mutable{\dummy}}
\selfEvalTest{\@tlabel@exception{3}}
\selfEvalTest{\@tlabel@lambda{}}
\selfEvalTest{\@tlabel@define{}}
\selfEvalTest{\@tlabel@if{}}
\selfEvalTest{\@tlabel@defmacro{}}
\selfEvalTest{\@tlabel@begin{}}
\selfEvalTest{\@tlabel@mdefine{}}
\selfEvalTest{\@tlabel@setb{}}
\selfEvalTest{\@tlabel@@let{}}
\selfEvalTest{\@tlabel@@mlet{}}
\selfEvalTest{\@tlabel@macroexpand{}}
\selfEvalTest{\@tlabel@callocc{}}
\selfEvalTest{\@tlabel@exception{{-1}{\@tlabel@string{dummy}}}}
\selfEvalTest{\@tlabel@continuation{1}}
\end{qstest}
\begin{qstest}{symbol}{\@lispeval}
%global env
\def\selfEvalTarget{\@tlabel@symbol{\=}}%
\setbox0=\hbox{\lispeval\selfEvalTarget\selfEvalResult}%
\Expect*{\the\wd0}{0.0pt}%
\expandafter\Expect\expandafter{\selfEvalResult}{\@tlabel@func{\@lisp@equal}}%
% local env
\def\selfEvalTarget{\@tlabel@symbol{\dummy}}%
\setbox0=\hbox{\expandafter\@eval\selfEvalTarget{\dummy{\@tlabel@int{42}}}\selfEvalResult}%
\Expect*{\the\wd0}{0.0pt}%
\expandafter\Expect\expandafter{\selfEvalResult}{\@tlabel@int{42}}%
% mutable
\def\dummyMutable{\@tlabel@symbol{\dummy}}
\setbox0=\hbox{\expandafter\@eval\selfEvalTarget{\dummy{\@tlabel@mutable{\dummyMutable}}}\selfEvalResult}%
\Expect*{\the\wd0}{0.0pt}%
expandafter\Expect\expandafter{\selfEvalResult}{\@tlabel@symbol{\dummy}}%
\end{qstest}
\begin{qstest}{cons cell and embeded function call}{\@lispeval}
\@lispread\parserTestCallBack(\+ :1 :2)
\setbox0=\hbox{\lispeval\parsedResult\consEvalResult}%
\Expect*{\the\wd0}{0.0pt}%
\expandafter\Expect\expandafter{\consEvalResult}{\@tlabel@int{3}}%
\end{qstest}
\begin{qstest}{special forms}{\@lispeval}
\def\specialFormEval#1{%
\@lispread\parserTestCallBack#1%
\setbox0=\hbox{\lispeval\parsedResult\spEvalResult}%
\Expect*{\the\wd0}{0.0pt}}
%% defineM
\def\getmdefSymbol#1\mdefSymbol#2#3\undefinedSymbol{%
\def\postDefinedEnv{#1}%
\def\testMdef{#2}%
\def\preDefinedEnv{#3}}%
\def\checkMdefinedValue#1#2#3{%
\Expect{#1}{\@tlabel@mutable}%
\expandafter\Expect\expandafter{#2}{#3}%
}
\toks0\expandafter{\@globalenv}%
\specialFormEval{(\defineM \mdefSymbol :42)}% it is also used for setB, if, and begin
\expandafter\getmdefSymbol\@globalenv\undefinedSymbol
\expandafter\Expect\expandafter{\postDefinedEnv}{}%
\expandafter\Expect\expandafter{\preDefinedEnv}*{\the\toks0}%
\expandafter\checkMdefinedValue\testMdef{\@tlabel@int{42}}%
%% setB
\specialFormEval{(\setB \mdefSymbol 'hoge')}%
\expandafter\getmdefSymbol\@globalenv\undefinedSymbol
\expandafter\checkMdefinedValue\testMdef{\@tlabel@string{hoge}}%
%% if
\specialFormEval{(\lispif /t (\setB \mdefSymbol :1) (\setB \mdefSymbol :2))}%
\expandafter\getmdefSymbol\@globalenv\undefinedSymbol
\expandafter\checkMdefinedValue\testMdef{\@tlabel@int{1}}%
\specialFormEval{(\lispif /f (\setB \mdefSymbol :1) (\setB \mdefSymbol :2))}%
\expandafter\getmdefSymbol\@globalenv\undefinedSymbol
\expandafter\checkMdefinedValue\testMdef{\@tlabel@int{2}}%
%% begin
\specialFormEval{(\begin (\setB \mdefSymbol :1) 'hoge')}%
\expandafter\Expect\expandafter{\spEvalResult}{\@tlabel@string{hoge}}%
\expandafter\checkMdefinedValue\testMdef{\@tlabel@int{1}}%
%% lambda
\def\checkClosure#1#2#3#4#5{%
\Expect{#1}{\@tlabel@closure}%
\checkClosureValue#2{#3}{#4}{#5}}
\def\checkClosureValue#1#2#3#4#5#6#7{%
\Expect{#1}{#5}% bind
\Expect{#2}{#6}% env
\Expect{#3{#4}}{#7}% body
}
\specialFormEval{(\lambda (\x \y) :42)}%
\expandafter\checkClosure\spEvalResult{\x\y:\@@unused}{}{\@tlabel@int{42}}%
\specialFormEval{(\lambda (\x . \y) :42)}%
\expandafter\checkClosure\spEvalResult{\x:\y}{}{\@tlabel@int{42}}%
\specialFormEval{(\lambda \x :42)}%
\expandafter\checkClosure\spEvalResult{:\x}{}{\@tlabel@int{42}}%
%% @let
\specialFormEval{(\@let \z 'foo' (\lambda (\x . \y) :42))}%
\expandafter\checkClosure\spEvalResult{\x:\y}{\z{\@tlabel@string{foo}}}{\@tlabel@int{42}}%
%% @mlet
\def\checkClosureMutable#1#2#3#4#5{%
\Expect{#1}{\@tlabel@closure}%
\checkClosureValueMutable#2{#3}{#4}{#5}}
\def\checkClosureValueMutable#1#2#3#4#5#6#7{%
\Expect{#1}{#5}% bind
\Expect{#3{#4}}{#7}% body
\checkClosureEnvMutable#2#6}
\def\checkClosureEnvMutable#1#2#3#4{%
\Expect{#1}{#3} % bineded symbol
\checkClosureEnvMutableInner#2{#4}}
\def\checkClosureEnvMutableInner#1#2#3{%
\Expect{#1}{\@tlabel@mutable}%
\expandafter\Expect\expandafter{#2}{#3}}
\specialFormEval{(\@mlet \z 'foo' (\lambda (\x . \y) :42))}%
\expandafter\checkClosureMutable\spEvalResult{\x:\y}{\z{\@tlabel@string{foo}}}{\@tlabel@int{42}}%
%% quote
\specialFormEval{(\quote :42)}%
\expandafter\Expect\expandafter{\spEvalResult}{\@tlabel@int{42}}%
%% define
\toks0\expandafter{\@globalenv}%
\specialFormEval{(\define \x :42)}%
\edef\hopedGlobalenv{\noexpand\x{\noexpand\@tlabel@int{42}}\the\toks0}%
\expandafter\expandafter\expandafter\Expect\expandafter\expandafter\expandafter{\expandafter\@globalenv\expandafter}\expandafter{\hopedGlobalenv}%
\expandafter\Expect\expandafter{\spEvalResult}{\@tlabel@nil{}}%
%% defmacro
\toks0\expandafter{\@globalenv}%
\specialFormEval{(\defmacro \mac (\lambda (\c) \c))}% it is also used in macroexpand
\edef\hopedGlobalenv{\noexpand\mac{\noexpand\@tlabel@macro{{\noexpand\c:\noexpand\@@unused}{}\noexpand\@tlabel@symbol{\noexpand\c}}}\the\toks0}%
\expandafter\expandafter\expandafter\Expect\expandafter\expandafter\expandafter{\expandafter\@globalenv\expandafter}\expandafter{\hopedGlobalenv}%
\expandafter\Expect\expandafter{\spEvalResult}{\@tlabel@nil{}}%
%% macroexpand
\def\testMacroExpand#1#2{%
\Expect{#1}{\@tlabel@cons}%
\testMacroExpandi#2}
\def\testMacroExpandi#1#2{%
\expandafter\Expect\expandafter{#1}{\@tlabel@symbol{\quote}}%
\expandafter\testMacroExpandii#2}
\def\testMacroExpandii#1#2{%
\Expect{#1}{\@tlabel@cons}%
\testMacroExpandiii#2}
\def\testMacroExpandiii#1#2{%
\expandafter\Expect\expandafter{#1}{\@tlabel@int{1}}%
\expandafter\Expect\expandafter{#2}{\@tlabel@nil{}}}
\specialFormEval{(\macroexpand (\quote (\mac (\quote :1))))}%
\expandafter\testMacroExpand\spEvalResult
\end{qstest}
\begin{qstest}{one-shot continuation}{\@lispeval}
\def\occEval#1{%
\@lispread\parserTestCallBack#1%
\setbox0=\hbox{\lispeval\parsedResult\occEvalResult}%
\Expect*{\the\wd0}{0.0pt}}
\occEval{(\callOCC (\lambda (\c) :1))}
\expandafter\Expect\expandafter{\occEvalResult}{\@tlabel@int{1}}
\occEval{(\callOCC (\lambda (\c) \c))}
\expandafter\Expect\expandafter{\occEvalResult}{\@tlabel@continuation{1}}
\occEval{(\callOCC (\lambda (\c) (\c :42)))}
\expandafter\Expect\expandafter{\occEvalResult}{\@tlabel@int{42}}
\occEval{(\callOCC (\lambda (\c) (\callOCC (\lambda (\d) \d))))}
\expandafter\Expect\expandafter{\occEvalResult}{\@tlabel@continuation{2}}
\end{qstest}
\begin{qstest}{mutiple map}{\@lispeval}
\def\occEval#1{%
\@lispread\parserTestCallBack#1%
\setbox0=\hbox{\lispeval\parsedResult\occEvalResult}%
\Expect*{\the\wd0}{0.0pt}}
\occEval{(\map (\lambda (\k) (\+ \k :1)) (\map (\lambda (\k) (\* \k :2)) (\quote (:1 :2))))}
\end{qstest}
\end{qstest}
\LogClose{lgout}
\end{document}
|