-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sample code for "Testing an XPath Function Library with XSpec 3.0"
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Sample code for "Testing an XPath Function Library with XSpec 3.0" | ||
|
||
Example files: | ||
|
||
* `SimpleLibraryAsMap.xpath` | ||
* `test-for-xpath-function-library.xspec` | ||
|
||
#### Link to Topic | ||
[Testing an XPath Function Library with XSpec 3.0](https://medium.com/@xspectacles/testing-an-xpath-function-library-with-xspec-3-0-1f324b0837cb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
xquery version "3.1"; | ||
module namespace SL = "urn:x-xspectacles:functions:simple-library"; | ||
|
||
declare variable $SL:vMath as map(*) := | ||
let | ||
$incr := function($n as xs:integer) | ||
{$n +1}, | ||
$mult := function($m as xs:integer, $n as xs:integer) | ||
{$m * $n}, | ||
$decr := function($n as xs:integer) | ||
{$n -1}, | ||
$idiv := function($m as xs:integer, $n as xs:integer) | ||
{$m idiv $n} | ||
|
||
(: Provide the function library as a map :) | ||
return | ||
map { | ||
'incr' : $incr, | ||
'mult' : $mult, | ||
'decr' : $decr, | ||
'idiv' : $idiv | ||
} | ||
; | ||
|
||
(: | ||
This code is adapted from the following paper, with the module | ||
namespace declaration and variable declaration added as the | ||
paper suggests. | ||
|
||
Novatchev, Dimitre. “Programming in XPath 3.0.” Presented at Balisage: The Markup Conference 2013, | ||
Montréal, Canada, August 6 - 9, 2013. In Proceedings of Balisage: The Markup Conference 2013. | ||
Balisage Series on Markup Technologies, vol. 10 (2013). https://doi.org/10.4242/BalisageVol10.Novatchev01. | ||
:) |
47 changes: 47 additions & 0 deletions
47
src/xpath-function-library/test-for-xpath-function-library.xspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<x:description | ||
query="urn:x-xspectacles:functions:simple-library" | ||
query-at="SimpleLibraryAsMap.xpath" | ||
xmlns:x="http://www.jenitennison.com/xslt/xspec" | ||
xmlns:SL="urn:x-xspectacles:functions:simple-library"> | ||
|
||
<!-- | ||
Sample Code for "Testing an XPath Function Library with XSpec 3.0" | ||
https://medium.com/@xspectacles/testing-an-xpath-function-library-with-xspec-3-0-1f324b0837cb | ||
--> | ||
|
||
<x:scenario label="incr function"> | ||
<x:call function="SL:vMath" call-as="variable"> | ||
<x:param select="'incr'"/> | ||
</x:call> | ||
<x:expect label="$x:result is a function with one integer parameter" | ||
test="$x:result instance of function(xs:integer) as item()*"/> | ||
<x:expect label="Incrementing 4 produces 5" | ||
test="$x:result(4)" | ||
select="5"/> | ||
<x:scenario label="Alternative syntax, less useful in case of failure"> | ||
<x:expect label="Incrementing 4 produces 5" | ||
test="$x:result(4) eq 5"/> | ||
</x:scenario> | ||
</x:scenario> | ||
<x:scenario label="mult function"> | ||
<x:call function="SL:vMath" call-as="variable"> | ||
<x:param select="'mult'"/> | ||
</x:call> | ||
<x:expect label="$x:result is a function with two integer parameters" | ||
test="$x:result instance of function(xs:integer, xs:integer) as item()*"/> | ||
<x:expect label="4 times 2 equals 8" | ||
test="$x:result(4,2)" | ||
select="8"/> | ||
</x:scenario> | ||
|
||
<x:scenario label="Incorrect syntax" pending="Error"> | ||
<x:call function="SL:vMath('incr')" call-as="variable"> | ||
<x:param select="4"/> | ||
</x:call> | ||
<x:expect label="Incrementing 4 produces 5" | ||
select="5"/> | ||
</x:scenario> | ||
</x:description> | ||
|
||
<!-- Copyright © 2024 by Amanda Galtman. --> |