From 3f9de09eb2fdc29b8fca10f7a9bf29aff883965f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 5 Nov 2010 18:36:53 +0100 Subject: Enlarge mcb test file --- Makefile | 17 +++--- TODO | 9 ++- luatexbase-mcb.dtx | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 180 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 5753dfc..439ea20 100644 --- a/Makefile +++ b/Makefile @@ -7,20 +7,21 @@ DTXSTY = lltxb-dtxstyle.tex # Files grouped by generation mode UNPACKED_MCB = luatexbase-mcb.sty mcb.lua \ - test-mcb-latex.tex test-mcb-plain.tex test-mcb.lua + test-mcb-latex.tex test-mcb-plain.tex \ + test-mcb.lua test-mcb-aux.tex UNPACKED_REGS = luatexbase-regs.sty \ - test-regs-plain.tex test-regs-latex.tex + test-regs-plain.tex test-regs-latex.tex UNPACKED_ATTR = luatexbase-attr.sty attr.lua \ - test-attr-plain.tex test-attr-latex.tex + test-attr-plain.tex test-attr-latex.tex UNPACKED_CCTB = luatexbase-cctb.sty cctb.lua \ - test-cctb-plain.tex test-cctb-latex.tex + test-cctb-plain.tex test-cctb-latex.tex UNPACKED_LOADER = luatexbase-loader.sty luatexbase.loader.lua \ - test-loader-plain.tex test-loader-latex.tex \ - $(TEST_LOADER).lua test-loader.sub.lua + test-loader-plain.tex test-loader-latex.tex \ + $(TEST_LOADER).lua test-loader.sub.lua UNPACKED_MODUTILS = luatexbase-modutils.sty modutils.lua test-modutils.lua \ - test-modutils-plain.tex test-modutils-latex.tex + test-modutils-plain.tex test-modutils-latex.tex UNPACKED_COMPAT = luatexbase-compat.sty \ - test-compat-plain.tex test-compat-latex.tex + test-compat-plain.tex test-compat-latex.tex UNPACKED_BASE = luatexbase.sty test-base-plain.tex test-base-latex.tex UNPACKED = $(UNPACKED_MCB) $(UNPACKED_REGS) $(UNPACKED_ATTR) $(UNPACKED_CCTB) \ $(UNPACKED_LOADER) $(UNPACKED_MODUTILS) $(UNPACKED_COMPAT) \ diff --git a/TODO b/TODO index c6d32cd..768a3a0 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,9 @@ +all +--- + +- regression checks on the results of the tests (sed+diff the log) +- add debug messages (to be used in the test suite)? + modutils -------- @@ -11,7 +17,8 @@ declaration and no declaration? mcb --- -- test: make each handler run at least once - doc: make an "example" section - doc: add a word about compatibility - code: verify that the return value of callback.register is checked +- code: fix listhandler logic again +- check type of all callbacks (& list) diff --git a/luatexbase-mcb.dtx b/luatexbase-mcb.dtx index 58099d7..39551eb 100644 --- a/luatexbase-mcb.dtx +++ b/luatexbase-mcb.dtx @@ -53,6 +53,7 @@ See source file '\inFileName' for details. \usedir{doc/luatex/luatexbase}% \file{test-mcb-plain.tex}{\from{luatexbase-mcb.dtx}{testplain}}% \file{test-mcb-latex.tex}{\from{luatexbase-mcb.dtx}{testlatex}}% + \file{test-mcb-aux.tex}{\from{luatexbase-mcb.dtx}{testaux}}% } \def\MetaPrefix{-- } @@ -434,7 +435,7 @@ local callbacktypes = callbacktypes or { stop_run = simple, hyphenate = simple, ligaturing = simple, - kerning = data, + kerning = data, -- FIXME find_write_file = first, find_read_file = first, find_vf_file = data, @@ -876,6 +877,107 @@ luatexbase.reset_callback("fooback") luatexbase.call_callback("fooback", "default") % \end{macrocode} % +% Now, we want to make each handler run at least once. So, define dummy +% functions and register them in various callbacks. We will make sure the +% callbacks are executed on the \tex end. Also, we want to check that +% everything works when we unload the functions either one by one, or using +% reset. +% +% A |list| callback. +% +% \begin{macrocode} +function add_hpack_filter() + luatexbase.add_to_callback('hpack_filter', function(head, ...) + texio.write_nl("I'm a dummy hpack_filter") + return head + end, + 'dummy hpack filter') + luatexbase.add_to_callback('hpack_filter', function(head, ...) + texio.write_nl("I'm an optimized dummy hpack_filter") + return true + end, + 'optimized dummy hpack filter') +end +function rm_one_hpack_filter() + luatexbase.remove_from_callback('hpack_filter', 'dummy hpack filter') +end +function rm_two_hpack_filter() + luatexbase.remove_from_callback('hpack_filter', + 'optimized dummy hpack filter') +end +% \end{macrocode} +% +% A |simple| callback. +% +% \begin{macrocode} +function add_hyphenate() + luatexbase.add_to_callback('hyphenate', function(head, tail) + texio.write_nl("I'm a dummy hyphenate") + end, + 'dummy hyphenate') + luatexbase.add_to_callback('hyphenate', function(head, tail) + texio.write_nl("I'm an other dummy hyphenate") + end, + 'other dummy hyphenate') +end +function rm_one_hyphenate() + luatexbase.remove_from_callback('hyphenate', 'dummy hyphenate') +end +function rm_two_hyphenate() + luatexbase.remove_from_callback('hyphenate', 'other dummy hyphenate') +end +% \end{macrocode} +% +% A |first| callback. +% +% \begin{macrocode} +function add_find_write_file() + luatexbase.add_to_callback('find_write_file', function(id, name) + texio.write_nl("I'm a dummy find_write_file") + return "dummy-"..name + end, + 'dummy find_write_file') + luatexbase.add_to_callback('find_write_file', function(id, name) + texio.write_nl("I'm an other dummy find_write_file") + return "dummy-other-"..name + end, + 'other dummy find_write_file') +end +function rm_one_find_write_file() + luatexbase.remove_from_callback('find_write_file', + 'dummy find_write_file') +end +function rm_two_find_write_file() + luatexbase.remove_from_callback('find_write_file', + 'other dummy find_write_file') +end +% \end{macrocode} +% +% A |data| callback. +% +% \begin{macrocode} +function add_process_input_buffer() + luatexbase.add_to_callback('process_input_buffer', function(buffer) + texio.write_nl("I'm a dummy process_input_buffer") + return buffer.."\\msg{dummy}" + end, + 'dummy process_input_buffer') + luatexbase.add_to_callback('process_input_buffer', function(buffer) + texio.write_nl("I'm an other dummy process_input_buffer") + return buffer.."\\msg{otherdummy}" + end, + 'other dummy process_input_buffer') +end +function rm_one_process_input_buffer() + luatexbase.remove_from_callback('process_input_buffer', + 'dummy process_input_buffer') +end +function rm_two_process_input_buffer() + luatexbase.remove_from_callback('process_input_buffer', + 'other dummy process_input_buffer') +end +% \end{macrocode} +% % \begin{macrocode} % % \end{macrocode} @@ -885,7 +987,67 @@ luatexbase.call_callback("fooback", "default") %\RequirePackage{luatexbase-mcb} %<*testplain,testlatex> \catcode 64 11 +\def\msg{\immediate\write16} +\msg{===== BEGIN =====} +% \end{macrocode} +% +% Loading the lua files tests that the management functions can be called +% without raising errors. +% +% \begin{macrocode} \luatexbase@directlua{dofile('test-mcb.lua')} +% \end{macrocode} +% +% We now want to load and unload stuff from the various callbacks have them +% called to test the handlers. Here is a helper macro for that. +% +% \begin{macrocode} +\def\test#1{% + \msg{^^J*****^^J* Testing #1^^J*****} + \msg{* Add two functions} + \luatexbase@directlua{add_#1()} + \csname test_#1\endcsname + \msg{* Remove one} + \luatexbase@directlua{rm_one_#1()} + \csname test_#1\endcsname + \msg{* Remove the second} + \luatexbase@directlua{rm_two_#1()} + \csname test_#1\endcsname + \msg{* Add two functions again} + \luatexbase@directlua{add_#1()} + \csname test_#1\endcsname + \msg{* Remove all functions} + \luatexbase@directlua{luatexbase.reset_callback("#1")} + \csname test_#1\endcsname +} +% \end{macrocode} +% +% For each callback, we need a specific macro that triggers it. For the +% hyphenate test, we need to untrap |\everypar| first, in the \latex case. +% +% \begin{macrocode} +\catcode`\_ 11 +%\everypar{} +\def\test_hpack_filter{\setbox0=\hbox{bla}} +\def\test_hyphenate{\setbox0=\vbox{\hsize\z@ blablabla}} +\def\test_find_write_file{\immediate\openout15 test-mcb-out.log} +\def\test_process_input_buffer{\input test-mcb-aux.tex} +%\relax +% \end{macrocode} +% +% Now actually test them +% +% \begin{macrocode} +\test{hpack_filter} +\test{hyphenate} +\test{find_write_file} +\test{process_input_buffer} +% \end{macrocode} +% +% Done. +% +% \begin{macrocode} +\msg{===== END =====} % %\bye %\stop -- cgit v1.2.3