\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}