Skip to content

Commit

Permalink
[MOD] rules and unit tests in support of abstract pattern parameters,…
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSales committed Mar 17, 2024
1 parent f612212 commit 8e62512
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
32 changes: 19 additions & 13 deletions schematron.sch
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ THIS SCHEMA HAS BEEN MODIFIED FROM THE SCHEMA DEFINED IN ISO/IEC 19757 3,
AND SHOULD NOT BE INTERPRETED AS COMPLYING WITH THAT STANDARD."
-->

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" xml:lang="en" queryBinding="xslt2">
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" xml:lang="en" queryBinding="xslt2"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name='abstract-pattern' match='sch:pattern[@abstract="true"]' use='@id'/>
<sch:title>Schema for Additional Constraints in Schematron</sch:title>
<sch:ns prefix="sch" uri="http://purl.oclc.org/dsdl/schematron"/>
<sch:p>This schema supplies some constraints in addition to those given in the
Expand All @@ -33,18 +35,6 @@ AND SHOULD NOT BE INTERPRETED AS COMPLYING WITH THAT STANDARD."
attribute of the active element shall match the id
attribute of a pattern.</sch:assert>
</sch:rule>
<sch:rule context="sch:pattern[@is-a]">
<sch:assert test="//sch:pattern[@abstract='true'][@id=current()/@is-a]" id="abstract-patterns"> The
is-a attribute of a pattern element shall match
the id attribute of an abstract pattern.
</sch:assert>
<sch:assert test="every $name in current()/sch:param/@name
satisfies $name eq //sch:pattern[@abstract='true'][@id=current()/@is-a]/sch:param/@name" id="param-names-match"> The
name attribute of a pattern param element shall match
the id attribute of an abstract pattern param element.
</sch:assert>
<sch:assert test="TODO: missing param value"></sch:assert>
</sch:rule>
<sch:rule context="sch:extends">
<sch:assert test="//sch:rule[@abstract='true'][@id=current()/@rule]" id="abstract-rules"> The rule
attribute of an extends element shall match the id
Expand All @@ -64,4 +54,20 @@ AND SHOULD NOT BE INTERPRETED AS COMPLYING WITH THAT STANDARD."
id="param-name">A parameter name should not use the same name as a parameter in the same scope.</sch:assert>
</sch:rule>
</sch:pattern>
<sch:pattern>
<sch:rule context="sch:pattern[@is-a]">
<sch:assert test="key('abstract-pattern', @is-a)" id="abstract-patterns"> The
is-a attribute of a pattern element shall match
the id attribute of an abstract pattern.
</sch:assert>
<sch:assert test="every $name in current()/sch:param/@name
satisfies $name eq key('abstract-pattern', @is-a)/sch:param/@name" id="param-names-match"> The
name attribute of a pattern param element shall match
the id attribute of an abstract pattern param element.
</sch:assert>
</sch:rule>
<sch:rule context="sch:pattern[@is-a]/sch:param">
<sch:assert test="@value or key('abstract-pattern', ../@is-a)/sch:param/@value" id="missing-param-value">A pattern parameter value shall be specified.</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
37 changes: 36 additions & 1 deletion schematron.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@
<pattern id='p7' is-a='bar'>
<param name="blort"/>
</pattern>
<pattern id='p8' abstract='true'>
<!-- abstract pattern param contains default value -->
<param name="jam" value='spam'/>
</pattern>
<pattern id='p9' is-a='p8'>
<!-- concrete pattern param missing; use default from abstract -->
<param name="jam"/>
</pattern>
<pattern id='p10' is-a='p8'>
<!-- concrete pattern param overrides default value -->
<param name="jam" value='clam'/>
</pattern>
<pattern id="p11" abstract='true'>
<!-- abstract pattern param has no default value -->
<param name="sham"/>
</pattern>
<pattern id='p12' is-a='p11'>
<!-- concrete pattern param specifies value -->
<param name="sham" value='shazam'/>
</pattern>
</schema></x:context>

<x:scenario label="active pattern references">
Expand Down Expand Up @@ -88,7 +108,7 @@
location="/sch:schema/sch:pattern[@id='bar']/sch:param[1]"/>
</x:scenario>

<!-- not-assert version of previous, with no duplicate schema params -->
<!-- not-assert version of previous scenario, with no duplicate schema params -->
<x:scenario label="schema param dupe name">
<x:context><sch:schema>
<sch:param name='pram1'/>
Expand All @@ -107,5 +127,20 @@
id="param-names-match"
location="/sch:schema/sch:pattern[@id='p7']"/>
</x:scenario>

<x:scenario label="pattern param value must be present">
<x:expect-assert label="param value not present on concrete or abstract pattern params"
id="missing-param-value"
location="/sch:schema/sch:pattern[@id='p7']/sch:param"/>
<x:expect-not-assert label="param value defaults to abstract pattern param"
id="missing-param-value"
location="/sch:schema/sch:pattern[@id='p9']/sch:param"/>
<x:expect-not-assert label="concrete pattern param value overrides abstract pattern default param value"
id="missing-param-value"
location="/sch:schema/sch:pattern[@id='p10']/sch:param"/>
<x:expect-not-assert label="concrete pattern param specifies value (no abstract pattern param default)"
id="missing-param-value"
location="/sch:schema/sch:pattern[@id='p12']/sch:param"/>
</x:scenario>
</x:scenario>
</x:description>

0 comments on commit 8e62512

Please sign in to comment.