-
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 files for "XQuery Makeover to Improve Testability with XSpec" (#…
…45)
- Loading branch information
Showing
7 changed files
with
124 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,18 @@ | ||
# Sample Code for "XQuery Makeover to Improve Testability with XSpec" | ||
|
||
Example files before refactoring: | ||
|
||
- `main.xqm` | ||
- `data.xml` | ||
|
||
Example files after refactoring: | ||
|
||
- `main-refactored.xqm` | ||
- `library.xqm` | ||
- `library.xspec` | ||
- `data.xml` | ||
|
||
|
||
#### Link to Topic | ||
|
||
[XQuery Makeover to Improve Testability with XSpec](https://medium.com/@xspectacles/xquery-makeover-to-improve-testability-with-xspec-dfd36432c3c7) |
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,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<root> | ||
<num>6789</num> | ||
<num>12345</num> | ||
<num>1000</num> | ||
<num>200</num> | ||
</root> |
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,19 @@ | ||
(: | ||
Sample code for "XQuery Makeover to Improve Testability with XSpec" section | ||
https://medium.com/@xspectacles/xquery-makeover-to-improve-testability-with-xspec-dfd36432c3c7 | ||
:) | ||
|
||
xquery version "3.1"; | ||
module namespace f = "urn:x-xspec-book:functions:xquery-modules"; | ||
declare decimal-format spaced grouping-separator = " "; | ||
|
||
declare function f:filter-round( | ||
$context as document-node(), | ||
$min as xs:integer | ||
) as xs:string* { | ||
for $n in $context//num/number()[. ge $min] | ||
return | ||
format-number($n, '### ###', 'spaced') | ||
}; | ||
|
||
(: Copyright © 2024 by Amanda Galtman. :) |
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<x:description xmlns:f="urn:x-xspec-book:functions:xquery-modules" | ||
xmlns:x="http://www.jenitennison.com/xslt/xspec" | ||
query="urn:x-xspec-book:functions:xquery-modules" | ||
query-at="library.xqm"> | ||
<!-- | ||
Sample code for "XQuery Makeover to Improve Testability with XSpec" section | ||
https://medium.com/@xspectacles/xquery-makeover-to-improve-testability-with-xspec-dfd36432c3c7 | ||
--> | ||
|
||
<x:scenario label="Test 'f:filter-round' function"> | ||
<x:call function="f:filter-round"> | ||
<x:param select="/"> | ||
<root> | ||
<num>1000</num> | ||
<num>5000</num> | ||
<num>500</num> | ||
<num>2000.75</num> | ||
</root> | ||
</x:param> | ||
<x:param>1000</x:param> | ||
</x:call> | ||
<x:expect label="Numbers at least 1000, in expected format" | ||
select="('1 000', '5 000', '2 001')"/> | ||
</x:scenario> | ||
</x:description> | ||
<!-- Copyright © 2024 by Amanda Galtman. --> |
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,25 @@ | ||
(: | ||
Sample code for "XQuery Makeover to Improve Testability with XSpec" section | ||
https://medium.com/@xspectacles/xquery-makeover-to-improve-testability-with-xspec-dfd36432c3c7 | ||
:) | ||
|
||
xquery version "3.1"; | ||
import module namespace f = "urn:x-xspec-book:functions:xquery-modules" | ||
at "library.xqm"; | ||
declare namespace output = | ||
"http://www.w3.org/2010/xslt-xquery-serialization"; | ||
declare context item as document-node() external := document { | ||
<root> | ||
<num>1000</num> | ||
<num>5000</num> | ||
<num>500</num> | ||
<num>2000.75</num> | ||
</root> | ||
}; | ||
declare variable $min as xs:integer external := 1000; | ||
declare option output:method "text"; | ||
|
||
(: Query body :) | ||
f:filter-round(., $min) | ||
|
||
(: Copyright © 2024 by Amanda Galtman. :) |
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,26 @@ | ||
(: | ||
Sample code for "XQuery Makeover to Improve Testability with XSpec" section | ||
https://medium.com/@xspectacles/xquery-makeover-to-improve-testability-with-xspec-dfd36432c3c7 | ||
:) | ||
|
||
xquery version "3.1"; | ||
declare namespace output = | ||
"http://www.w3.org/2010/xslt-xquery-serialization"; | ||
declare decimal-format spaced grouping-separator = " "; | ||
declare context item as document-node() external := document { | ||
<root> | ||
<num>1000</num> | ||
<num>5000</num> | ||
<num>500</num> | ||
<num>2000.75</num> | ||
</root> | ||
}; | ||
declare variable $min as xs:integer external := 1000; | ||
declare option output:method "text"; | ||
|
||
(: Query body :) | ||
for $n in //num/number()[. ge $min] | ||
return | ||
format-number($n, '### ###', 'spaced') | ||
|
||
(: Copyright © 2024 by Amanda Galtman. :) |