Skip to content

Commit

Permalink
Sample code for "XQuery Update Facility Can Simplify XSpec Test Helpe…
Browse files Browse the repository at this point in the history
…r Functions" (#53)
  • Loading branch information
galtm authored Oct 30, 2024
1 parent 56900e8 commit ffff6df
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Each post corresponds to a [subfolder under `src/`](https://github.com/galtm/xsp
* [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)
* [How to Test Error Handling in XSpec](https://github.com/galtm/xspectacles/tree/main/src/catch-error)
* **(NEW!)** [Ignoring Code Comments During XSpec Testing](https://github.com/galtm/xspectacles/tree/main/src/helper-comments)
* [Ignoring Code Comments During XSpec Testing](https://github.com/galtm/xspectacles/tree/main/src/helper-comments)
* [Inheritance as a Form of Reuse in XSpec](https://github.com/galtm/xspectacles/tree/main/src/code-reuse-call)
* [Multiple Cases in One XSpec Scenario](https://github.com/galtm/xspectacles/tree/main/src/context-sequence)
* [My XML Content in XSpec Causes an Error](https://github.com/galtm/xspectacles/tree/main/src/xml-content-error)
* [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)
* [Saying "Almost Valid" or "Beyond Valid" in XSpec Tests for Schematron](https://github.com/galtm/xspectacles/tree/main/src/almost-valid)
* [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 RELAX NG Schema Using XSpec](https://github.com/galtm/xspectacles/tree/main/src/relaxng)
Expand All @@ -37,4 +37,5 @@ Each post corresponds to a [subfolder under `src/`](https://github.com/galtm/xsp
* [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)
* [XQuery Makeover to Improve Testability with XSpec](https://github.com/galtm/xspectacles/tree/main/src/xquery-modules)
* [XQuery Makeover to Improve Testability with XSpec](https://github.com/galtm/xspectacles/tree/main/src/xquery-modules)
* **(NEW!)** [XQuery Update Facility Can Simplify XSpec Test Helper Functions](https://github.com/galtm/xspectacles/tree/main/src/helper-comments-xquf)
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<exclude>ixml/ixml-design1.xspec</exclude>
<exclude>ixml/ixml-design2.xspec</exclude>
<exclude>relaxng/relaxng-test.xspec</exclude>
<exclude>helper-comments-xquf/helper-remove-comments-xquf.xspec</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
12 changes: 12 additions & 0 deletions src/helper-comments-xquf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Sample code for "XQuery Update Facility Can Simplify XSpec Test Helper Functions"

Example files for XQuery, including dependencies from ../helper-comments folder:

- `helper-remove-comments-xquf.xqm`
- `helper-remove-comments-xquf.xspec`
- `../helper-comments/test-target.xqm`
- `../helper-comments/helper-remove-comments-xslt.xspec`


#### Links to Topic
[XQuery Update Facility Can Simplify XSpec Test Helper Functions](https://medium.com/@xspectacles/xquery-update-facility-can-simplify-xspec-test-helper-functions-803a7b362002)
33 changes: 33 additions & 0 deletions src/helper-comments-xquf/helper-remove-comments-xquf.xqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
xquery version "3.1";
module namespace frc = "urn:x-xspectacles:functions:helper:remove-comments:xquf";

(:
Sample Code for "XQuery Update Facility Can Simplify XSpec Test Helper Functions"
https://medium.com/@xspectacles/xquery-update-facility-can-simplify-xspec-test-helper-functions-803a7b362002
:)

(:
This helper file requires the XQuery processor to support the
copy modify expression in XQuery Update Facility 1.0. Processors
with such support include:
* BaseX
* Saxon-EE with XQuery Update explicitly enabled (-update:on)
:)
declare variable $frc:prefix as xs:string := 'TEST NOTE:';

(:
Remove certain comments from $node, assumed to be an element or
document node. The comments to remove are those whose
space-normalized content starts with 'TEST NOTE:'.
:)
declare function frc:remove-comments(
$node as node()
) {
copy $node-copy := $node
modify delete node $node-copy//comment()
[starts-with(normalize-space(.), $frc:prefix)]
return
$node-copy
};

(: Copyright © 2024 by Amanda Galtman. :)
20 changes: 20 additions & 0 deletions src/helper-comments-xquf/helper-remove-comments-xquf.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description query="urn:x-xspectacles:functions:report"
query-at="../helper-comments/test-target.xqm"
xmlns:frc="urn:x-xspectacles:functions:helper:remove-comments:xquf"
xmlns:rpt="urn:x-xspectacles:functions:report"
xmlns:x="http://www.jenitennison.com/xslt/xspec">

<!--
Sample Code for "XQuery Update Facility Can Simplify XSpec Test Helper Functions"
https://medium.com/@xspectacles/xquery-update-facility-can-simplify-xspec-test-helper-functions-803a7b362002
-->

<x:helper
query="urn:x-xspectacles:functions:helper:remove-comments:xquf"
query-at="helper-remove-comments-xquf.xqm"/>

<x:import href="../helper-comments/helper-remove-comments-xslt.xspec"/>

</x:description>
<!-- Copyright © 2024 by Amanda Galtman. -->

0 comments on commit ffff6df

Please sign in to comment.