Skip to content

Commit

Permalink
Sample files for "Text Nodes and Locations in XSpec Tests for Schemat…
Browse files Browse the repository at this point in the history
…ron" (#42)
  • Loading branch information
galtm authored May 29, 2024
1 parent c97d698 commit 7558730
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Each post corresponds to a [subfolder under `src/`](https://github.com/galtm/xsp
* [But the Diffs Look the Same](https://github.com/galtm/xspectacles/tree/main/src/identical-diffs)
* [Code Reuse at the File Level in XSpec](https://github.com/galtm/xspectacles/tree/main/src/code-reuse-file-level)
* [Code Reuse in XSpec: How to Use x:like](https://github.com/galtm/xspectacles/tree/main/src/code-reuse)
* **(NEW!)** [Comparing Attributes Selectively in XSpec 3.0](https://github.com/galtm/xspectacles/tree/main/src/three-dots-attrs)
* [Comparing Attributes Selectively in XSpec 3.0](https://github.com/galtm/xspectacles/tree/main/src/three-dots-attrs)
* [Content Outside the Selection in XSpec](https://github.com/galtm/xspectacles/tree/main/src/out-of-scope)
* [Fixing Surprise Spaces in XSpec Actual Result](https://github.com/galtm/xspectacles/tree/main/src/space-actual)
* [Inheritance as a Form of Reuse in XSpec](https://github.com/galtm/xspectacles/tree/main/src/code-reuse-call)
Expand All @@ -24,8 +24,9 @@ Each post corresponds to a [subfolder under `src/`](https://github.com/galtm/xsp
* [Testing an XPath Function Library with XSpec 3.0](https://github.com/galtm/xspectacles/tree/main/src/xpath-function-library)
* [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)
* [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 Messages with XSpec 3.0](https://github.com/galtm/xspectacles/tree/main/src/schematron-messages)
* [Testing Schematron Patterns in Isolation](https://github.com/galtm/xspectacles/tree/main/src/isolated-patterns)
* **(NEW!)** [Text Nodes and Locations in XSpec Tests for Schematron](https://github.com/galtm/xspectacles/tree/main/src/schxslt-in-xspec)
* [The Equality Check that's Neither True Nor False](https://github.com/galtm/xspectacles/tree/main/src/non-boolean-eq)
* [Ways to Access XSLT Result in XSpec Testing: Dot Versus Result Variable](https://github.com/galtm/xspectacles/tree/main/src/dot-versus-result)
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<excludes>
<!-- Exclude tests that fail deliberately. -->
<exclude>pending/pending-error-xq.xspec</exclude>
<exclude>schxslt-in-xspec/schxslt-in-xspec-mistakes.xspec</exclude>
<exclude>space-actual/problem/space-actual-problem.xspec</exclude>
<exclude>space-actual/problem-variation/space-actual-problem.xspec</exclude>
</excludes>
Expand Down
11 changes: 11 additions & 0 deletions src/schxslt-in-xspec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Sample code for "Text Nodes and Locations in XSpec Tests for Schematron"

Example files:

* `schxslt-in-xspec.sch`
* `schxslt-in-xspec.xspec`
* `schxslt-in-xspec-mistakes.xspec`
* `document.xml`

#### Link to Topic
[Text Nodes and Locations in XSpec Tests for Schematron](https://medium.com/@xspectacles/text-nodes-and-locations-in-xspec-tests-for-schematron-2174e7c943b3)
8 changes: 8 additions & 0 deletions src/schxslt-in-xspec/document.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<topic>
<info>
<title>Schematron for Text Nodes</title>
</info>
<para xml:id="para-1"> Paragraph one</para>
<para xml:id="para-2"><phrase>Paragraph</phrase> two</para>
</topic>
45 changes: 45 additions & 0 deletions src/schxslt-in-xspec/schxslt-in-xspec-mistakes.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
schematron="schxslt-in-xspec.sch"
version="3.0"
xmlns:x="http://www.jenitennison.com/xslt/xspec">

<!--
Sample code for "Text Nodes and Locations in XSpec Tests for Schematron"
https://medium.com/@xspectacles/text-nodes-and-locations-in-xspec-tests-for-schematron-2174e7c943b3
-->

<x:scenario label="Mistake in location attribute">
<x:context href="document.xml"/>
<x:pending label="Errors">
<x:expect-not-assert id="sp"
location="//para[@xml:id='para2']/text()"/>
<x:expect-not-assert id="sp"
location="//para/text()"/>
</x:pending>

<!-- Troubleshooting -->
<x:expect test="$x:context">
<x:label>What is in the document?</x:label>
placeholder
</x:expect>
<x:expect test="$x:context//para[@xml:id='para2']/text()">
<x:label>What does location attribute find at
//para[@xml:id='para2']/text() ? </x:label>
placeholder
</x:expect>
<x:expect test="$x:context//para/text()">
<x:label>What does location attribute find at
//para/text() ? </x:label>
placeholder
</x:expect>
</x:scenario>

<x:scenario label="Fix for mistake in location attribute">
<x:context href="document.xml"/>
<x:expect-not-assert id="sp"
location="//para[@xml:id='para-2']/text()"/>
</x:scenario>
</x:description>

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

<!--
Sample code for "Text Nodes and Locations in XSpec Tests for Schematron"
https://medium.com/@xspectacles/text-nodes-and-locations-in-xspec-tests-for-schematron-2174e7c943b3
-->

<sch:pattern>
<sch:rule context="para/node()[1]/self::text()">
<sch:assert test="not(starts-with(., ' '))" id="sp"
>Paragraph must start with a word, not a space.</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>

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

<!--
Sample code for "Text Nodes and Locations in XSpec Tests for Schematron"
https://medium.com/@xspectacles/text-nodes-and-locations-in-xspec-tests-for-schematron-2174e7c943b3
-->

<x:scenario label="Paragraph starting with space">
<x:context href="document.xml"/>
<x:expect-assert id="sp"/>
<x:expect-assert id="sp"
location="//para[@xml:id='para-1']/text()"/>
<x:expect-assert id="sp"
location="topic/para[@xml:id='para-1']/text()"/>
<x:expect-assert id="sp"
location="$x:context//para[@xml:id='para-1']/text()"/>
</x:scenario>

<!-- See schxslt-in-xspec-mistakes.xspec for tips
on troubleshooting mistakes in location attribute. -->

<x:scenario label="Fix for mistake in location attribute">
<x:context href="document.xml"/>
<x:expect-not-assert id="sp"
location="//para[@xml:id='para-2']/text()"/>
</x:scenario>
</x:description>

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

0 comments on commit 7558730

Please sign in to comment.