2014-11-21 09:15:24 -05:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<!--
|
|
|
|
Tests dynamic function application
|
|
|
|
|
|
|
|
Copyright (C) 2014 LoVullo Associates, Inc.
|
|
|
|
|
|
|
|
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"
|
2014-11-21 15:00:47 -05:00
|
|
|
xmlns:f="http://www.lovullo.com/hoxsl/apply"
|
2014-11-21 09:15:24 -05:00
|
|
|
xmlns:foo="http://www.lovullo.com/_junk"
|
|
|
|
stylesheet="apply-test.xsl">
|
|
|
|
|
2014-11-26 15:35:35 -05:00
|
|
|
<variable name="foo-uri"
|
|
|
|
select="namespace-uri-for-prefix( 'foo', $args )" />
|
|
|
|
|
2014-11-26 11:16:24 -05:00
|
|
|
<variable name="args">
|
|
|
|
<foo:args>
|
|
|
|
<foo:arg1 />
|
|
|
|
<foo:arg2 />
|
|
|
|
<foo:arg3 />
|
|
|
|
<foo:arg4 />
|
|
|
|
<foo:arg5 />
|
|
|
|
<foo:arg6 />
|
|
|
|
<foo:arg7 />
|
|
|
|
<foo:arg8 />
|
|
|
|
</foo:args>
|
|
|
|
</variable>
|
2014-11-21 09:15:24 -05:00
|
|
|
|
2014-11-26 11:16:24 -05:00
|
|
|
<scenario label="f:apply">
|
|
|
|
<scenario label="applied to complete argument list of">
|
2014-11-21 09:15:24 -05:00
|
|
|
<scenario label="nullary function">
|
|
|
|
<call function="f:apply">
|
2014-11-24 11:07:25 -05:00
|
|
|
<param name="fnref">
|
|
|
|
<f:ref><foo:fn0 /></f:ref>
|
|
|
|
</param>
|
2014-11-21 09:15:24 -05:00
|
|
|
</call>
|
|
|
|
|
2014-11-26 11:16:24 -05:00
|
|
|
<!-- technically it applies a template -->
|
|
|
|
<expect label="applies target function"
|
2014-11-26 23:43:56 -05:00
|
|
|
test="$x:result[ 1 ] = foo:applied[ @n = 0 ]" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="unary function">
|
|
|
|
<call function="f:apply">
|
2014-11-24 11:07:25 -05:00
|
|
|
<param name="fnref">
|
|
|
|
<f:ref><foo:fn1 /></f:ref>
|
|
|
|
</param>
|
2014-11-26 11:16:24 -05:00
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="passes each argument"
|
2014-11-26 11:16:24 -05:00
|
|
|
test="$x:result[ 1 ] = foo:applied[ @n = 1 ]
|
|
|
|
and $x:result[ 2 ] is $args/foo:arg1" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="binary function">
|
|
|
|
<call function="f:apply">
|
2014-11-24 11:07:25 -05:00
|
|
|
<param name="fnref">
|
|
|
|
<f:ref><foo:fn2 /></f:ref>
|
|
|
|
</param>
|
2014-11-26 11:16:24 -05:00
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
|
|
|
<param name="arg2" select="$args/foo:arg2" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="passes each argument"
|
2014-11-26 11:16:24 -05:00
|
|
|
test="$x:result[ 1 ] = foo:applied[ @n = 2 ]
|
|
|
|
and $x:result[ 2 ] is $args/foo:arg1
|
|
|
|
and $x:result[ 3 ] is $args/foo:arg2" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="ternary function">
|
|
|
|
<call function="f:apply">
|
2014-11-24 11:07:25 -05:00
|
|
|
<param name="fnref">
|
|
|
|
<f:ref><foo:fn3 /></f:ref>
|
|
|
|
</param>
|
2014-11-26 11:16:24 -05:00
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
|
|
|
<param name="arg2" select="$args/foo:arg2" />
|
|
|
|
<param name="arg3" select="$args/foo:arg3" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="passes each argument"
|
2014-11-26 11:16:24 -05:00
|
|
|
test="$x:result[ 1 ] = foo:applied[ @n = 3 ]
|
|
|
|
and $x:result[ 2 ] is $args/foo:arg1
|
|
|
|
and $x:result[ 3 ] is $args/foo:arg2
|
|
|
|
and $x:result[ 4 ] is $args/foo:arg3" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="4-ary function">
|
|
|
|
<call function="f:apply">
|
2014-11-24 11:07:25 -05:00
|
|
|
<param name="fnref">
|
|
|
|
<f:ref><foo:fn4 /></f:ref>
|
|
|
|
</param>
|
2014-11-26 11:16:24 -05:00
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
|
|
|
<param name="arg2" select="$args/foo:arg2" />
|
|
|
|
<param name="arg3" select="$args/foo:arg3" />
|
|
|
|
<param name="arg4" select="$args/foo:arg4" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="passes each argument"
|
2014-11-26 11:16:24 -05:00
|
|
|
test="$x:result[ 1 ] = foo:applied[ @n = 4 ]
|
|
|
|
and $x:result[ 2 ] is $args/foo:arg1
|
|
|
|
and $x:result[ 3 ] is $args/foo:arg2
|
|
|
|
and $x:result[ 4 ] is $args/foo:arg3
|
|
|
|
and $x:result[ 5 ] is $args/foo:arg4" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="5-ary function">
|
|
|
|
<call function="f:apply">
|
2014-11-24 11:07:25 -05:00
|
|
|
<param name="fnref">
|
|
|
|
<f:ref><foo:fn5 /></f:ref>
|
|
|
|
</param>
|
2014-11-26 11:16:24 -05:00
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
|
|
|
<param name="arg2" select="$args/foo:arg2" />
|
|
|
|
<param name="arg3" select="$args/foo:arg3" />
|
|
|
|
<param name="arg4" select="$args/foo:arg4" />
|
|
|
|
<param name="arg5" select="$args/foo:arg5" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="passes each argument"
|
2014-11-26 11:16:24 -05:00
|
|
|
test="$x:result[ 1 ] = foo:applied[ @n = 5 ]
|
|
|
|
and $x:result[ 2 ] is $args/foo:arg1
|
|
|
|
and $x:result[ 3 ] is $args/foo:arg2
|
|
|
|
and $x:result[ 4 ] is $args/foo:arg3
|
|
|
|
and $x:result[ 5 ] is $args/foo:arg4
|
|
|
|
and $x:result[ 6 ] is $args/foo:arg5" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="6-ary function">
|
|
|
|
<call function="f:apply">
|
2014-11-24 11:07:25 -05:00
|
|
|
<param name="fnref">
|
|
|
|
<f:ref><foo:fn6 /></f:ref>
|
|
|
|
</param>
|
2014-11-26 11:16:24 -05:00
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
|
|
|
<param name="arg2" select="$args/foo:arg2" />
|
|
|
|
<param name="arg3" select="$args/foo:arg3" />
|
|
|
|
<param name="arg4" select="$args/foo:arg4" />
|
|
|
|
<param name="arg5" select="$args/foo:arg5" />
|
|
|
|
<param name="arg6" select="$args/foo:arg6" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="passes each argument"
|
2014-11-26 11:16:24 -05:00
|
|
|
test="$x:result[ 1 ] = foo:applied[ @n = 6 ]
|
|
|
|
and $x:result[ 2 ] is $args/foo:arg1
|
|
|
|
and $x:result[ 3 ] is $args/foo:arg2
|
|
|
|
and $x:result[ 4 ] is $args/foo:arg3
|
|
|
|
and $x:result[ 5 ] is $args/foo:arg4
|
|
|
|
and $x:result[ 6 ] is $args/foo:arg5
|
|
|
|
and $x:result[ 7 ] is $args/foo:arg6" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="7-ary function">
|
|
|
|
<call function="f:apply">
|
2014-11-24 11:07:25 -05:00
|
|
|
<param name="fnref">
|
|
|
|
<f:ref><foo:fn7 /></f:ref>
|
|
|
|
</param>
|
2014-11-26 11:16:24 -05:00
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
|
|
|
<param name="arg2" select="$args/foo:arg2" />
|
|
|
|
<param name="arg3" select="$args/foo:arg3" />
|
|
|
|
<param name="arg4" select="$args/foo:arg4" />
|
|
|
|
<param name="arg5" select="$args/foo:arg5" />
|
|
|
|
<param name="arg6" select="$args/foo:arg6" />
|
|
|
|
<param name="arg7" select="$args/foo:arg7" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="passes each argument"
|
2014-11-26 11:16:24 -05:00
|
|
|
test="$x:result[ 1 ] = foo:applied[ @n = 7 ]
|
|
|
|
and $x:result[ 2 ] is $args/foo:arg1
|
|
|
|
and $x:result[ 3 ] is $args/foo:arg2
|
|
|
|
and $x:result[ 4 ] is $args/foo:arg3
|
|
|
|
and $x:result[ 5 ] is $args/foo:arg4
|
|
|
|
and $x:result[ 6 ] is $args/foo:arg5
|
|
|
|
and $x:result[ 7 ] is $args/foo:arg6
|
|
|
|
and $x:result[ 8 ] is $args/foo:arg7" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="8-ary function">
|
|
|
|
<call function="f:apply">
|
2014-11-24 11:07:25 -05:00
|
|
|
<param name="fnref">
|
|
|
|
<f:ref><foo:fn8 /></f:ref>
|
|
|
|
</param>
|
2014-11-26 11:16:24 -05:00
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
|
|
|
<param name="arg2" select="$args/foo:arg2" />
|
|
|
|
<param name="arg3" select="$args/foo:arg3" />
|
|
|
|
<param name="arg4" select="$args/foo:arg4" />
|
|
|
|
<param name="arg5" select="$args/foo:arg5" />
|
|
|
|
<param name="arg6" select="$args/foo:arg6" />
|
|
|
|
<param name="arg7" select="$args/foo:arg7" />
|
|
|
|
<param name="arg8" select="$args/foo:arg8" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="passes each argument"
|
2014-11-26 11:16:24 -05:00
|
|
|
test="$x:result[ 1 ] = foo:applied[ @n = 8 ]
|
|
|
|
and $x:result[ 2 ] is $args/foo:arg1
|
|
|
|
and $x:result[ 3 ] is $args/foo:arg2
|
|
|
|
and $x:result[ 4 ] is $args/foo:arg3
|
|
|
|
and $x:result[ 5 ] is $args/foo:arg4
|
|
|
|
and $x:result[ 6 ] is $args/foo:arg5
|
|
|
|
and $x:result[ 7 ] is $args/foo:arg6
|
|
|
|
and $x:result[ 8 ] is $args/foo:arg7
|
|
|
|
and $x:result[ 9 ] is $args/foo:arg8" />
|
2014-11-21 09:15:24 -05:00
|
|
|
</scenario>
|
|
|
|
</scenario>
|
|
|
|
</scenario>
|
2014-11-26 15:35:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
<scenario label="f:make-ref constructor">
|
|
|
|
<scenario label="when called with a function QName and arity">
|
|
|
|
<variable name="qname"
|
|
|
|
select="QName( $foo-uri, 'reftest' )" />
|
|
|
|
<variable name="arity"
|
|
|
|
select="2" />
|
|
|
|
|
|
|
|
<call function="f:make-ref">
|
|
|
|
<param name="name" select="$qname" />
|
|
|
|
<param name="arity" select="$arity" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="produces a dynamic function reference"
|
|
|
|
test="f:is-ref( $x:result )" />
|
|
|
|
|
|
|
|
<expect label="produces provided reference arity"
|
|
|
|
test="f:arity( $x:result ) = $arity" />
|
|
|
|
|
|
|
|
<expect label="produces reference to expected QName"
|
|
|
|
test="f:QName( $x:result ) = $qname" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="produces a valid dynamic function reference">
|
|
|
|
<call function="f:apply">
|
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn1' ),
|
|
|
|
1 )" />
|
|
|
|
<param name="arg1"
|
|
|
|
select="$args/foo:arg1" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="that can be applied using f:apply"
|
|
|
|
test="$x:result[ 1 ] = foo:applied[ @n = 1 ]
|
|
|
|
and $x:result[ 2 ] is $args/foo:arg1" />
|
|
|
|
</scenario>
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="f:is-ref predicate">
|
|
|
|
<scenario label="given a valid dynamic function reference">
|
|
|
|
<call function="f:is-ref">
|
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'foo' ), 0 )" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="returns true()"
|
|
|
|
select="true()" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="given an invalid dynamic function reference">
|
|
|
|
<call function="f:is-ref">
|
|
|
|
<param name="fnref">
|
|
|
|
<foo:bar />
|
|
|
|
</param>
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="returns false()"
|
|
|
|
select="false()" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="given a dynamic function reference without arity">
|
|
|
|
<call function="f:is-ref">
|
|
|
|
<param name="fnref">
|
|
|
|
<f:ref>
|
|
|
|
<foo:bar />
|
|
|
|
</f:ref>
|
|
|
|
</param>
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="returns false()"
|
|
|
|
select="false()" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="given a dynamic function reference without
|
|
|
|
integral arity">
|
|
|
|
<call function="f:is-ref">
|
|
|
|
<param name="fnref">
|
|
|
|
<f:ref arity="moo">
|
|
|
|
<foo:bar />
|
|
|
|
</f:ref>
|
|
|
|
</param>
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="returns false()"
|
|
|
|
select="false()" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="given a dynamic function reference without target
|
|
|
|
node">
|
|
|
|
<call function="f:is-ref">
|
|
|
|
<param name="fnref">
|
|
|
|
<f:ref arity="0" />
|
|
|
|
</param>
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="returns false()"
|
|
|
|
select="false()" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="given an empty sequence">
|
|
|
|
<call function="f:is-ref">
|
|
|
|
<param name="fnref" select="()" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="returns false()"
|
|
|
|
select="false()" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="given a non-element">
|
|
|
|
<call function="f:is-ref">
|
|
|
|
<param name="fnref" select="5" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="returns false()"
|
|
|
|
select="false()" />
|
|
|
|
</scenario>
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="f:QName accessor">
|
|
|
|
<scenario label="given a valid dynamic function reference">
|
|
|
|
<variable name="foo-qname"
|
|
|
|
select="QName( $foo-uri, 'foo' )" />
|
|
|
|
|
|
|
|
<call function="f:QName">
|
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( $foo-qname, 0 )" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="returns QName"
|
|
|
|
test="$x:result instance of xs:QName" />
|
|
|
|
|
|
|
|
<expect label="returns QName of target dynamic function"
|
|
|
|
select="$foo-qname" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="given a dynamic function reference with no target
|
|
|
|
node">
|
|
|
|
<call function="f:QName">
|
|
|
|
<param name="fnref">
|
|
|
|
<f:ref arity="5" />
|
|
|
|
</param>
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="returns empty sequence"
|
|
|
|
select="()" />
|
|
|
|
</scenario>
|
|
|
|
</scenario>
|
2014-11-21 09:15:24 -05:00
|
|
|
</description>
|