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"
|
2016-03-26 14:17:30 -04:00
|
|
|
xmlns:f="http://mikegerwitz.com/hoxsl/apply"
|
|
|
|
xmlns:foo="http://mikegerwitz.com/_junk"
|
2014-11-21 09:15:24 -05:00
|
|
|
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-26 16:17:19 -05:00
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn0' ), 0 )" />
|
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-26 16:17:19 -05:00
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn1' ), 1 )" />
|
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-26 16:17:19 -05:00
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn2' ), 2 )" />
|
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-26 16:17:19 -05:00
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn3' ), 3 )" />
|
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-26 16:17:19 -05:00
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn4' ), 4 )" />
|
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-26 16:17:19 -05:00
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn5' ), 5 )" />
|
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-26 16:17:19 -05:00
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn6' ), 6 )" />
|
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-26 16:17:19 -05:00
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn7' ), 7 )" />
|
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-26 16:17:19 -05:00
|
|
|
<param name="fnref"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn8' ), 8 )" />
|
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>
|
2014-11-26 16:28:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
<scenario label="applied to partial argument list">
|
2014-11-26 16:46:02 -05:00
|
|
|
<variable name="fn8"
|
|
|
|
select="f:make-ref( QName( $foo-uri, 'fn8' ),
|
|
|
|
8 )" />
|
|
|
|
|
2014-11-26 16:28:29 -05:00
|
|
|
<!-- while this looks comprehensive, this really only tests
|
|
|
|
f:apply#2 -->
|
|
|
|
<scenario label="supports currying">
|
|
|
|
|
|
|
|
<call function="f:apply">
|
|
|
|
<!-- @, @ makin' you dizzy? -->
|
|
|
|
<param name="fnref"
|
|
|
|
select="f:apply(
|
|
|
|
f:apply(
|
|
|
|
f:apply(
|
|
|
|
f:apply(
|
|
|
|
f:apply(
|
|
|
|
f:apply(
|
|
|
|
f:apply(
|
|
|
|
$fn8,
|
|
|
|
$args/foo:arg1 ),
|
|
|
|
$args/foo:arg2 ),
|
|
|
|
$args/foo:arg3 ),
|
|
|
|
$args/foo:arg4 ),
|
|
|
|
$args/foo:arg5 ),
|
|
|
|
$args/foo:arg6 ),
|
|
|
|
$args/foo:arg7 )" />
|
|
|
|
|
|
|
|
<!-- the final argument that will apply the unary
|
|
|
|
partially applied function to the target 8-ary -->
|
|
|
|
<param name="arg1"
|
|
|
|
select="$args/foo:arg8" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="applies target function and binds each
|
|
|
|
argument in proper order"
|
2014-11-26 16:46:02 -05:00
|
|
|
test="foo:arg8-check( $args/*, $x:result )" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="with 1 argument">
|
|
|
|
<call function="f:apply">
|
|
|
|
<param name="fnref" select="$fn8" />
|
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="produces a partial application"
|
|
|
|
test="f:is-partial( $x:result )" />
|
|
|
|
|
|
|
|
<expect label="can complete application with arguments in
|
|
|
|
proper order"
|
|
|
|
test="foo:arg8-check(
|
|
|
|
$args/*,
|
|
|
|
f:apply( $x:result, $args/foo:arg2,
|
|
|
|
$args/foo:arg3,
|
|
|
|
$args/foo:arg4,
|
|
|
|
$args/foo:arg5,
|
|
|
|
$args/foo:arg6,
|
|
|
|
$args/foo:arg7,
|
|
|
|
$args/foo:arg8 ) )" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="with 2 arguments">
|
|
|
|
<call function="f:apply">
|
|
|
|
<param name="fnref" select="$fn8" />
|
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
|
|
|
<param name="arg2" select="$args/foo:arg2" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="produces a partial application"
|
|
|
|
test="f:is-partial( $x:result )" />
|
|
|
|
|
|
|
|
<expect label="can complete application with arguments in
|
|
|
|
proper order"
|
|
|
|
test="foo:arg8-check(
|
|
|
|
$args/*,
|
|
|
|
f:apply( $x:result, $args/foo:arg3,
|
|
|
|
$args/foo:arg4,
|
|
|
|
$args/foo:arg5,
|
|
|
|
$args/foo:arg6,
|
|
|
|
$args/foo:arg7,
|
|
|
|
$args/foo:arg8 ) )" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="with 3 arguments">
|
|
|
|
<call function="f:apply">
|
|
|
|
<param name="fnref" select="$fn8" />
|
|
|
|
<param name="arg1" select="$args/foo:arg1" />
|
|
|
|
<param name="arg2" select="$args/foo:arg2" />
|
|
|
|
<param name="arg3" select="$args/foo:arg3" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="produces a partial application"
|
|
|
|
test="f:is-partial( $x:result )" />
|
|
|
|
|
|
|
|
<expect label="can complete application with arguments in
|
|
|
|
proper order"
|
|
|
|
test="foo:arg8-check(
|
|
|
|
$args/*,
|
|
|
|
f:apply( $x:result, $args/foo:arg4,
|
|
|
|
$args/foo:arg5,
|
|
|
|
$args/foo:arg6,
|
|
|
|
$args/foo:arg7,
|
|
|
|
$args/foo:arg8 ) )" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="with 4 arguments">
|
|
|
|
<call function="f:apply">
|
|
|
|
<param name="fnref" select="$fn8" />
|
|
|
|
<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" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="produces a partial application"
|
|
|
|
test="f:is-partial( $x:result )" />
|
|
|
|
|
|
|
|
<expect label="can complete application with arguments in
|
|
|
|
proper order"
|
|
|
|
test="foo:arg8-check(
|
|
|
|
$args/*,
|
|
|
|
f:apply( $x:result, $args/foo:arg5,
|
|
|
|
$args/foo:arg6,
|
|
|
|
$args/foo:arg7,
|
|
|
|
$args/foo:arg8 ) )" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="with 5 arguments">
|
|
|
|
<call function="f:apply">
|
|
|
|
<param name="fnref" select="$fn8" />
|
|
|
|
<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" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="produces a partial application"
|
|
|
|
test="f:is-partial( $x:result )" />
|
|
|
|
|
|
|
|
<expect label="can complete application with arguments in
|
|
|
|
proper order"
|
|
|
|
test="foo:arg8-check(
|
|
|
|
$args/*,
|
|
|
|
f:apply( $x:result, $args/foo:arg6,
|
|
|
|
$args/foo:arg7,
|
|
|
|
$args/foo:arg8 ) )" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="with 6 arguments">
|
|
|
|
<call function="f:apply">
|
|
|
|
<param name="fnref" select="$fn8" />
|
|
|
|
<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" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="produces a partial application"
|
|
|
|
test="f:is-partial( $x:result )" />
|
|
|
|
|
|
|
|
<expect label="can complete application with arguments in
|
|
|
|
proper order"
|
|
|
|
test="foo:arg8-check(
|
|
|
|
$args/*,
|
|
|
|
f:apply( $x:result, $args/foo:arg7,
|
|
|
|
$args/foo:arg8 ) )" />
|
|
|
|
</scenario>
|
|
|
|
|
|
|
|
|
|
|
|
<scenario label="with 7 arguments">
|
|
|
|
<call function="f:apply">
|
|
|
|
<param name="fnref" select="$fn8" />
|
|
|
|
<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" />
|
|
|
|
</call>
|
|
|
|
|
|
|
|
<expect label="produces a partial application"
|
|
|
|
test="f:is-partial( $x:result )" />
|
|
|
|
|
|
|
|
<expect label="can complete application with arguments in
|
|
|
|
proper order"
|
|
|
|
test="foo:arg8-check(
|
|
|
|
$args/*,
|
|
|
|
f:apply( $x:result, $args/foo:arg8 ) )" />
|
2014-11-26 16:28:29 -05:00
|
|
|
</scenario>
|
|
|
|
</scenario>
|
2014-11-21 09:15:24 -05:00
|
|
|
</scenario>
|
|
|
|
</description>
|