[latex3-commits] [git/LaTeX3-latex3-latex3] master: Safety checks and yet more tests (b1179ecf4)

Phelype Oleinik phe.h.o1 at gmail.com
Tue Sep 10 03:42:22 CEST 2019


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/b1179ecf4d6b8be589517970acae867556f663f9

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

commit b1179ecf4d6b8be589517970acae867556f663f9
Author: Phelype Oleinik <phe.h.o1 at gmail.com>
Date:   Mon Sep 9 22:42:22 2019 -0300

    Safety checks and yet more tests


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

b1179ecf4d6b8be589517970acae867556f663f9
 l3experimental/l3cctab/l3cctab.dtx                 | 115 ++++++++++++++-------
 l3experimental/l3cctab/testfiles/m3cctab001.lvt    |   6 +-
 ...m3cctab001.luatex.tlg => m3cctab002.luatex.tlg} |  26 +++--
 l3experimental/l3cctab/testfiles/m3cctab002.lvt    |  29 ++++++
 l3experimental/l3cctab/testfiles/m3cctab002.tlg    |  39 +++++++
 5 files changed, 164 insertions(+), 51 deletions(-)

diff --git a/l3experimental/l3cctab/l3cctab.dtx b/l3experimental/l3cctab/l3cctab.dtx
index d7ceda7f4..cf952ed50 100644
--- a/l3experimental/l3cctab/l3cctab.dtx
+++ b/l3experimental/l3cctab/l3cctab.dtx
@@ -122,6 +122,8 @@
 %     \cs{cctab_if_exist:NTF} \meta{category code table} \Arg{true code} \Arg{false code}
 %   \end{syntax}
 %   Tests whether the \meta{category code table} is currently defined.
+%   This does not check that the \meta{category code table} really is a
+%   category code table.
 % \end{function}
 %
 % \subsection{Constant category code tables}
@@ -198,8 +200,8 @@
 % \end{variable}
 %
 % \begin{macro}{\cctab_new:N,\cctab_new:c}
-% \begin{macro}{\cctab_begin:N,\cctab_begin:c}
-% \begin{macro}{\cctab_end:}
+% \begin{macro}{\@@_begin:N,\@@_begin:c}
+% \begin{macro}{\@@_end:}
 % \begin{macro}{\cctab_gset:Nn,\cctab_gset:cn}
 %   As \LuaTeX{} offers engine support for category code tables, and this is
 %   entirely lacking from the other engines, we need two complementary
@@ -255,7 +257,7 @@
         \tex_savecatcodetable:D \g_@@_stack_int
         \tex_catcodetable:D \g_@@_stack_int
       }
-    \cs_new_protected:Npn \cctab_end:
+    \cs_new_protected:Npn \@@_end:
       {
         \int_gsub:Nn \g_@@_stack_int { 2 }
         \seq_if_empty:NTF \g_@@_stack_seq
@@ -271,7 +273,7 @@
     \cs_new_protected:Npn \cctab_gset:Nn #1#2
       {
         \group_begin:
-          #2
+          #2 \scan_stop:
           \tex_savecatcodetable:D #1
         \group_end:
       }
@@ -343,7 +345,7 @@
       }
     \cs_generate_variant:Nn \intarray_new:Nn { c }
     \cs_generate_variant:Nn \intarray_gset:Nnn { c }
