hoxsl/test/node.xspec

385 lines
13 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!--
Tests node constructors
Copyright (C) 2015, 2016 Mike Gerwitz
This file is part of hoxsl.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<description xmlns="http://www.jenitennison.com/xslt/xspec"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:n="http://mikegerwitz.com/hoxsl/node"
xmlns:foo="http://mikegerwitz.com/_junk"
xmlns:test-prefix-a="test-ns-a"
stylesheet="../src/node.xsl">
<variable name="test-qname-a"
select="QName( 'test-ns-a', 'test-prefix-a:a' )" />
<variable name="test-qname-b"
select="QName( 'test-ns-b', 'test-prefix-b:b' )" />
<variable name="test-qname-c"
select="QName( 'test-ns-c', 'test-prefix-c:c' )" />
<variable name="test-qname-d"
select="QName( 'test-ns-d', 'test-prefix-d:d' )" />
<variable name="test-qname-e"
select="QName( 'test-ns-e', 'test-prefix-e:e' )" />
<variable name="test-qname-noprefix"
select="QName( 'test-ns-a', 'a' )" />
<variable name="test-node-element" as="element()">
<foo:node-a foo="bar">
<node-child />
</foo:node-a>
</variable>
<variable name="test-node-comment" as="comment()">
<!-- comment -->
</variable>
<!-- whitespace intentional -->
<variable name="test-text-a"
select="' This is some test text '" />
<variable name="test-text-b"
select="'Some more test text'" />
<variable name="test-value"
select="5" />
<!--
Primitives
-->
<scenario label="A new element">
<scenario label="with only a QName">
<call function="n:element">
<param name="qname" select="$test-qname-a" />
</call>
<expect label="produces an element"
test="$x:result instance of element()" />
<expect label="produces an element with the given QName"
test="node-name( $x:result ) = $test-qname-a" />
<expect label="produces an element with no attributes"
test="empty( $x:result/@* )" />
<expect label="produces an element with no children"
test="empty( $x:result/node() )" />
</scenario>
<scenario label="with a sequence of N attributes">
<call function="n:element">
<param name="qname" select="$test-qname-b" />
<param name="attrs"
select="( n:attr( $test-qname-a, 'a' ),
n:attr( $test-qname-c, 'c' ) )" />
</call>
<expect label="produces an element"
test="$x:result instance of element()" />
<expect label="produces an element with the given QName"
test="node-name( $x:result ) = $test-qname-b" />
<expect label="produces an element with no children"
test="empty( $x:result/node() )" />
<expect label="produces an element with N attributes"
test="count( $x:result/@* ) = 2" />
<expect label="produces an element with proper attribute QName/value"
test="( some $x in $x:result/@* satisfies
( node-name( $x ) = $test-qname-a
and $x = 'a' ) )
and ( some $x in $x:result/@* satisfies
( node-name( $x ) = $test-qname-c
and $x = 'c' ) )" />
</scenario>
<scenario label="with child nodes">
<call function="n:element">
<param name="qname" select="$test-qname-b" />
<param name="attrs" select="()" />
<param name="child-nodes"
select="$test-node-element,
$test-node-comment" />
</call>
<expect label="produces an element"
test="$x:result instance of element()" />
<expect label="produces an element with the given QName"
test="node-name( $x:result ) = $test-qname-b" />
<expect label="produces an element with N children"
test="count( $x:result/node() ) = 2" />
<expect label="includes exact child nodes"
test="( some $x in $x:result/node() satisfies
deep-equal( $x, $test-node-element ) )
and ( some $x in $x:result/node() satisfies
deep-equal( $x, $test-node-comment ) )" />
</scenario>
</scenario>
<scenario label="A new comment">
<scenario label="standalone">
<call function="n:comment">
<param name="text" select="$test-text-a" />
</call>
<expect label="produces a comment node"
test="$x:result instance of comment()" />
<expect label="contains given text verbatim"
test="$x:result = $test-text-a" />
</scenario>
<scenario label="within an element">
<call function="n:element">
<param name="name" select="QName( '', 'foo' )" />
<param name="attrs" select="()" />
<param name="child-nodes"
select="n:comment( $test-text-a ),
n:comment( $test-text-b )" />
</call>
<expect label="can be produced N times"
test="count( $x:result/comment() ) = 2" />
<expect label="results in no other child nodes"
test="count( $x:result/node() ) = 2" />
<expect label="contains given text verbatim, ordered"
test="$x:result/comment()[1] = $test-text-a
and $x:result/comment()[2] = $test-text-b" />
</scenario>
</scenario>
<scenario label="A new attribute">
<scenario label="with a value">
<!-- to test this, the attribute needs an element parent -->
<call function="n:element">
<param name="qname" select="$test-qname-a" />
<param name="attrs"
select="n:attr( $test-qname-b, 'foo' )" />
</call>
<expect label="has given QName"
test="node-name( $x:result/@* ) = $test-qname-b" />
<expect label="has given value"
test="$x:result/@* = 'foo'" />
</scenario>
<scenario label="with no value">
<!-- to test this, the attribute needs an element parent -->
<call function="n:element">
<param name="qname" select="$test-qname-a" />
<param name="attrs"
select="n:attr( $test-qname-c )" />
</call>
<expect label="has given QName"
test="node-name( $x:result/@* ) = $test-qname-c" />
<expect label="has empty value"
test="$x:result/@* = ''" />
</scenario>
</scenario>
<scenario label="A new text node">
<scenario label="standalone">
<call function="n:text">
<param name="text" select="$test-text-a" />
</call>
<expect label="produces a text node"
test="$x:result instance of text()" />
<expect label="contains given text verbatim"
test="$x:result = $test-text-a" />
</scenario>
<scenario label="adjacent to text within an element">
<call function="n:element">
<param name="name" select="QName( '', 'foo' )" />
<param name="attrs" select="()" />
<param name="child-nodes"
select="n:text( $test-text-a ),
n:text( $test-text-b )" />
</call>
<expect label="contains given text verbatim, ordered"
test="$x:result/text()[1] =
concat( $test-text-a, $test-text-b )" />
<!-- they're adjacent, and so combined into a single node -->
<expect label="results in no other child nodes"
test="count( $x:result/node() ) = 1" />
</scenario>
<scenario label="separated by other nodes within an element">
<call function="n:element">
<param name="name" select="QName( '', 'foo' )" />
<param name="attrs" select="()" />
<param name="child-nodes"
select="n:text( $test-text-a ),
$test-node-element,
n:text( $test-text-b )" />
</call>
<expect label="can produce N separate text nodes"
test="count( $x:result/text() ) = 2" />
<expect label="contains given text verbatim, ordered"
test="$x:result/text()[1] = $test-text-a
and $x:result/text()[2] = $test-text-b" />
<expect label="results in no other child nodes"
test="count( $x:result/node() ) = 3" />
</scenario>
</scenario>
<!--
Node Mutators
-->
<scenario label="Mutator">
<scenario label="n:add-attributes">
<variable name="element-attr-ns" as="element()"
select="n:element( $test-qname-a,
( n:attr( $test-qname-b, 'b' ),
n:attr( $test-qname-c, 'c' ) ),
( n:element( $test-qname-b ),
n:element( $test-qname-c ) ) )" />
<scenario label="with no new attributes">
<call function="n:add-attributes">
<param name="element" select="$element-attr-ns" />
<param name="attrs" select="()" />
</call>
<expect label="produces node with same QName"
test="node-name( $x:result ) = $test-qname-a" />
<expect label="retains all existing attributes"
test="deep-equal( $x:result/@*,
$element-attr-ns/@* )" />
<expect label="retains all existing children"
test="deep-equal( $x:result/node(),
$element-attr-ns/node() )" />
</scenario>
<scenario label="with all new attributes">
<call function="n:add-attributes">
<param name="element" select="$element-attr-ns" />
<param name="attrs"
select="( n:attr( $test-qname-d, 'd' ),
n:attr( $test-qname-e, 'e' ) )" />
</call>
<expect label="produces node with same QName"
test="node-name( $x:result ) = $test-qname-a" />
<expect label="adds new attributes"
test="( some $x in $x:result/@* satisfies
( node-name( $x ) = $test-qname-d
and $x = 'd' ) )
and ( some $x in $x:result/@* satisfies
( node-name( $x ) = $test-qname-e
and $x = 'e' ) )" />
<expect label="retains all existing attributes"
test="( some $x in $x:result/@* satisfies
( node-name( $x ) = $test-qname-b
and $x = 'b' ) )
and ( some $x in $x:result/@* satisfies
( node-name( $x ) = $test-qname-c
and $x = 'c' ) )" />
<!-- less than check will allow this to succeed even if an above
test fails so that we can accurately determine the problem-->
<expect label="does not add any other attributes"
test="count( $x:result/@* ) &lt;= 4" />
<expect label="retains all existing children"
test="deep-equal( $x:result/node(),
$element-attr-ns/node() )" />
</scenario>
<scenario label="with some duplicate attributes">
<call function="n:add-attributes">
<param name="element" select="$element-attr-ns" />
<param name="attrs"
select="( n:attr( $test-qname-c, 'c2' ),
n:attr( $test-qname-d, 'd2' ) )" />
</call>
<expect label="produces node with same QName"
test="node-name( $x:result ) = $test-qname-a" />
<expect label="adds new attributes"
test="( some $x in $x:result/@* satisfies
( node-name( $x ) = $test-qname-d
and $x = 'd2' ) )" />
<expect label="replaces existing attributes"
test="( some $x in $x:result/@* satisfies
( node-name( $x ) = $test-qname-c
and $x = 'c2' ) )" />
<expect label="retains all existing attributes"
test="( some $x in $x:result/@* satisfies
( node-name( $x ) = $test-qname-b
and $x = 'b' ) )" />
<!-- less than check will allow this to succeed even if an above
test fails so that we can accurately determine the problem-->
<expect label="does not add any other attributes"
test="count( $x:result/@* ) &lt;= 3" />
<expect label="retains all existing children"
test="deep-equal( $x:result/node(),
$element-attr-ns/node() )" />
</scenario>
</scenario>
</scenario>
</description>