[latex3-commits] [git/LaTeX3-latex3-l3build] master: Support assertions (fixes #102) (49f8b53)

Joseph Wright joseph.wright at morningstar2.co.uk
Fri Nov 1 21:19:20 CET 2019


Repository : https://github.com/latex3/l3build
On branch  : master
Link       : https://github.com/latex3/l3build/commit/49f8b533aef44d155d3a88fe29b69caf7bb45b08

>---------------------------------------------------------------

commit 49f8b533aef44d155d3a88fe29b69caf7bb45b08
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Fri Nov 1 20:19:20 2019 +0000

    Support assertions (fixes #102)


>---------------------------------------------------------------

49f8b533aef44d155d3a88fe29b69caf7bb45b08
 CHANGELOG.md                   |  4 ++++
 l3build.dtx                    | 38 +++++++++++++++++++++++++++++++++++++-
 testfiles/00-test-1.luatex.tlg |  7 +++++++
 testfiles/00-test-1.lvt        | 11 +++++++++++
 testfiles/00-test-1.tlg        |  7 +++++++
 testfiles/00-test-1.xetex.tlg  |  7 +++++++
 6 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 42291c9..baaa8a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Added
+
+- New `\ASSERT` and `\ASSERTSTR` functions (issue #102)
+
 ### Changed
 
 - Avoid normalisation of (u)pTeX data when this is standard engine
diff --git a/l3build.dtx b/l3build.dtx
index c6b7198..5b37e7b 100644
--- a/l3build.dtx
+++ b/l3build.dtx
@@ -929,6 +929,10 @@
 % \item
 % \cs{SHOWFILE} (\eTeX{} only) Shows the content of the file given as an
 % argument.
+% \item
+% \cs{ASSERT} and \cs{ASSERTSTR} (\eTeX{} only) Asserts if the full expansion
+% of the two required arguments are the same: the \cs{ASSERT} function is
+% token-based, the \cs{ASSERTSTR} works on a string basis.
 % \end{itemize}
 % An example of some of these commands is shown following.
 % \begin{Verbatim}
@@ -2233,7 +2237,9 @@
 %     \FALSE,
 %     \YES,
 %     \NO,
-%     \NEWLINE
+%     \NEWLINE,
+%     \ASSERT,
+%     \ASSERTSTR
 %   }
 %   We are not starved for space in the log file output, so let's make it as
 %   verbose as is useful when reading the |.diff|'s.
@@ -2285,6 +2291,36 @@
 \def \YES   {\TYPE{YES}}
 \def \NO    {\TYPE{NO}}
 \def \NEWLINE {\TYPE{^^J}}
+\csname protected\endcsname\long\def\ASSERT#1#2{%
+  \begingroup
+    \edef\@tempa{#1}%
+    \edef\@tempb{#2}%
+    \ifx\@tempa\@tempb
+      \TYPE{PASSED}%
+    \else
+      \TYPE{FAILED}%
+    \fi
+  \endgroup
+}
+\csname protected\endcsname\long\def\ASSERTSTR#1#2{%
+  \begingroup
+    \edef\@tempa{#1}%
+    \edef\@tempb{#2}%
+    \edef\@tempa{\detokenize\expandafter{\@tempa}}%
+    \edef\@tempb{\detokenize\expandafter{\@tempb}}%
+    \ifx\@tempa\@tempb
+      \TYPE{PASSED}%
+    \else
+      \TYPE{FAILED}%
+    \fi
+  \endgroup
+}
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname detokenize\endcsname\relax
+  \long\def\ASSERTSTR#1#2{%
+    \TYPE{FEATURE UNAVAILABLE}%
+  }
+\fi
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/testfiles/00-test-1.luatex.tlg b/testfiles/00-test-1.luatex.tlg
index 7f6d6f2..806c6ba 100644
--- a/testfiles/00-test-1.luatex.tlg
+++ b/testfiles/00-test-1.luatex.tlg
@@ -16,6 +16,13 @@ l. ...}
 TEST 2: Enviornment test
 ============================================================
 ============================================================
+============================================================
+TEST 3: Assertions
+============================================================
+PASSED
+FAILED
+PASSED
+============================================================
 Completed box being shipped out [1]
 \vbox(578.15999+0.0)x469.75499, direction TLT
 .\glue 0.0
diff --git a/testfiles/00-test-1.lvt b/testfiles/00-test-1.lvt
index 0a271e9..f641cbf 100644
--- a/testfiles/00-test-1.lvt
+++ b/testfiles/00-test-1.lvt
@@ -32,4 +32,15 @@
   \end{verbatim}
 \ENDTEST
 
+\begingroup
+  \catcode`Q=4 %
+  \gdef\ODD{Q}%
+\endgroup
+
+\TEST{Assertions}{%
+  \ASSERT{A}{A}%
+  \ASSERT{Q}{\ODD}%
+  \ASSERTSTR{Q}{\ODD}%
+}
+
 \end{document}
diff --git a/testfiles/00-test-1.tlg b/testfiles/00-test-1.tlg
index f51200e..8ac81bd 100644
--- a/testfiles/00-test-1.tlg
+++ b/testfiles/00-test-1.tlg
@@ -16,6 +16,13 @@ l. ...}
 TEST 2: Enviornment test
 ============================================================
 ============================================================
+============================================================
+TEST 3: Assertions
+============================================================
+PASSED
+FAILED
+PASSED
+============================================================
 Completed box being shipped out [1]
 \vbox(578.15999+0.0)x469.75499
 .\glue 0.0
diff --git a/testfiles/00-test-1.xetex.tlg b/testfiles/00-test-1.xetex.tlg
index 26221f5..b8fa57e 100644
--- a/testfiles/00-test-1.xetex.tlg
+++ b/testfiles/00-test-1.xetex.tlg
@@ -16,6 +16,13 @@ l. ...}
 TEST 2: Enviornment test
 ============================================================
 ============================================================
+============================================================
+TEST 3: Assertions
+============================================================
+PASSED
+FAILED
+PASSED
+============================================================
 Completed box being shipped out [1]
 \vbox(578.15999+0.0)x469.75499
 .\glue 0.0





More information about the latex3-commits mailing list