-    \cs_new_protected:Npn \cctab_end:
+    \cs_new_protected:Npn \@@_end:
       {
         \int_step_inline:nn { 256 }
           {
@@ -360,7 +362,7 @@
     \cs_new_protected:Npn \cctab_gset:Nn #1#2
       {
         \group_begin:
-          #2
+          #2 \scan_stop:
           \int_step_inline:nn { 256 }
             {
               \intarray_gset:cnn { g_@@_ \int_use:N #1 _cctab } {##1}
@@ -377,63 +379,89 @@
 % \end{macro}
 % \end{macro}
 %
-% \begin{macro}{\cctab_begin:N}
-%   Check if a \meta{cctab~var} exists before trying to use it.
-%   Otherwise the code would throw an ``undefined control sequence''.
+% \begin{macro}{\cctab_begin:N,\cctab_end:}
+%   These functions perform a few sanity checks before calling the
+%   functions which will do the heavy-lifting.
+%   \cs{cctab_begin:N} checks if a \meta{cctab~var} exists before trying
+%   to use it. \cs{cctab_end:} checks if a \cs{cctab_begin:N} was used
+%   some time earlier.
+%   
+%   Skipping these checks would result in an ``Undefined control
+%   sequence'' error for \cs{cctab_begin:N} with an undefined
+%   \meta{cctab~var}, and a ``Missing font identifier'' for an extra
+%   \cs{cctab_end:}.
 %    \begin{macrocode}
 \cs_new_protected:Npn \cctab_begin:N #1
+  { \@@_chk_if_valid:NT #1 { \__cctab_begin:N #1 } }
+\cs_generate_variant:Nn \cctab_begin:N { c }
+\cs_new_protected:Npn \cctab_end:
   {
-    \cctab_if_exist:NTF #1
-      { \__cctab_begin:N #1 }
-      {
-        \__kernel_msg_error:nnx { kernel } { variable-not-defined }
-          { \token_to_str:N #1 }
-      }
+    \int_compare:nNnTF { \g_@@_stack_int } = { \c_zero_int }
+      { \__kernel_msg_error:nn { kernel } { cctab-extra-end } }
+      { \@@_end: }
   }
-\cs_generate_variant:Nn \cctab_begin:N { c }
 %    \end{macrocode}
 % \end{macro}
 %
 % \begin{macro}{\cctab_if_exist:N,\cctab_if_exist:c}
 %   Checks whether a \meta{cctab~var} is defined.
-%   The \LuaTeX{} code simply does \cs{cs_if_exist:N} on the argument,
-%   as the engine saves the category code table in a single control
-%   sequence. The code for other engines does that, but also check if
-%   the internal \meta{intarray~var} exists.
+%    \begin{macrocode}
+\prg_new_eq_conditional:NNn \cctab_if_exist:N \cs_if_exist:N
+  { TF , T , F , p }
+\prg_new_eq_conditional:NNn \cctab_if_exist:c \cs_if_exist:c
+  { TF , T , F , p }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_chk_if_valid:N}
+%   Checks whether the argument is defined and whether it is a valid
+%   \meta{cctab~var}. In \LuaTeX{} the validity of the \meta{cctab~var}
+%   is checked by the engine, which complains if the argument is not
+%   a \cs{chardef}'ed constant. In other engines, check if the
+%   underlying \cs[no-index]{g_@@_\meta{integer}_cctab}
+%   \meta{intarray~var} exists.
 %    \begin{macrocode}
 \sys_if_engine_luatex:TF
   {
-    \prg_new_eq_conditional:NNn \cctab_if_exist:N \cs_if_exist:N
-      { TF , T , F , p }
-    \prg_new_eq_conditional:NNn \cctab_if_exist:c \cs_if_exist:c
-      { TF , T , F , p }
+    \prg_new_protected_conditional:Npnn \@@_chk_if_valid:N #1
+      { TF , T , F }
+      {
+        \cctab_if_exist:NTF #1
+          { \prg_return_true: }
+          {
+            \__kernel_msg_error:nnx { kernel } { command-not-defined }
+              { \token_to_str:N #1 }
+            \prg_return_false:
+          }
+      }
   }
   {
-    \prg_new_conditional:Npnn \cctab_if_exist:N #1 { TF , T , F , p }
+    \prg_new_protected_conditional:Npnn \@@_chk_if_valid:N #1
+      { TF , T , F }
       {
-        \cs_if_exist:NTF #1
+        \cctab_if_exist:NTF #1
           {
             \cs_if_exist:cTF { g_@@_ \int_use:N #1 _cctab }
               { \prg_return_true: }
-              { \prg_return_false: }
+              {
+                \__kernel_msg_error:nnx { kernel } { invalid-cctab }
+                  { \token_to_str:N #1 }
+                \prg_return_false:
+              }
           }
-          { \prg_return_false: }
-      }
-    \prg_new_conditional:Npnn \cctab_if_exist:c #1 { TF , T , F , p }
-      {
-        \cs_if_exist:cTF {#1}
           {
-            \cs_if_exist:cTF { g_@@_ \int_use:c {#1} _cctab }
-              { \prg_return_true: }
-              { \prg_return_false: }
+            \__kernel_msg_error:nnx { kernel } { command-not-defined }
+              { \token_to_str:N #1 }
+            \prg_return_false:
           }
-          { \prg_return_false: }
       }
   }
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\cctab_const:Nn}
+% \begin{macro}{\cctab_const:Nn,\cctab_const:cn}
+%  Creates a new \meta{cctab~var} then sets it with the current and
+%  user-supplied codes.
 %    \begin{macrocode}
 \cs_new_protected:Npn \cctab_const:Nn #1#2
   {
@@ -489,6 +517,19 @@
     LaTeX~has~been~asked~to~switch~to~a~new~category~code~table,~
     but~there~is~no~more~space~to~do~this!
   }
+\__kernel_msg_new:nnnn { kernel } { cctab-extra-end }
+  { Extra~\iow_char:N\\cctab_end:~ignored~\msg_line_context:. }
+  {
+    LaTeX~came~across~a~\iow_char:N\\cctab_end:~without~a~matching~
+    \iow_char:N\\cctab_begin:N.~This~command~will~be~ignored.
+  }
+\__kernel_msg_new:nnnn { kernel } { invalid-cctab }
+  { Invalid~\iow_char:N\\catcode:~table. }
+  {
+    You~can~only~switch~to~a~\iow_char:N\\catcode~table~that~is~
+    initialized~using~\iow_char:N\\cctab_new:N~or~
+    \iow_char:N\\cctab_const:Nn.
+  }
 %    \end{macrocode}
 %
 %    \begin{macrocode}
diff --git a/l3experimental/l3cctab/testfiles/m3cctab001.lvt b/l3experimental/l3cctab/testfiles/m3cctab001.lvt
index 90d7806cb..0bda22832 100644
--- a/l3experimental/l3cctab/testfiles/m3cctab001.lvt
+++ b/l3experimental/l3cctab/testfiles/m3cctab001.lvt
@@ -2,9 +2,9 @@
 \input{regression-test}
 
 \RequirePackage[enable-debug]{expl3}
-% \ExplSyntaxOn
-% \debug_on:n { check-declarations , deprecation }
-% \ExplSyntaxOff
+\ExplSyntaxOn
+\debug_on:n { check-declarations , deprecation }
+\ExplSyntaxOff
 
 \START
 \AUTHOR{Phelype Oleinik}
diff --git a/l3experimental/l3cctab/testfiles/m3cctab001.luatex.tlg b/l3experimental/l3cctab/testfiles/m3cctab002.luatex.tlg
similarity index 60%
copy from l3experimental/l3cctab/testfiles/m3cctab001.luatex.tlg
copy to l3experimental/l3cctab/testfiles/m3cctab002.luatex.tlg
index c6aabf0c4..1a5484ff1 100644
--- a/l3experimental/l3cctab/testfiles/m3cctab001.luatex.tlg
+++ b/l3experimental/l3cctab/testfiles/m3cctab002.luatex.tlg
@@ -12,22 +12,26 @@ Package: l3cctab ....-..-.. L3 Experimental category code tables
 \c_str_cctab=\catcodetable...
 )
 ============================================================
-TEST 1: cctab_begin/code in iniTeX
+TEST 1: Undefined cctab for \cctab_end:N 
 ============================================================
-OK
+! LaTeX3 Error: Control sequence \c_some_undefined_cctab undefined.
+For immediate help type H <return>.
+ ...                                              
+l. ...  { \cctab_begin:N \c_some_undefined_cctab }
+This is a coding error.
+LaTeX has been asked to use a control sequence '\c_some_undefined_cctab':
+this has not been defined yet.
 ============================================================
 ============================================================
-TEST 2: cctab_begin/iniTeX in code
+TEST 2: Another undefined cctab for \cctab_end:N 
 ============================================================
-OK
+! Invalid \catcode table.
+<recently read> \l_tmpa_int 
+l. ...  }
+You can only switch to a \catcode table that is initialized
+using \savecatcodetable or \initcatcodetable, or to table 0
 ============================================================
 ============================================================
-TEST 3: cctab_begin/str in document
+TEST 3: Extra \cctab_end: 
 ============================================================
-OK
-============================================================
-============================================================
-TEST 4: cctab_begin/document in str
-============================================================
-OK
 ============================================================
diff --git a/l3experimental/l3cctab/testfiles/m3cctab002.lvt b/l3experimental/l3cctab/testfiles/m3cctab002.lvt
new file mode 100644
index 000000000..90142aa90
--- /dev/null
+++ b/l3experimental/l3cctab/testfiles/m3cctab002.lvt
@@ -0,0 +1,29 @@
+\documentclass{minimal}
+\input{regression-test}
+
+\RequirePackage[enable-debug]{expl3}
+\ExplSyntaxOn
+\debug_on:n { check-declarations , deprecation }
+\ExplSyntaxOff
+
+\START
+\AUTHOR{Phelype Oleinik}
+\RequirePackage{l3cctab}
+
+\ExplSyntaxOn
+
+\TEST { Undefined~cctab~for~\cctab_end:N }
+  { \cctab_begin:N \c_some_undefined_cctab }
+
+\TEST { Another~undefined~cctab~for~\cctab_end:N }
+  {
+    \int_set:Nn \l_tmpa_int { 99 }
+    \cctab_begin:N \l_tmpa_int
+  }
+
+\TEST { Extra~\cctab_end: }
+  { \cctab_end: }
+
+\ExplSyntaxOff
+
+\END
diff --git a/l3experimental/l3cctab/testfiles/m3cctab002.tlg b/l3experimental/l3cctab/testfiles/m3cctab002.tlg
new file mode 100644
index 000000000..6e2ca8b9f
--- /dev/null
+++ b/l3experimental/l3cctab/testfiles/m3cctab002.tlg
@@ -0,0 +1,39 @@
+This is a generated file for the LaTeX (2e + expl3) validation system.
+Don't change this file in any respect.
+Author: Phelype Oleinik
+(l3cctab.sty
+Package: l3cctab ....-..-.. L3 Experimental category code tables
+\g__cctab_allocate_int=\count...
+\g__cctab_stack_int=\count...
+)
+============================================================
+TEST 1: Undefined cctab for \cctab_end:N 
+============================================================
+! LaTeX3 Error: Control sequence \c_some_undefined_cctab undefined.
+For immediate help type H <return>.
+ ...                                              
+l. ...  { \cctab_begin:N \c_some_undefined_cctab }
+This is a coding error.
+LaTeX has been asked to use a control sequence '\c_some_undefined_cctab':
+this has not been defined yet.
+============================================================
+============================================================
+TEST 2: Another undefined cctab for \cctab_end:N 
+============================================================
+! LaTeX3 Error: Invalid \catcode: table.
+For immediate help type H <return>.
+ ...                                              
+l. ...  }
+You can only switch to a \catcode table that is initialized using \cctab_new:N
+or \cctab_const:Nn.
+============================================================
+============================================================
+TEST 3: Extra \cctab_end: 
+============================================================
+! LaTeX3 Error: Extra \cctab_end: ignored on line ....
+For immediate help type H <return>.
+ ...                                              
+l. ...  { \cctab_end: }
+LaTeX came across a \cctab_end: without a matching \cctab_begin:N. This
+command will be ignored.
+============================================================





More information about the latex3-commits mailing list