Skip to content

Commit

Permalink
Sample code for "Testing Schematron Messages with XSpec 3.0" (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
galtm authored Apr 10, 2024
1 parent 1553a32 commit 6802d5e
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ Each post corresponds to a [subfolder under `src/`](https://github.com/galtm/xsp
* [Multiple Cases in One XSpec Scenario](https://github.com/galtm/xspectacles/tree/main/src/context-sequence)
* [One-or-More Ways to Foil Empty-Sequence Surprises in XSpec](https://github.com/galtm/xspectacles/tree/main/src/one-or-more)
* [Saying "Almost Valid" or "Beyond Valid" in XSpec Tests for Schematron](https://github.com/galtm/xspectacles/tree/main/src/almost-valid)
* **(NEW!)** [Saying "Not Yet" in XSpec](https://github.com/galtm/xspectacles/tree/main/src/pending)
* [Saying "Not Yet" in XSpec](https://github.com/galtm/xspectacles/tree/main/src/pending)
* [Saying "Whatever" in XSpec: How, Why, When](https://github.com/galtm/xspectacles/tree/main/src/three-dots)
* [Testing a Thin-Wrapper XSLT Template Without Excessive Repetition](https://github.com/galtm/xspectacles/tree/main/src/similar-code-wrapper)
* [Testing Boolean-Valued Functions: An XSpec Blooper with Easy Fixes](https://github.com/galtm/xspectacles/tree/main/src/boolean-fcn)
* [Testing Explicit Whitespace in XSpec](https://github.com/galtm/xspectacles/tree/main/src/space-explicit)
* **(NEW!)** [Testing Schematron Messages with XSpec 3.0](https://github.com/galtm/xspectacles/tree/main/src/schematron-messages)
* [Testing Preformatted or Codelike Text in XSpec](https://github.com/galtm/xspectacles/tree/main/src/space-preformatted)
* [Testing Schematron Patterns in Isolation](https://github.com/galtm/xspectacles/tree/main/src/isolated-patterns)
* [The Equality Check that's Neither True Nor False](https://github.com/galtm/xspectacles/tree/main/src/non-boolean-eq)
Expand Down
20 changes: 20 additions & 0 deletions src/schematron-messages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Sample code for "Testing Schematron Messages with XSpec 3.0"

Primary example files:

* `schematron-messages.sch`
* `schematron-messages.xspec`
* `schematron-messages.xml`

"Verifying Report Messages":

* `schematron-messages-report.sch`
* `schematron-messages-report.xspec`

"Verifying Diagnostic Messages":

* `schematron-messages-with-diag.sch`
* `schematron-messages-with-diag.xspec`

#### Link to Topic
[Testing Schematron Messages with XSpec 3.0](https://medium.com/@xspectacles/testing-schematron-messages-with-xspec-3-0-1adc9be69a4d)
23 changes: 23 additions & 0 deletions src/schematron-messages/schematron-messages-report.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">

<!--
Sample code for "Testing Schematron Messages with XSpec 3.0"
https://medium.com/@xspectacles/testing-schematron-messages-with-xspec-3-0-1adc9be69a4d
-->

<!-- "Verifying Report Messages" -->
<sch:pattern>
<sch:rule context="section/section/info">
<sch:let name="top-section-title"
value="ancestor::section[last()]/title"/>
<sch:report test="true()" id="subsection-no-info">
Subsection must not contain info. Move children to
"<sch:value-of select="$top-section-title"/>" info.
</sch:report>
</sch:rule>
</sch:pattern>

</sch:schema>

<!-- Copyright © 2024 by Amanda Galtman. -->
27 changes: 27 additions & 0 deletions src/schematron-messages/schematron-messages-report.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
schematron="schematron-messages-report.sch"
xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
xmlns:x="http://www.jenitennison.com/xslt/xspec"
version="3.0">

<!--
Sample code for "Testing Schematron Messages with XSpec 3.0"
https://medium.com/@xspectacles/testing-schematron-messages-with-xspec-3-0-1adc9be69a4d
-->

<!-- This test requires XSpec 3.0 -->

<!-- "Verifying Report Messages" -->
<x:scenario label="Subsection with info element">
<x:context href="schematron-messages.xml"/>
<x:expect-report
id="subsection-no-info">
Subsection must not contain info.
Move children to "Top-Level Section" info.
</x:expect-report>
</x:scenario>

</x:description>

<!-- Copyright © 2024 by Amanda Galtman. -->
30 changes: 30 additions & 0 deletions src/schematron-messages/schematron-messages-with-diag.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">

<!--
Sample code for "Testing Schematron Messages with XSpec 3.0"
https://medium.com/@xspectacles/testing-schematron-messages-with-xspec-3-0-1adc9be69a4d
-->

<!-- "Defining Diagnostic Messages" -->

<sch:pattern>
<sch:rule context="section/section/info">
<sch:let name="top-section-title"
value="ancestor::section[last()]/title"/>
<sch:assert test="false()" id="subsection-no-info"
diagnostics="guideline-1-2">
Subsection must not contain info. Move children to
"<sch:value-of select="$top-section-title"/>" info.
</sch:assert>
</sch:rule>
</sch:pattern>

<sch:diagnostics>
<sch:diagnostic id="guideline-1-2">[WG 1.2]</sch:diagnostic>
<sch:diagnostic id="guideline-1-3">[WG 1.3]</sch:diagnostic>
<!-- More diagnostic definitions can go here -->
</sch:diagnostics>
</sch:schema>

<!-- Copyright © 2024 by Amanda Galtman. -->
29 changes: 29 additions & 0 deletions src/schematron-messages/schematron-messages-with-diag.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
schematron="schematron-messages-with-diag.sch"
xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
xmlns:x="http://www.jenitennison.com/xslt/xspec"
version="3.0">

<!--
Sample code for "Testing Schematron Messages with XSpec 3.0"
https://medium.com/@xspectacles/testing-schematron-messages-with-xspec-3-0-1adc9be69a4d
-->

<!-- This test requires XSpec 3.0 -->

<!-- "Verifying Diagnostic Messages" -->
<x:scenario label="Subsection with info element">
<x:context href="schematron-messages.xml"/>
<x:expect-assert
id="subsection-no-info">
Subsection must not contain info.
Move children to "Top-Level Section" info.
</x:expect-assert>
<x:expect-assert label="Check diagnostic:"
id="subsection-no-info">[WG 1.2] q</x:expect-assert>
</x:scenario>

</x:description>

<!-- Copyright © 2024 by Amanda Galtman. -->
22 changes: 22 additions & 0 deletions src/schematron-messages/schematron-messages.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">

<!--
Sample code for "Testing Schematron Messages with XSpec 3.0"
https://medium.com/@xspectacles/testing-schematron-messages-with-xspec-3-0-1adc9be69a4d
-->

<sch:pattern>
<sch:rule context="section/section/info">
<sch:let name="top-section-title"
value="ancestor::section[last()]/title"/>
<sch:assert test="false()" id="subsection-no-info">
Subsection must not contain info. Move children to
"<sch:value-of select="$top-section-title"/>" info.
</sch:assert>
</sch:rule>
</sch:pattern>

</sch:schema>

<!-- Copyright © 2024 by Amanda Galtman. -->
15 changes: 15 additions & 0 deletions src/schematron-messages/schematron-messages.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="schematron-messages.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<section xml:id="top-section">
<title>Top-Level Section</title>
<info xml:id="top-info"><!-- metadata belongs here --></info>
<para>Introductory content</para>
<section>
<title>Subsection</title>
<info>
<authorinitials>TSE</authorinitials>
</info>
<para>Subsection content</para>
</section>
</section>
<!-- Copyright © 2024 by Amanda Galtman. -->
26 changes: 26 additions & 0 deletions src/schematron-messages/schematron-messages.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
schematron="schematron-messages.sch"
xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
xmlns:x="http://www.jenitennison.com/xslt/xspec"
version="3.0">

<!--
Sample code for "Testing Schematron Messages with XSpec 3.0"
https://medium.com/@xspectacles/testing-schematron-messages-with-xspec-3-0-1adc9be69a4d
-->

<!-- This test requires XSpec 3.0 -->

<x:scenario label="Subsection with info element">
<x:context href="schematron-messages.xml"/>
<x:expect-assert
id="subsection-no-info">
Subsection must not contain info.
Move children to "Top-Level Section" info.
</x:expect-assert>
</x:scenario>

</x:description>

<!-- Copyright © 2024 by Amanda Galtman. -->

0 comments on commit 6802d5e

Please sign in to comment.