Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lthooks new showhook 2 #1249

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 206 additions & 0 deletions base/testfiles-lthooks/helpers/lthooks-show.sty
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
% This is a library of commands used by various `lthooks*.lvt`

\ExplSyntaxOn
\tl_new:N \l__TESTHookShow_tl

\IncludeInRelease{2023-06-01}{\WithArgs}{With arguments}
\cs_new:Npn \TESTHookWithArgs:Nnn #1 #2 #3
% #1 the local tl variable holding the result
% #2 the template
% #3 the number of arguments
{
\tl_clear:N #1
\int_step_inline:nn { #3 } { \tl_put_right:Nn #1 { #2 } }
}
\def\TESTBlockHookCmdWithArgs#1#2#3{
% run at the top level
% #1: the title of the block
% #2: the csname of the command
\BEGINTEST{Command:~#1}
\DebugShowHookCmd{#2}
\TESTHookWithArgs:Nnn \l__TESTHookShow_tl { ######1/ } { #3 }
\exp_args:Nnx
\AddToHookWithArguments { cmd/#2/before }
{ \exp_not:N \TYPE { <#2~BEFORE:~/\exp_not:V \l__TESTHookShow_tl> } }
\exp_args:Nnx
\AddToHookWithArguments { cmd/#2/after }
{ \exp_not:N \TYPE { <#2~AFTER :~/\exp_not:V \l__TESTHookShow_tl> } }
\DebugShowHookCmd{#2}
\ENDTEST
}
\def\TESTBlockHookWithArgs#1#2#3{
% run at the top level
% #1: the title of the block
% #2: the name of the hook
% #3: the number of arguments
% Not in the 2020-10-01 release
\BEGINTEST{#1}
\def\TEST{
\TESTHookWithArgs:Nnn \l__TESTHookShow_tl { { arg_####1 } } { #3 }
\TYPE{\token_to_str:N \UseHookWithArguments {#2} {#3} \l__TESTHookShow_tl =>}
\exp_last_unbraced:Nno
\use:n { \UseHookWithArguments {#2} {#3} } \l__TESTHookShow_tl
\ShowHook{#2}
}
\BEGINTEST{Undeclared~#2}
\TEST
\ENDTEST
\BEGINTEST{#2~+~TOP-LEVEL}
\TESTHookWithArgs:Nnn \l__TESTHookShow_tl { arg~######1 / } { #3 }
\exp_args:Nnx
\use:n { \AddToHookWithArguments { #2 } }
{ \exp_not:N \TYPE { <#2~TOP-LEVEL:~/\exp_not:V \l__TESTHookShow_tl> } }
\TEST
\ENDTEST
\BEGINTEST{#2~+~A~LABEL}
\TESTHookWithArgs:Nnn \l__TESTHookShow_tl { arg~######1 / } { #3 }
\exp_args:Nnx
\use:n { \AddToHookWithArguments { #2 }[A~LABEL] }
{ \exp_not:N \TYPE { <#2~A~CODE:~/\exp_not:V \l__TESTHookShow_tl> } }
\TEST
\ENDTEST
\BEGINTEST{#2~+~B~LABEL}
\TESTHookWithArgs:Nnn \l__TESTHookShow_tl { arg~######1 / } { #3 }
\exp_args:Nnx
\use:n { \AddToHookWithArguments { #2 }[B~LABEL] }
{ \exp_not:N \TYPE { <#2~B~CODE:~/\exp_not:V \l__TESTHookShow_tl> } }
\TEST
\ENDTEST
\BEGINTEST{#2~+~C~LABEL}
\TESTHookWithArgs:Nnn \l__TESTHookShow_tl { arg~######1 / } { #3 }
\exp_args:Nnx
\use:n { \AddToHookWithArguments { #2 }[C~LABEL] }
{ \exp_not:N \TYPE { <#2~C~CODE:~/\exp_not:V \l__TESTHookShow_tl> } }
\TEST
\ENDTEST
\BEGINTEST{#2~+~NEXT}
\TESTHookWithArgs:Nnn \l__TESTHookShow_tl { arg~######1 / } { #3 }
\exp_args:Nnx
\use:n { \AddToHookNextWithArguments { #2 } }
{ \exp_not:N \TYPE { <#2~NEXT-ONLY~CODE:~/\exp_not:V \l__TESTHookShow_tl> } }
\ShowHook{#2}
\TEST
\ENDTEST
\BEGINTEST{#2~+~C~LABEL~<~A~LABEL}
\DeclareHookRule{#2}{C~LABEL}{before}{A~LABEL}
\TEST
\ENDTEST
\BEGINTEST{#2~+~DEFAULT:~B~LABEL~>~C~LABEL}
\DeclareDefaultHookRule{B~LABEL}{after}{C~LABEL}
\TEST
\ENDTEST
\ENDTEST
}
\EndIncludeInRelease
\ExplSyntaxOff
%

\IncludeInRelease{2020-10-01}{\TESTBlockHook}{Message}

\def\DebugShowHookEnv#1{
\ShowHook{env/#1/before}
\ShowHook{env/#1/begin}
\ShowHook{env/#1/end}
\ShowHook{env/#1/after}
}

\def\DebugShowHookCmd#1{
\ShowHook{cmd/#1/before}
\ShowHook{cmd/#1/after}
}

\def\TESTBlockHookEnv#1#2{
% run at the top level
% #1: the title of the block
% #2: the name of the environment
\BEGINTEST{Environment: #2}
\DebugShowHookEnv{#2}
\AddToHook{env/#2/before}{\TYPE{<#2 BEFORE>}}
\AddToHook{env/#2/begin}{\TYPE{<#2 BEGIN>}}
\AddToHook{env/#2/end}{\TYPE{<#2 END>}}
\AddToHook{env/#2/after}{\TYPE{<#2 AFTER>}}
\DebugShowHookEnv{#2}
\ENDTEST
}

\def\TESTBlockHookCmd#1#2{
% run at the top level
% #1: the title of the block
% #2: the csname of the command
\BEGINTEST{Command: #1}
\DebugShowHookCmd{#2}
\AddToHook{cmd/#2/before}{\TYPE{<#2 BEFORE>}}
\AddToHook{cmd/#2/after}{\TYPE{<#2 AFTER>}}
\DebugShowHookCmd{#2}
\ENDTEST
}
\def\TESTBlockHookCustomGeneric#1#2{
% run at the top level
% #1: the title of the block
% #2: the name of the hook
\BEGINTEST{Custom generic hook: #1}
\def\TEST{
\UseHook{#2}
\ShowHook{#2}
}
\BEGINTEST{Raw: #2}
\AddToHook{#2}[LABEL]{\TYPE{<#2 CODE>}}
\TEST
\ENDTEST
\BEGINTEST{Activated: #2}
\ActivateGenericHook{#2}
\TEST
\ENDTEST
\BEGINTEST{Disabled: #2}
\DisableGenericHook{#2}
\TEST
\ENDTEST
\ENDTEST
}
\def\TESTBlockHook#1#2{
% run at the top level
% #1: the title of the block
% #2: the name of the hook
\BEGINTEST{#1}
\def\TEST{
\UseHook{#2}
\ShowHook{#2}
}
\BEGINTEST{Undeclared #2}
\TEST
\ENDTEST
\BEGINTEST{#2 + TOP-LEVEL}
\AddToHook{#2}{\TYPE{<#2 TOP-LEVEL>}}
\TEST
\ENDTEST
\BEGINTEST{#2 + A LABEL}
\AddToHook{#2}[A LABEL]{\TYPE{<#2 A CODE>}}
\TEST
\ENDTEST
\BEGINTEST{#2 + B LABEL}
\AddToHook{#2}[B LABEL]{\TYPE{<#2 B CODE>}}
\TEST
\ENDTEST
\BEGINTEST{#2 + C LABEL}
\AddToHook{#2}[C LABEL]{\TYPE{<#2 C CODE>}}
\TEST
\ENDTEST
\BEGINTEST{#2 + NEXT}
\AddToHookNext{#2}{\TYPE{<NEXT-ONLY>}}
\ShowHook{#2}
\TEST
\ENDTEST
\BEGINTEST{#2 + C LABEL < A LABEL}
\DeclareHookRule{#2}{C LABEL}{before}{A LABEL}
\TEST
\ENDTEST
\BEGINTEST{#2 + DEFAULT: B LABEL > C LABEL}
\DeclareDefaultHookRule{B LABEL}{after}{C LABEL}
\TEST
\ENDTEST
\ENDTEST
}
\EndIncludeInRelease%{2020-10-01}{\TESTBlockHookOneArg}{Message}

\IncludeInRelease{0000-00-00}{\whatever}{Message}
\EndIncludeInRelease
86 changes: 86 additions & 0 deletions base/testfiles-lthooks/lthooks-show-2020-10-01.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
% This is somehow `lthooks-show.lvt` frozen to the 2020-10-01 release
% before hooks with arguments were introduced.

\input{regression-test}
\RequirePackage[2020-10-01]{latexrelease}
\TYPE{********* RequirePackage[2020-10-01]{latexrelease}}

\RequirePackage{./lthooks-show}

\ExplSyntaxOn
\debug_on:n { check-declarations , deprecation }
\ExplSyntaxOff

\documentclass{article}

% There are many different hook profiles.

\START

\TESTBlockHookEnv
{Undefined environment envA}
{envA}
\NewDocumentEnvironment
{envA}{}
{\TYPE{<BEGIN{envA}>}}
{\TYPE{<END{envA}>}}
\begin{envA}\TYPE{<envA BODY>}\end{envA}

\NewDocumentEnvironment
{envB}{}
{\TYPE{<BEGIN{envB}>}}
{\TYPE{<END{envB}>}}
\TESTBlockHookEnv
{Defined environment envB}
{envB}
\begin{envB}\TYPE{<envB BODY>}\end{envB}

\TESTBlockHookCmd
{Undefined command with no arguments}
{cmdA}
\NewDocumentCommand\cmdA{}{\TYPE{<cmdA BODY>}}
\cmdA

\NewDocumentCommand\cmdB{}{\TYPE{<cmdB BODY>}}
\TESTBlockHookCmd
{Defined command with no arguments}
{cmdB}
\cmdB

\TESTBlockHookCustomGeneric
{CUSTOM GENERIC HOOK}
{CUSTOM GENERIC HOOK}

\TESTBlockHook
{OTHER HOOK: Undeclared}
{UNDECLARED HOOK}

\NewHook{DECLARED HOOK}

\TESTBlockHook
{OTHER HOOK: declared}
{DECLARED HOOK}

\NewReversedHook{DECLARED REVERSED}

\TESTBlockHook
{OTHER HOOK: declared reversed}
{DECLARED REVERSED}

\OMIT
\begin{document}
\TIMO

\BEGINTEST{After \begin{document}}

\BEGINTEST{Commands}
\cmdA
\SEPARATOR
\cmdB
\ENDTEST

\ENDTEST

\TYPE{!!!! If this test changes the documentation needs updating !!!!}

\END
Loading