f:arity extracted into its own stylesheet
It depends on partial application logic, but does not belong in partial.xslmaster
parent
a02865d8b1
commit
04373b5edd
|
@ -30,6 +30,8 @@
|
|||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:f="http://www.lovullo.com/hoxsl/apply">
|
||||
|
||||
<import href="apply/arity.xsl" />
|
||||
|
||||
|
||||
<function name="f:apply">
|
||||
<param name="fnref" as="element(f:ref)" />
|
||||
|
@ -193,20 +195,4 @@
|
|||
</message>
|
||||
</template>
|
||||
|
||||
|
||||
<!--
|
||||
Attempt to retrieve arity of delayed function
|
||||
|
||||
The input must be a function reference. If the arity cannot be
|
||||
determined, -1 is returned.
|
||||
-->
|
||||
<function name="f:arity" as="xs:decimal">
|
||||
<param name="fnref" as="element(f:ref)" />
|
||||
|
||||
<sequence select="if ( $fnref/@arity ) then
|
||||
$fnref/@arity
|
||||
else
|
||||
-1" />
|
||||
</function>
|
||||
|
||||
</stylesheet>
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Arity calculations on dynamic and partially applied functions
|
||||
|
||||
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/>.
|
||||
-->
|
||||
|
||||
<stylesheet version="2.0"
|
||||
xmlns="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:f="http://www.lovullo.com/hoxsl/apply">
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
Attempt to retrieve arity of dynamic function
|
||||
|
||||
The input must be a function reference. Partially applied function
|
||||
references will have an arity equivalent to the remaining parameters
|
||||
in the original function.
|
||||
|
||||
If the arity cannot be determined, -1 is returned.
|
||||
-->
|
||||
<function name="f:arity" as="xs:decimal">
|
||||
<param name="fnref" as="element(f:ref)" />
|
||||
|
||||
<sequence select="if ( $fnref/@arity ) then
|
||||
$fnref/@arity
|
||||
else
|
||||
-1" />
|
||||
</function>
|
||||
|
||||
</stylesheet>
|
|
@ -192,43 +192,4 @@
|
|||
</scenario>
|
||||
</scenario>
|
||||
</scenario>
|
||||
|
||||
|
||||
<scenario label="f:arity">
|
||||
<scenario label="given a proper function reference">
|
||||
<variable name="test-arity"
|
||||
select="5" />
|
||||
|
||||
<!-- test our format directly; do not rely on the
|
||||
apply-gen code -->
|
||||
<variable name="fnref">
|
||||
<f:ref arity="{$test-arity}">
|
||||
<foo:bar />
|
||||
</f:ref>
|
||||
</variable>
|
||||
|
||||
<call function="f:arity">
|
||||
<param name="fnref"
|
||||
select="$fnref" />
|
||||
</call>
|
||||
|
||||
<expect label="provides function arity"
|
||||
test="$x:result = $test-arity" />
|
||||
</scenario>
|
||||
|
||||
|
||||
<scenario label="given a function reference with no defined arity">
|
||||
<variable name="fnref">
|
||||
<f:ref><foo:bar /></f:ref>
|
||||
</variable>
|
||||
|
||||
<call function="f:arity">
|
||||
<param name="fnref"
|
||||
select="$fnref" />
|
||||
</call>
|
||||
|
||||
<expect label="returns -1"
|
||||
test="$x:result = -1" />
|
||||
</scenario>
|
||||
</scenario>
|
||||
</description>
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Tests arity calculations
|
||||
|
||||
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"
|
||||
xmlns:x="http://www.jenitennison.com/xslt/xspec"
|
||||
xmlns:f="http://www.lovullo.com/hoxsl/apply"
|
||||
xmlns:foo="http://www.lovullo.com/_junk"
|
||||
stylesheet="../../src/apply/arity.xsl">
|
||||
|
||||
|
||||
<scenario label="f:arity">
|
||||
<scenario label="given a proper function reference">
|
||||
<variable name="test-arity"
|
||||
select="5" />
|
||||
|
||||
<!-- test our format directly; do not rely on the
|
||||
apply-gen code -->
|
||||
<variable name="fnref">
|
||||
<f:ref arity="{$test-arity}">
|
||||
<foo:bar />
|
||||
</f:ref>
|
||||
</variable>
|
||||
|
||||
<call function="f:arity">
|
||||
<param name="fnref"
|
||||
select="$fnref" />
|
||||
</call>
|
||||
|
||||
<expect label="provides function arity"
|
||||
test="$x:result = $test-arity" />
|
||||
</scenario>
|
||||
|
||||
|
||||
<scenario label="given a function reference with no defined arity">
|
||||
<variable name="fnref">
|
||||
<f:ref><foo:bar /></f:ref>
|
||||
</variable>
|
||||
|
||||
<call function="f:arity">
|
||||
<param name="fnref"
|
||||
select="$fnref" />
|
||||
</call>
|
||||
|
||||
<expect label="returns -1"
|
||||
test="$x:result = -1" />
|
||||
</scenario>
|
||||
</scenario>
|
||||
</description>
|
Loading…
Reference in New Issue