hoxsl/test/record.xspec

303 lines
11 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!--
Tests records
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:R="http://mikegerwitz.com/hoxsl/record"
xmlns:foo="http://mikegerwitz.com/_junk"
stylesheet="../src/record.xsl">
<variable name="test-qname"
select="QName( 'http://mikegerwitz.com/_junk',
'foo:test-qname' )" />
<variable name="test-qname-2"
select="QName( 'http://mikegerwitz.com/_junk',
'foo:test-qname-2' )" />
<variable name="test-qname-3"
select="QName( 'http://mikegerwitz.com/_junk',
'foo:test-qname-3' )" />
<variable name="slot-ns" as="xs:anyURI"
select="resolve-uri( 'http://mikegerwitz.com/_junk/slot' )" />
<variable name="sa" as="xs:QName"
select="QName( $slot-ns, 'a' )" />
<variable name="sb" as="xs:QName"
select="QName( $slot-ns, 'b' )" />
<variable name="sc" as="xs:QName"
select="QName( $slot-ns, 'c' )" />
<variable name="sd" as="xs:QName"
select="QName( $slot-ns, 'd' )" />
<scenario label="R:make-record-header">
<scenario label="with no supertype">
<call function="R:make-record-header">
<param name="qname" select="$test-qname" />
<param name="slots" select="3" />
</call>
<expect label="produces an R:Record element"
test="$x:result instance of element( R:Record )" />
<expect label="R:Record type matches the generic R:Record"
test="R:is-a( $R:qname, $x:result )" />
<expect label="R:Record type matches given QName"
test="R:is-a( $test-qname, $x:result )" />
<expect label="R:Record type does not match other QName"
test="not( R:is-a( $test-qname-2, $x:result ) )" />
<expect label="R:Record element contains number of slots"
test="R:slot-count( $x:result ) = 3" />
</scenario>
<scenario label="with a supertype">
<scenario label="produces">
<call function="R:make-record-header">
<param name="qname" select="$test-qname" />
<param name="slots" select="3" />
<param name="supertype"
select="R:make-record-header( $test-qname-2, 2 )" />
</call>
<expect label="produces an R:Record element"
test="$x:result instance of element( R:Record )" />
<expect label="R:Record type matches given QName"
test="R:is-a( $test-qname, $x:result )" />
<expect label="R:Record type matches supertype QName"
test="R:is-a( $test-qname-2, $x:result )" />
<expect label="R:Record type matches the generic R:Record"
test="R:is-a( $R:qname, $x:result )" />
<expect label="R:Record type does not match other QName"
test="not( R:is-a( QName( '', 'foo' ), $x:result ) )" />
</scenario>
<scenario label="with slot count greater than that of supertype">
<call function="R:make-record-header">
<param name="qname" select="$test-qname" />
<param name="slots" select="3" />
<param name="supertype"
select="R:make-record-header( $test-qname-2, 2 )" />
</call>
<expect label="R:Record element contains given number of slots"
test="R:slot-count( $x:result ) = 3" />
</scenario>
<scenario label="with slot count equal to that of supertype">
<call function="R:make-record-header">
<param name="qname" select="$test-qname" />
<param name="slots" select="2" />
<param name="supertype"
select="R:make-record-header( $test-qname-2, 2 )" />
</call>
<expect label="R:Record element contains given number of slots"
test="R:slot-count( $x:result ) = 2" />
</scenario>
<scenario label="with slot count less than that of supertype">
<call function="R:make-record-header">
<param name="qname" select="$test-qname" />
<param name="slots" select="1" />
<param name="supertype"
select="R:make-record-header( $test-qname-2, 2 )" />
</call>
<expect label="R:Record element contains supertype slot count"
test="R:slot-count( $x:result ) = 2" />
</scenario>
</scenario>
<!-- arbitrary nesting of supertypes -->
<scenario label="with a super-supertype">
<scenario label="produces">
<call function="R:make-record-header">
<param name="qname" select="$test-qname" />
<param name="slots" select="3" />
<param name="supertype"
select="R:make-record-header(
$test-qname-2,
2,
R:make-record-header( $test-qname-3, 2 ))" />
</call>
<expect label="produces an R:Record element"
test="$x:result instance of element( R:Record )" />
<expect label="R:Record type matches given QName"
test="R:is-a( $test-qname, $x:result )" />
<expect label="R:Record type matches supertype QName"
test="R:is-a( $test-qname-2, $x:result )" />
<expect label="R:Record type matches super-supertype QName"
test="R:is-a( $test-qname-3, $x:result )" />
<expect label="R:Record type matches the generic R:Record"
test="R:is-a( $R:qname, $x:result )" />
<expect label="R:Record type does not match other QName"
test="not( R:is-a( QName( '', 'foo' ), $x:result ) )" />
</scenario>
</scenario>
</scenario>
<scenario label="R:name-slots">
<scenario label="not having been invoked on a record">
<call function="R:make-record-header">
<param name="qname" select="$test-qname" />
<param name="slots" select="3" />
</call>
<expect label="produces no named slots"
test="empty( R:slot-names( $x:result, $slot-ns ) )" />
</scenario>
<scenario label="with no names">
<call function="R:name-slots">
<param name="Record"
select="R:make-record-header( $test-qname, 3 )" />
<param name="names" select="()" />
</call>
<expect label="retains slot count"
test="R:slot-count( $x:result ) = 3" />
<expect label="produces no named slots"
test="empty( R:slot-names( $x:result, $slot-ns ) )" />
</scenario>
<scenario label="with names less than slot count">
<call function="R:name-slots">
<param name="Record"
select="R:make-record-header( $test-qname, 3 )" />
<param name="names" select="( $sa, $sb )" />
</call>
<expect label="retains slot count"
test="R:slot-count( $x:result ) = 3" />
<expect label="produces given named slots"
test="deep-equal( R:slot-names( $x:result, $slot-ns ),
( n:attr( $sa, 1 ),
n:attr( $sb, 2 ) ) )" />
</scenario>
<scenario label="with names greater than slot count N">
<call function="R:name-slots">
<param name="Record"
select="R:make-record-header( $test-qname, 3 )" />
<param name="names" select="( $sa, $sb, $sc, $sd )" />
</call>
<expect label="retains slot count"
test="R:slot-count( $x:result ) = 3" />
<expect label="produces only first N slot names"
test="deep-equal( R:slot-names( $x:result, $slot-ns ),
( n:attr( $sa, 1 ),
n:attr( $sb, 2 ),
n:attr( $sc, 3 ) ) )" />
</scenario>
<scenario label="invoked multiple times">
<!-- need to use a node to assert on attributes -->
<call function="n:element">
<param name="qname" select="$test-qname" />
<param name="attrs"
select="R:slot-names(
R:name-slots(
R:name-slots(
R:make-record-header( $test-qname, 3 ),
( $sa, $sb ) ),
( $sd, $sc, $sb ) ),
$slot-ns)" />
</call>
<expect label="overwrites slots names already specified"
test="count( $x:result/@* ) = 4
and ( every $x in $x:result/@* satisfies
deep-equal( $x, n:attr( $sd, 1 ) )
or deep-equal( $x, n:attr( $sa, 1 ) )
or deep-equal( $x, n:attr( $sc, 2 ) )
or deep-equal( $x, n:attr( $sb, 3 ) ) )" />
</scenario>
</scenario>
<scenario label="R:is-compatible">
<scenario label="with super- and sub-types of same slot count">
<call function="R:is-compatible">
<param name="A" select="R:make-record-header( $test-qname, 2 )" />
<param name="B" select="R:make-record-header( $test-qname-2, 2 )" />
</call>
<expect label="yields true()"
test="$x:result = true()" />
</scenario>
<scenario label="with subtype slot count greater than supertype">
<call function="R:is-compatible">
<param name="sub"
select="R:make-record-header( $test-qname, 2 )" />
<param name="super"
select="R:make-record-header( $test-qname-2, 1 )" />
</call>
<expect label="yields true()"
test="$x:result = true()" />
</scenario>
<scenario label="with subtype slot count less than supertype">
<call function="R:is-compatible">
<param name="sub"
select="R:make-record-header( $test-qname, 1 )" />
<param name="super"
select="R:make-record-header( $test-qname-2, 2 )" />
</call>
<expect label="yields false()"
test="$x:result = false()" />
</scenario>
</scenario>
</description>