From d787837840a1b2c20c54bb42b4fe0ca5e294443d Mon Sep 17 00:00:00 2001
From: Amanda Galtman <40716346+galtm@users.noreply.github.com>
Date: Tue, 9 Jul 2024 15:34:15 -0400
Subject: [PATCH] Sample files for "XQuery Makeover to Improve Testability with
XSpec" (#45)
---
README.md | 3 ++-
src/xquery-modules/README.md | 18 +++++++++++++++++
src/xquery-modules/data.xml | 7 +++++++
src/xquery-modules/library.xqm | 19 ++++++++++++++++++
src/xquery-modules/library.xspec | 27 ++++++++++++++++++++++++++
src/xquery-modules/main-refactored.xqm | 25 ++++++++++++++++++++++++
src/xquery-modules/main.xqm | 26 +++++++++++++++++++++++++
7 files changed, 124 insertions(+), 1 deletion(-)
create mode 100644 src/xquery-modules/README.md
create mode 100644 src/xquery-modules/data.xml
create mode 100644 src/xquery-modules/library.xqm
create mode 100644 src/xquery-modules/library.xspec
create mode 100644 src/xquery-modules/main-refactored.xqm
create mode 100644 src/xquery-modules/main.xqm
diff --git a/README.md b/README.md
index 482d6b1..987a9be 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ Each post corresponds to a [subfolder under `src/`](https://github.com/galtm/xsp
* [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)
-* **(NEW!)** [How to Test Error Handling in XSpec](https://github.com/galtm/xspectacles/tree/main/src/catch-error)
+* [How to Test Error Handling in XSpec](https://github.com/galtm/xspectacles/tree/main/src/catch-error)
* [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)
@@ -32,3 +32,4 @@ 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)
+* **(NEW!)** [XQuery Makeover to Improve Testability with XSpec](https://github.com/galtm/xspectacles/tree/main/src/xquery-modules)
\ No newline at end of file
diff --git a/src/xquery-modules/README.md b/src/xquery-modules/README.md
new file mode 100644
index 0000000..e17abda
--- /dev/null
+++ b/src/xquery-modules/README.md
@@ -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)
diff --git a/src/xquery-modules/data.xml b/src/xquery-modules/data.xml
new file mode 100644
index 0000000..c70da5f
--- /dev/null
+++ b/src/xquery-modules/data.xml
@@ -0,0 +1,7 @@
+
+
+ 6789
+ 12345
+ 1000
+ 200
+
diff --git a/src/xquery-modules/library.xqm b/src/xquery-modules/library.xqm
new file mode 100644
index 0000000..1767711
--- /dev/null
+++ b/src/xquery-modules/library.xqm
@@ -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. :)
diff --git a/src/xquery-modules/library.xspec b/src/xquery-modules/library.xspec
new file mode 100644
index 0000000..e521ffb
--- /dev/null
+++ b/src/xquery-modules/library.xspec
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+ 1000
+ 5000
+ 500
+ 2000.75
+
+
+ 1000
+
+
+
+
+
diff --git a/src/xquery-modules/main-refactored.xqm b/src/xquery-modules/main-refactored.xqm
new file mode 100644
index 0000000..f7bfc2a
--- /dev/null
+++ b/src/xquery-modules/main-refactored.xqm
@@ -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 {
+
+ 1000
+ 5000
+ 500
+ 2000.75
+
+};
+declare variable $min as xs:integer external := 1000;
+declare option output:method "text";
+
+(: Query body :)
+f:filter-round(., $min)
+
+(: Copyright © 2024 by Amanda Galtman. :)
diff --git a/src/xquery-modules/main.xqm b/src/xquery-modules/main.xqm
new file mode 100644
index 0000000..0962271
--- /dev/null
+++ b/src/xquery-modules/main.xqm
@@ -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 {
+
+ 1000
+ 5000
+ 500
+ 2000.75
+
+};
+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. :)