From 3d5c4d7edaaafb287a45a33c75acb8984e76126c Mon Sep 17 00:00:00 2001 From: Ulrike Fischer Date: Mon, 19 Feb 2024 14:32:01 +0100 Subject: [PATCH] test existence of props, latex3/latex3#1455 --- CHANGELOG.md | 1 + tagpdf-checks.dtx | 5 +- tagpdf-roles.dtx | 106 ++++++----- testfiles-pdftex/test-get_role-20.lvt | 6 +- testfiles-pdftex/test-get_role-20.tlg | 243 ++------------------------ 5 files changed, 85 insertions(+), 276 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58c7547b..37ef0b27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ this project uses date-based 'snapshot' version identifiers. ### Fixed - missing slashes in dvilualatex backend, issue #96 - lua error with large object numbers, issue #97 + - existence tests for unknown props (issue latex3/latex3#1455) ### Changed - speed gain by using linked properties diff --git a/tagpdf-checks.dtx b/tagpdf-checks.dtx index c95b9d8b..48a3b632 100644 --- a/tagpdf-checks.dtx +++ b/tagpdf-checks.dtx @@ -306,7 +306,7 @@ % Message if an attribute i sunknown. % \end{function} % -% \begin{function}{role-missing,role-unknown,role-unknown-tag,role-tag,new-tag, +% \begin{function}{role-missing,role-unknown,role-unknown-tag,role-unknown-NS,role-tag,new-tag, % role-parent-child,role-remapping} % Messages related to role mapping. % \end{function} @@ -500,12 +500,13 @@ % \end{macro} % % \subsection{Roles} -% \begin{macro}{role-missing,role-unknown,role-unknown-tag} +% \begin{macro}{role-missing,role-unknown,role-unknown-tag,role-unknown-NS} % Warning message if either the tag or the role is missing % \begin{macrocode} \msg_new:nnn { tag } {role-missing} { tag~#1~has~no~role~assigned } \msg_new:nnn { tag } {role-unknown} { role~#1~is~not~known } \msg_new:nnn { tag } {role-unknown-tag} { tag~#1~is~not~known } +\msg_new:nnn { tag } {role-unknown-NS} { \tl_if_empty:nTF{#1}{Empty~NS}{NS~#1~is~not~known} } % \end{macrocode} % \end{macro} % \begin{macro}{role-parent-child} diff --git a/tagpdf-roles.dtx b/tagpdf-roles.dtx index 47a1f40b..9b4b9c1e 100644 --- a/tagpdf-roles.dtx +++ b/tagpdf-roles.dtx @@ -505,11 +505,16 @@ { \msg_info:nnn { tag }{new-tag}{#1} } - \prop_get:cnN { g_@@_role_NS_#4_class_prop } {#3}\l_@@_tmpa_tl - \quark_if_no_value:NT \l_@@_tmpa_tl - { - \tl_set:Nn\l_@@_tmpa_tl{--UNKNOWN--} - } + \prop_if_exist:cTF + { g_@@_role_NS_#4_class_prop } + { + \prop_get:cnN { g_@@_role_NS_#4_class_prop } {#3}\l_@@_tmpa_tl + \quark_if_no_value:NT \l_@@_tmpa_tl + { + \tl_set:Nn\l_@@_tmpa_tl{--UNKNOWN--} + } + } + { \tl_set:Nn\l_@@_tmpa_tl{--UNKNOWN--} } \@@_role_alloctag:nnV {#1}{#2}\l_@@_tmpa_tl % \end{macrocode} % Do not remap standard tags. TODO add warning? @@ -579,15 +584,24 @@ %#3 tlvar which hold the role tag %#4 tlvar which hold the name of the target NS { - \prop_get:cnNTF {g_@@_role_NS_#2_prop} {#1}\l_@@_tmpa_tl - { - \tl_set:Ne #3 {\exp_last_unbraced:NV\use_i:nn \l_@@_tmpa_tl} - \tl_set:Ne #4 {\exp_last_unbraced:NV\use_ii:nn \l_@@_tmpa_tl} - } - { - \tl_set:Nn #3 {#1} - \tl_set:Nn #4 {#2} - } + \prop_if_exist:cTF {g_@@_role_NS_#2_prop} + { + \prop_get:cnNTF {g_@@_role_NS_#2_prop} {#1}\l_@@_tmpa_tl + { + \tl_set:Ne #3 {\exp_last_unbraced:NV\use_i:nn \l_@@_tmpa_tl} + \tl_set:Ne #4 {\exp_last_unbraced:NV\use_ii:nn \l_@@_tmpa_tl} + } + { + \msg_warning:nnn { tag } {role-unknown-tag} { #1 } + \tl_set:Nn #3 {#1} + \tl_set:Nn #4 {#2} + } + } + { + \msg_warning:nnn { tag } {role-unknown-NS} { #2 } + \tl_set:Nn #3 {#1} + \tl_set:Nn #4 {#2} + } } \cs_generate_variant:Nn \@@_role_get:nnNN {VVNN} } @@ -1106,20 +1120,27 @@ \tl_set:Nn \l_@@_tmpa_tl {#1} } { - \prop_get:cnNTF - { g_@@_role_NS_#2_prop } - {#1} - \l_@@_tmpa_tl - { - \tl_set:Ne \l_@@_tmpa_tl {\tl_head:N\l_@@_tmpa_tl} - \tl_if_empty:NT\l_@@_tmpa_tl - { - \tl_set:Nn \l_@@_tmpa_tl {#1} - } - } - { - \tl_set:Nn \l_@@_tmpa_tl {\q_no_value} - } + \prop_if_exist:cTF { g_@@_role_NS_#2_prop } + { + \prop_get:cnNTF + { g_@@_role_NS_#2_prop } + {#1} + \l_@@_tmpa_tl + { + \tl_set:Ne \l_@@_tmpa_tl {\tl_head:N\l_@@_tmpa_tl} + \tl_if_empty:NT\l_@@_tmpa_tl + { + \tl_set:Nn \l_@@_tmpa_tl {#1} + } + } + { + \tl_set:Nn \l_@@_tmpa_tl {\q_no_value} + } + } + { + \msg_warning:nnn { tag } {role-unknown-NS} { #2} + \tl_set:Nn \l_@@_tmpa_tl {\q_no_value} + } } % \end{macrocode} % and the same for the child @@ -1131,20 +1152,27 @@ \tl_set:Nn \l_@@_tmpb_tl {#3} } { - \prop_get:cnNTF - { g_@@_role_NS_#4_prop } - {#3} - \l_@@_tmpb_tl + \prop_if_exist:cTF { g_@@_role_NS_#4_prop } { - \tl_set:Ne \l_@@_tmpb_tl { \tl_head:N\l_@@_tmpb_tl } - \tl_if_empty:NT\l_@@_tmpb_tl - { - \tl_set:Nn \l_@@_tmpb_tl {#3} - } + \prop_get:cnNTF + { g_@@_role_NS_#4_prop } + {#3} + \l_@@_tmpb_tl + { + \tl_set:Ne \l_@@_tmpb_tl { \tl_head:N\l_@@_tmpb_tl } + \tl_if_empty:NT\l_@@_tmpb_tl + { + \tl_set:Nn \l_@@_tmpb_tl {#3} + } + } + { + \tl_set:Nn \l_@@_tmpb_tl {\q_no_value} + } } - { + { + \msg_warning:nnn { tag } {role-unknown-NS} { #4} \tl_set:Nn \l_@@_tmpb_tl {\q_no_value} - } + } } % \end{macrocode} % and now get the relation diff --git a/testfiles-pdftex/test-get_role-20.lvt b/testfiles-pdftex/test-get_role-20.lvt index 0be84a51..4b51bae2 100644 --- a/testfiles-pdftex/test-get_role-20.lvt +++ b/testfiles-pdftex/test-get_role-20.lvt @@ -29,15 +29,15 @@ xxx \tl_show:N \l_tmpa_tl\tl_show:N \l_tmpb_tl } -\TEST{get~standard~role:~Sect} +\TEST{get~standard~role:~Sect,~unknown~NS} { \__tag_role_get:nnNN {Sect}{xxx}\l_tmpa_tl\l_tmpb_tl \tl_show:N \l_tmpa_tl\tl_show:N \l_tmpb_tl } -\TEST{get~standard~role:~Aside} +\TEST{get~standard~role:~Aside,~empty~NS} { - \__tag_role_get:nnNN {Aside}{xxx}\l_tmpa_tl\l_tmpb_tl + \__tag_role_get:nnNN {Aside}{}\l_tmpa_tl\l_tmpb_tl \tl_show:N \l_tmpa_tl\tl_show:N \l_tmpb_tl } \ExplSyntaxOff diff --git a/testfiles-pdftex/test-get_role-20.tlg b/testfiles-pdftex/test-get_role-20.tlg index e22f85b0..7e0fe3af 100644 --- a/testfiles-pdftex/test-get_role-20.tlg +++ b/testfiles-pdftex/test-get_role-20.tlg @@ -17,91 +17,18 @@ l. ... } ============================================================ TEST 3: get known role title, unknown name space ============================================================ -! Use of \__prop_get_linked:w doesn't match its definition. - \g__tag_role_NS_blub_prop -l. ... } -If you say, e.g., `\def\a1{...}', then you must always -put `1' after `\a', since control sequence names are -made up of letters only. The macro here has not been -followed by the required stuff, so I'm ignoring it. -! Argument of \tl_set:Nn has an extra }. - - \par -l. ... } -I've run across a `}' that doesn't seem to match anything. -For example, `\def\a#1{...}' and `\a}' would produce -this error. If you simply proceed now, the `\par' that -I've just inserted will cause me to report a runaway -argument that might be the root of the problem. But if -your `}' was spurious, just type `2' and it will go away. -Runaway argument? -! Paragraph ended before \tl_set:Nn was complete. - - \par -l. ... } -I suspect you've forgotten a `}', causing me to apply this -control sequence to too much text. How can we recover? -My plan is to forget the whole thing and hope for the best. -! Missing number, treated as zero. - - } -l. ... } -A number should have been here; I inserted `0'. -(If you can't figure out why I needed to see a number, -look up `weird error' in the index to The TeXbook.) -! Argument of \use_i:nn has an extra }. - - \par -l. ... } -I've run across a `}' that doesn't seem to match anything. -For example, `\def\a#1{...}' and `\a}' would produce -this error. If you simply proceed now, the `\par' that -I've just inserted will cause me to report a runaway -argument that might be the root of the problem. But if -your `}' was spurious, just type `2' and it will go away. -Runaway argument? -! Paragraph ended before \use_i:nn was complete. - - \par -l. ... } -I suspect you've forgotten a `}', causing me to apply this -control sequence to too much text. How can we recover? -My plan is to forget the whole thing and hope for the best. -! Missing number, treated as zero. - - } -l. ... } -A number should have been here; I inserted `0'. -(If you can't figure out why I needed to see a number, -look up `weird error' in the index to The TeXbook.) -! Argument of \use_ii:nn has an extra }. - - \par -l. ... } -I've run across a `}' that doesn't seem to match anything. -For example, `\def\a#1{...}' and `\a}' would produce -this error. If you simply proceed now, the `\par' that -I've just inserted will cause me to report a runaway -argument that might be the root of the problem. But if -your `}' was spurious, just type `2' and it will go away. -Runaway argument? -! Paragraph ended before \use_ii:nn was complete. - - \par -l. ... } -I suspect you've forgotten a `}', causing me to apply this -control sequence to too much text. How can we recover? -My plan is to forget the whole thing and hope for the best. -> \l_tmpa_tl={Span}{pdf}. +Package tagpdf Warning: NS blub is not known +> \l_tmpa_tl=title. } l. ... } -> \l_tmpb_tl=. +> \l_tmpb_tl=blub. } l. ... } ============================================================ ============================================================ TEST 4: get unknown role: blub ============================================================ +Package tagpdf Warning: tag blub is not known > \l_tmpa_tl=blub. } l. ... } @@ -110,169 +37,21 @@ l. ... } l. ... } ============================================================ ============================================================ -TEST 5: get standard role: Sect +TEST 5: get standard role: Sect, unknown NS ============================================================ -! Use of \__prop_get_linked:w doesn't match its definition. - \g__tag_role_NS_xxx_prop -l. ... } -If you say, e.g., `\def\a1{...}', then you must always -put `1' after `\a', since control sequence names are -made up of letters only. The macro here has not been -followed by the required stuff, so I'm ignoring it. -! Argument of \tl_set:Nn has an extra }. - - \par -l. ... } -I've run across a `}' that doesn't seem to match anything. -For example, `\def\a#1{...}' and `\a}' would produce -this error. If you simply proceed now, the `\par' that -I've just inserted will cause me to report a runaway -argument that might be the root of the problem. But if -your `}' was spurious, just type `2' and it will go away. -Runaway argument? -! Paragraph ended before \tl_set:Nn was complete. - - \par -l. ... } -I suspect you've forgotten a `}', causing me to apply this -control sequence to too much text. How can we recover? -My plan is to forget the whole thing and hope for the best. -! Missing number, treated as zero. - - } -l. ... } -A number should have been here; I inserted `0'. -(If you can't figure out why I needed to see a number, -look up `weird error' in the index to The TeXbook.) -! Argument of \use_i:nn has an extra }. - - \par -l. ... } -I've run across a `}' that doesn't seem to match anything. -For example, `\def\a#1{...}' and `\a}' would produce -this error. If you simply proceed now, the `\par' that -I've just inserted will cause me to report a runaway -argument that might be the root of the problem. But if -your `}' was spurious, just type `2' and it will go away. -Runaway argument? -! Paragraph ended before \use_i:nn was complete. - - \par -l. ... } -I suspect you've forgotten a `}', causing me to apply this -control sequence to too much text. How can we recover? -My plan is to forget the whole thing and hope for the best. -! Missing number, treated as zero. - - } -l. ... } -A number should have been here; I inserted `0'. -(If you can't figure out why I needed to see a number, -look up `weird error' in the index to The TeXbook.) -! Argument of \use_ii:nn has an extra }. - - \par -l. ... } -I've run across a `}' that doesn't seem to match anything. -For example, `\def\a#1{...}' and `\a}' would produce -this error. If you simply proceed now, the `\par' that -I've just inserted will cause me to report a runaway -argument that might be the root of the problem. But if -your `}' was spurious, just type `2' and it will go away. -Runaway argument? -! Paragraph ended before \use_ii:nn was complete. - - \par -l. ... } -I suspect you've forgotten a `}', causing me to apply this -control sequence to too much text. How can we recover? -My plan is to forget the whole thing and hope for the best. -> \l_tmpa_tl={Span}{pdf}. +Package tagpdf Warning: NS xxx is not known +> \l_tmpa_tl=Sect. } l. ... } -> \l_tmpb_tl=. +> \l_tmpb_tl=xxx. } l. ... } ============================================================ ============================================================ -TEST 6: get standard role: Aside +TEST 6: get standard role: Aside, empty NS ============================================================ -! Use of \__prop_get_linked:w doesn't match its definition. - \g__tag_role_NS_xxx_prop -l. ... } -If you say, e.g., `\def\a1{...}', then you must always -put `1' after `\a', since control sequence names are -made up of letters only. The macro here has not been -followed by the required stuff, so I'm ignoring it. -! Argument of \tl_set:Nn has an extra }. - - \par -l. ... } -I've run across a `}' that doesn't seem to match anything. -For example, `\def\a#1{...}' and `\a}' would produce -this error. If you simply proceed now, the `\par' that -I've just inserted will cause me to report a runaway -argument that might be the root of the problem. But if -your `}' was spurious, just type `2' and it will go away. -Runaway argument? -! Paragraph ended before \tl_set:Nn was complete. - - \par -l. ... } -I suspect you've forgotten a `}', causing me to apply this -control sequence to too much text. How can we recover? -My plan is to forget the whole thing and hope for the best. -! Missing number, treated as zero. - - } -l. ... } -A number should have been here; I inserted `0'. -(If you can't figure out why I needed to see a number, -look up `weird error' in the index to The TeXbook.) -! Argument of \use_i:nn has an extra }. - - \par -l. ... } -I've run across a `}' that doesn't seem to match anything. -For example, `\def\a#1{...}' and `\a}' would produce -this error. If you simply proceed now, the `\par' that -I've just inserted will cause me to report a runaway -argument that might be the root of the problem. But if -your `}' was spurious, just type `2' and it will go away. -Runaway argument? -! Paragraph ended before \use_i:nn was complete. - - \par -l. ... } -I suspect you've forgotten a `}', causing me to apply this -control sequence to too much text. How can we recover? -My plan is to forget the whole thing and hope for the best. -! Missing number, treated as zero. - - } -l. ... } -A number should have been here; I inserted `0'. -(If you can't figure out why I needed to see a number, -look up `weird error' in the index to The TeXbook.) -! Argument of \use_ii:nn has an extra }. - - \par -l. ... } -I've run across a `}' that doesn't seem to match anything. -For example, `\def\a#1{...}' and `\a}' would produce -this error. If you simply proceed now, the `\par' that -I've just inserted will cause me to report a runaway -argument that might be the root of the problem. But if -your `}' was spurious, just type `2' and it will go away. -Runaway argument? -! Paragraph ended before \use_ii:nn was complete. - - \par -l. ... } -I suspect you've forgotten a `}', causing me to apply this -control sequence to too much text. How can we recover? -My plan is to forget the whole thing and hope for the best. -> \l_tmpa_tl={Span}{pdf}. +Package tagpdf Warning: Empty NS +> \l_tmpa_tl=Aside. } l. ... } > \l_tmpb_tl=.