Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample code for "Interpreting XML Diffs in XSpec Test Reports" #60

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ Each post corresponds to a [subfolder under `src/`](https://github.com/galtm/xsp
* [How to Test Error Handling in XSpec](https://github.com/galtm/xspectacles/tree/main/src/catch-error)
* [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)
* **(NEW!)** [Interpreting XML Diffs in XSpec Test Reports](https://github.com/galtm/xspectacles/tree/main/src/diff-colors)
* [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)
* [Overriding Global XSLT Variables in XSpec, Part 1](https://github.com/galtm/xspectacles/tree/main/src/override-global-var-part1)
* [Overriding Global XSLT Variables in XSpec, Part 2](https://github.com/galtm/xspectacles/tree/main/src/override-global-var-part2)
* **(NEW!)** [Overriding Global XSLT Variables in XSpec, Part 3](https://github.com/galtm/xspectacles/tree/main/src/override-global-var-part3)
* [Overriding Global XSLT Variables in XSpec, Part 3](https://github.com/galtm/xspectacles/tree/main/src/override-global-var-part3)
* [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)
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<testDir>${project.basedir}/src</testDir>
<excludes>
<!-- Exclude tests that fail deliberately. -->
<exclude>diff-colors/diff-colors.xspec</exclude>
<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>
Expand Down
9 changes: 9 additions & 0 deletions src/diff-colors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Sample code for "Interpreting XML Diffs in XSpec Test Reports"

Example files:

* `diff-colors.xqm`
* `diff-colors.xspec`

#### Link to Topic
[Interpreting XML Diffs in XSpec Test Reports](https://medium.com/@xspectacles/interpreting-xml-diffs-in-xspec-test-reports-ce37358ac2bd)
32 changes: 32 additions & 0 deletions src/diff-colors/diff-colors.xqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
xquery version "1.0";
module namespace mf = "urn:x-xspectacles:functions:diff-colors";

(:
Sample Code for "Interpreting XML Diffs in XSpec Test Reports"
https://medium.com/@xspectacles/interpreting-xml-diffs-in-xspec-test-reports-ce37358ac2bd
:)

declare function mf:make-doc() as document-node(element(doc)) {
document{
<doc>
<section class="sect1">
<title class="heading">Elements</title>
<para>Alpha</para>
<para>Beta</para>
</section>
<section class="sect1">
<title class="heading">Text</title>
<para>Some text</para>
<para>More text</para>
</section>
<section class="sect1">
<title class="heading">Attributes</title>
<para id="p1">First</para>
<para>Second</para>
<para id="p3">Third</para>
</section>
</doc>
}
};

(: Copyright © 2025 by Amanda Galtman. :)
38 changes: 38 additions & 0 deletions src/diff-colors/diff-colors.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description query="urn:x-xspectacles:functions:diff-colors"
query-at="diff-colors.xqm" xquery-version="1.0"
xmlns:x="http://www.jenitennison.com/xslt/xspec">

<!--
Sample Code for "Interpreting XML Diffs in XSpec Test Reports"
https://medium.com/@xspectacles/interpreting-xml-diffs-in-xspec-test-reports-ce37358ac2bd
-->

<x:scenario label="Deliberate failure to illustrate diffs in report">
<x:call function="mf:make-doc"
xmlns:mf="urn:x-xspectacles:functions:diff-colors"/>
<x:expect label="Document">
<doc>
<section class="sect1">
<title class="heading">Elements</title>
<para>Alpha</para>
<remark>Beta</remark>
<para>Gamma</para>
</section>
<section class="sect1">
<title class="heading">Text</title>
<para>Some text</para>
<para>More interesting text</para>
</section>
<section class="sect1">
<title class="heading">Attributes</title>
<para>First</para>
<para id="p2">Second</para>
<para id="p33">Third</para>
</section>
</doc>
</x:expect>
</x:scenario>
</x:description>

<!-- Copyright © 2025 by Amanda Galtman. -->
Loading