[latex3-commits] [git/LaTeX3-latex3-latex2e] hook-args: Add tests for \ShowHook (cd2b5fb4)
PhelypeOleinik
phelype.oleinik at latex-project.org
Thu Mar 30 03:44:48 CEST 2023
Repository : https://github.com/latex3/latex2e
On branch : hook-args
Link : https://github.com/latex3/latex2e/commit/cd2b5fb481d53d8a05f2b667187dc1d57fa9d2b3
>---------------------------------------------------------------
commit cd2b5fb481d53d8a05f2b667187dc1d57fa9d2b3
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date: Wed Mar 29 22:44:48 2023 -0300
Add tests for \ShowHook
>---------------------------------------------------------------
cd2b5fb481d53d8a05f2b667187dc1d57fa9d2b3
base/testfiles-lthooks/lthooks-033.lvt | 43 +++++++-
base/testfiles-lthooks/lthooks-033.tlg | 177 +++++++++++++++++++++++++++++++++
2 files changed, 215 insertions(+), 5 deletions(-)
diff --git a/base/testfiles-lthooks/lthooks-033.lvt b/base/testfiles-lthooks/lthooks-033.lvt
index 59893c20..e8662047 100644
--- a/base/testfiles-lthooks/lthooks-033.lvt
+++ b/base/testfiles-lthooks/lthooks-033.lvt
@@ -34,7 +34,9 @@
\AddToHookWithArguments{\hookname}[label]{\typeout{label-args(#1,#2)}}
\AddToHook{\hookname}[label]{\typeout{label-hashes(#1,#2)}}
\AddToHookWithArguments{\hookname}[label]{\typeout{label-args(#1,#2)}}
-
+ %
+ \ShowHook{\hookname}
+ %
\UseHook{\hookname}{foo}{bar}
}
@@ -59,8 +61,17 @@
\AddToHookWithArguments{\hookname}[label]{\typeout{label-args(#1,#2)}}
\AddToHook{\hookname}[label]{\typeout{label-hashes(#1,#2)}}
\AddToHookWithArguments{\hookname}[label]{\typeout{label-args(#1,#2)}}
-
- \UseHook{\hookname}{foo}{bar}
+ %
+ \ShowHook{\hookname}
+ %
+ \UseHook{\hookname}{foo}
+ %
+ % Any operation that may change the fast-execution token-list
+ % (macro nowadays) will trigger sorting again, and the labeled code
+ % stored in the code pool will error all over again about any
+ % "Illegal parameter number" added to the code. Not ideal...
+ \DeclareHookRule{\hookname}{foo}{before}{bar}
+ \ShowHook{\hookname}
}
%
@@ -84,8 +95,10 @@
\AddToHookWithArguments{\hookname}[label]{\typeout{label-args(#1,#2)}}
\AddToHook{\hookname}[label]{\typeout{label-hashes(#1,#2)}}
\AddToHookWithArguments{\hookname}[label]{\typeout{label-args(#1,#2)}}
-
- \UseHook{\hookname}{foo}{bar}
+ %
+ \ShowHook{\hookname}
+ %
+ \UseHook{\hookname}
}
%
@@ -98,6 +111,9 @@
\AddToHookWithArguments{test-10}{\typeout{10-top-level(#1,#2)}}
\AddToHookWithArguments{test-10}[label]{\typeout{10-label(#1,#2)}}
\AddToHookNextWithArguments{test-10}{\typeout{10-next(#1,#2)}}
+ %
+ \ShowHook{test-10}
+ %
\UseHook{test-10}{foo}{bar}%
{3}{4}{5}{6}{7}{8}{9}
}
@@ -123,8 +139,13 @@
{
\NewHookWithArguments{use-once}{2}
\AddToHookWithArguments{use-once}{\typeout{once(#1,#2)}}
+ %
+ \ShowHook{use-once}
+ %
\UseOneTimeHookWithArguments{use-once}{foo}{bar}
\AddToHookWithArguments{use-once}{\typeout{twice(#1,#2)}}
+ %
+ \ShowHook{use-once}
}
%
@@ -138,6 +159,8 @@
\AddToHookNextWithArguments{not-declared}{\typeout{next-args(#1,#2)}}
\AddToHookNext{not-declared}{\typeout{next-hashes(#1,#2)}}
%
+ \ShowHook{not-declared}
+ %
\NewHookWithArguments{not-declared}{2}
%
\AddToHookWithArguments{not-declared}{\typeout{top-more-args(#1,#2)}}
@@ -147,6 +170,8 @@
\AddToHookNextWithArguments{not-declared}{\typeout{next-more-args(#1,#2)}}
\AddToHookNext{not-declared}{\typeout{next-more-hashes(#1,#2)}}
%
+ \ShowHook{not-declared}
+ %
\UseHookWithArguments{not-declared}{foo}{bar}
}
@@ -161,6 +186,8 @@
\AddToHookNextWithArguments{not-nine}{\typeout{next-args(#1,#9)}}
\AddToHookNext{not-nine}{\typeout{next-hashes(#1,#9)}}
%
+ \ShowHook{not-nine}
+ %
\NewHookWithArguments{not-nine}{9}
%
\AddToHookWithArguments{not-nine}{\typeout{top-more-args(#1,#9)}}
@@ -170,6 +197,8 @@
\AddToHookNextWithArguments{not-nine}{\typeout{next-more-args(#1,#9)}}
\AddToHookNext{not-nine}{\typeout{next-more-hashes(#1,#9)}}
%
+ \ShowHook{not-nine}
+ %
\UseHookWithArguments{not-nine}{foo}2345678{bar}
}
@@ -184,12 +213,16 @@
\AddToHookNext{liar}{\typeout{next-hash(#1)}}
\AddToHook{liar}[label]{\typeout{label-hash(#1)}}
%
+ \ShowHook{liar}
+ %
\NewHook{liar}
%
\AddToHook{liar}{\typeout{more-top-hash(#1)}}
\AddToHookNext{liar}{\typeout{more-next-hash(#1)}}
\AddToHook{liar}[label]{\typeout{more-label-hash(#1)}}
%
+ \ShowHook{liar}
+ %
\UseHook{liar}
}
diff --git a/base/testfiles-lthooks/lthooks-033.tlg b/base/testfiles-lthooks/lthooks-033.tlg
index 6bebc4cd..282564bf 100644
--- a/base/testfiles-lthooks/lthooks-033.tlg
+++ b/base/testfiles-lthooks/lthooks-033.tlg
@@ -3,6 +3,19 @@ Don't change this file in any respect.
============================================================
TEST 1: Two arguments
============================================================
+-> The hook 'test-2' (2 arguments):
+> Code chunks:
+> label -> \typeout {label-hashes(##1,##2)}\typeout {label-args(#1,#2)}\typeout {label-hashes(##1,##2)}\typeout {label-args(#1,#2)}
+> Document-level (top-level) code (executed last):
+> -> \typeout {top-hashes(##1,##2)}\typeout {top-args(#1,#2)}\typeout {top-hashes(##1,##2)}\typeout {top-args(#1,#2)}
+> Extra code for next invocation:
+> -> \typeout {next-hashes(##1,##2)}\typeout {next-args(#1,#2)}\typeout {next-hashes(##1,##2)}\typeout {next-args(#1,#2)}
+> Rules:
+> ---
+> Execution order:
+> label.
+<recently read> }
+l. ... }
label-hashes(##1,##2)
label-args(foo,bar)
label-hashes(##1,##2)
@@ -75,6 +88,19 @@ l. ... }
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.
+-> The hook 'test-1' (1 argument):
+> Code chunks:
+> label -> \typeout {label-hashes(##1,##2)}\typeout {label-args(#1,#2)}\typeout {label-hashes(##1,##2)}\typeout {label-args(#1,#2)}
+> Document-level (top-level) code (executed last):
+> -> \typeout {top-hashes(##1,##2)}\typeout {top-args(#1,##2)}\typeout {top-hashes(##1,##2)}\typeout {top-args(#1,##2)}
+> Extra code for next invocation:
+> -> \typeout {next-hashes(##1,##2)}\typeout {next-args(#1,##2)}\typeout {next-hashes(##1,##2)}\typeout {next-args(#1,##2)}
+> Rules:
+> ---
+> Execution order:
+> label.
+<recently read> }
+l. ... }
label-hashes(##1,##2)
label-args(foo,##2)
label-hashes(##1,##2)
@@ -87,6 +113,33 @@ next-hashes(##1,##2)
next-args(foo,##2)
next-hashes(##1,##2)
next-args(foo,##2)
+! Illegal parameter number in definition of \__hook test-1.
+<to be read again>
+ 2
+l. ... }
+You meant to type ## instead of #, right?
+Or maybe a } was forgotten somewhere earlier, and things
+are all screwed up? I'm going to assume that you meant ##.
+! Illegal parameter number in definition of \__hook test-1.
+<to be read again>
+ 2
+l. ... }
+You meant to type ## instead of #, right?
+Or maybe a } was forgotten somewhere earlier, and things
+are all screwed up? I'm going to assume that you meant ##.
+-> The hook 'test-1' (1 argument):
+> Code chunks:
+> label -> \typeout {label-hashes(##1,##2)}\typeout {label-args(#1,#2)}\typeout {label-hashes(##1,##2)}\typeout {label-args(#1,#2)}
+> Document-level (top-level) code (executed last):
+> -> \typeout {top-hashes(##1,##2)}\typeout {top-args(#1,##2)}\typeout {top-hashes(##1,##2)}\typeout {top-args(#1,##2)}
+> Extra code for next invocation:
+> ---
+> Rules:
+> ---
+> Execution order:
+> label.
+<recently read> }
+l. ... }
============================================================
============================================================
TEST 3: Zero arguments
@@ -135,6 +188,19 @@ l. ... }
You tried to use \AddToHookWithArguments on a hook that takes no arguments.
Check the usage of the hook or use \AddToHook instead.
LaTeX will use \AddToHook.
+-> The hook 'test-0':
+> Code chunks:
+> label -> \typeout {label-hashes(##1,##2)}\typeout {label-args(##1,##2)}\typeout {label-hashes(##1,##2)}\typeout {label-args(##1,##2)}
+> Document-level (top-level) code (executed last):
+> -> \typeout {top-hashes(##1,##2)}\typeout {top-args(##1,##2)}\typeout {top-hashes(##1,##2)}\typeout {top-args(##1,##2)}
+> Extra code for next invocation:
+> -> \typeout {next-hashes(##1,##2)}\typeout {next-args(##1,##2)}\typeout {next-hashes(##1,##2)}\typeout {next-args(##1,##2)}
+> Rules:
+> ---
+> Execution order:
+> label.
+<recently read> }
+l. ... }
label-hashes(##1,##2)
label-args(##1,##2)
label-hashes(##1,##2)
@@ -157,6 +223,19 @@ For immediate help type H <return>.
l. ... }
You tried to declare a hook with 10 arguments, but a hook can only have up to
nine. LaTeX will define this hook with nine arguments.
+-> The hook 'test-10' (9 arguments):
+> Code chunks:
+> label -> \typeout {10-label(#1,#2)}
+> Document-level (top-level) code (executed last):
+> -> \typeout {10-top-level(#1,#2)}
+> Extra code for next invocation:
+> -> \typeout {10-next(#1,#2)}
+> Rules:
+> ---
+> Execution order:
+> label.
+<recently read> }
+l. ... }
10-label(foo,bar)
10-top-level(foo,bar)
10-next(foo,bar)
@@ -196,6 +275,19 @@ no-next(##1,##2)
============================================================
TEST 6: One-time hook with arguments
============================================================
+-> The hook 'use-once' (2 arguments):
+> Code chunks:
+> ---
+> Document-level (top-level) code (executed last):
+> -> \typeout {once(#1,#2)}
+> Extra code for next invocation:
+> ---
+> Rules:
+> ---
+> Execution order:
+> ---.
+<recently read> }
+l. ... }
once(foo,bar)
! LaTeX hooks Error: You can't have arguments in used one-time hook
(hooks) 'use-once'.
@@ -207,10 +299,41 @@ been used. You have to add the code before the hook is used, or add the code
without arguments using \AddToHook instead.
LaTeX will use \AddToHook.
twice(##1,##2)
+-> The hook 'use-once' (2 arguments):
+> The hook is empty.
+<recently read> }
+l. ... }
============================================================
============================================================
TEST 7: Add with arguments before hook is declared
============================================================
+-> The hook 'not-declared':
+> The hook is not declared.
+> Code chunks:
+> label -> \typeout {label-args(#1,#2)}\typeout {label-hashes(##1,##2)}
+> Document-level (top-level) code:
+> -> \typeout {top-args(#1,#2)}\typeout {top-hashes(##1,##2)}
+> Extra code for next invocation:
+> -> \typeout {next-args(#1,#2)}\typeout {next-hashes(##1,##2)}
+> Rules:
+> ---
+> Execution order:
+> Not set because the hook is undeclared.
+<recently read> }
+l. ... }
+-> The hook 'not-declared' (2 arguments):
+> Code chunks:
+> label -> \typeout {label-args(#1,#2)}\typeout {label-hashes(##1,##2)}\typeout {label-more-args(#1,#2)}\typeout {label-more-hashes(##1,##2)}
+> Document-level (top-level) code (executed last):
+> -> \typeout {top-args(#1,#2)}\typeout {top-hashes(##1,##2)}\typeout {top-more-args(#1,#2)}\typeout {top-more-hashes(##1,##2)}
+> Extra code for next invocation:
+> -> \typeout {next-args(#1,#2)}\typeout {next-hashes(##1,##2)}\typeout {next-more-args(#1,#2)}\typeout {next-more-hashes(##1,##2)}
+> Rules:
+> ---
+> Execution order:
+> label.
+<recently read> }
+l. ... }
label-args(foo,bar)
label-hashes(##1,##2)
label-more-args(foo,bar)
@@ -227,6 +350,33 @@ next-more-hashes(##1,##2)
============================================================
TEST 8: Testing with nine arguments
============================================================
+-> The hook 'not-nine':
+> The hook is not declared.
+> Code chunks:
+> label -> \typeout {label-args(#1,#9)}\typeout {label-hashes(##1,##9)}
+> Document-level (top-level) code:
+> -> \typeout {top-args(#1,#9)}\typeout {top-hashes(##1,##9)}
+> Extra code for next invocation:
+> -> \typeout {next-args(#1,#9)}\typeout {next-hashes(##1,##9)}
+> Rules:
+> ---
+> Execution order:
+> Not set because the hook is undeclared.
+<recently read> }
+l. ... }
+-> The hook 'not-nine' (9 arguments):
+> Code chunks:
+> label -> \typeout {label-args(#1,#9)}\typeout {label-hashes(##1,##9)}\typeout {label-more-args(#1,#9)}\typeout {label-more-hashes(##1,##9)}
+> Document-level (top-level) code (executed last):
+> -> \typeout {top-args(#1,#9)}\typeout {top-hashes(##1,##9)}\typeout {top-more-args(#1,#9)}\typeout {top-more-hashes(##1,##9)}
+> Extra code for next invocation:
+> -> \typeout {next-args(#1,#9)}\typeout {next-hashes(##1,##9)}\typeout {next-more-args(#1,#9)}\typeout {next-more-hashes(##1,##9)}
+> Rules:
+> ---
+> Execution order:
+> label.
+<recently read> }
+l. ... }
label-args(foo,bar)
label-hashes(##1,##9)
label-more-args(foo,bar)
@@ -243,6 +393,20 @@ next-more-hashes(##1,##9)
============================================================
TEST 9: Add with hooks, but declare without
============================================================
+-> The hook 'liar':
+> The hook is not declared.
+> Code chunks:
+> label -> \typeout {label-arg(#1)}\typeout {label-hash(##1)}
+> Document-level (top-level) code:
+> -> \typeout {top-arg(#1)}\typeout {top-hash(##1)}
+> Extra code for next invocation:
+> -> \typeout {next-arg(#1)}\typeout {next-hash(##1)}
+> Rules:
+> ---
+> Execution order:
+> Not set because the hook is undeclared.
+<recently read> }
+l. ... }
! Illegal parameter number in definition of \__hook_toplevel liar.
<to be read again>
1
@@ -271,6 +435,19 @@ l. ... }
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.
+-> The hook 'liar':
+> Code chunks:
+> label -> \typeout {label-arg(#1)}\typeout {label-hash(##1)}\typeout {more-label-hash(##1)}
+> Document-level (top-level) code (executed last):
+> -> \typeout {top-arg(##1)}\typeout {top-hash(##1)}\typeout {more-top-hash(##1)}
+> Extra code for next invocation:
+> -> \typeout {next-arg(##1)}\typeout {next-hash(##1)}\typeout {more-next-hash(##1)}
+> Rules:
+> ---
+> Execution order:
+> label.
+<recently read> }
+l. ... }
label-arg(##1)
label-hash(##1)
more-label-hash(##1)
More information about the latex3-commits
mailing list.