apply-gen application template generation added
parent
28845f8b2e
commit
81bec6714b
|
@ -1 +1,2 @@
|
|||
/test/**/xspec/
|
||||
*.out
|
||||
|
|
15
Makefile
15
Makefile
|
@ -1,4 +1,4 @@
|
|||
## xslink Makefile
|
||||
## hoxsl Makefile
|
||||
#
|
||||
# Copyright (C) 2014 LoVullo Associates, Inc.
|
||||
#
|
||||
|
@ -16,10 +16,21 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
path_src := src
|
||||
path_test := test
|
||||
|
||||
test_in_apply_gen := $(path_test)/transform/apply-gen-test-in.xsl.out
|
||||
|
||||
.PHONY: check test
|
||||
|
||||
test: check
|
||||
check:
|
||||
check: $(test_in_apply_gen)
|
||||
$(path_test)/runner
|
||||
|
||||
%.xsl.out: %.xsl
|
||||
java -jar "$(SAXON_CP)" \
|
||||
-xsl:"$(path_src)/transform/apply-gen.xsl" \
|
||||
"$<" > "$@"
|
||||
|
||||
clean:
|
||||
$(RM) "$(test_in_apply_gen)"
|
||||
|
|
|
@ -127,6 +127,8 @@
|
|||
|
||||
<sequence select="fgen:create-func(
|
||||
$name-resolv, $local-name, $ns )" />
|
||||
<sequence select="fgen:create-tpl(
|
||||
$name-resolv, . )" />
|
||||
</template>
|
||||
|
||||
|
||||
|
@ -154,4 +156,40 @@
|
|||
</out:function>
|
||||
</function>
|
||||
|
||||
|
||||
<!--
|
||||
TODO: param count overloading
|
||||
-->
|
||||
<function name="fgen:create-tpl">
|
||||
<param name="name-resolv" as="xs:QName" />
|
||||
<param name="defn" as="element(xsl:function)" />
|
||||
|
||||
<variable name="params"
|
||||
select="$defn/xsl:param" />
|
||||
|
||||
<out:template mode="f:apply"
|
||||
match="{$name-resolv}">
|
||||
<for-each select="$params">
|
||||
<xsl:variable name="i"
|
||||
select="position()" />
|
||||
|
||||
<out:param name="arg{$i}">
|
||||
<copy-of select="@as" />
|
||||
</out:param>
|
||||
</for-each>
|
||||
|
||||
<variable name="argstr">
|
||||
<for-each select="$params">
|
||||
<if test="position() gt 1">
|
||||
<text>, </text>
|
||||
</if>
|
||||
<text>$arg</text>
|
||||
<value-of select="position()" />
|
||||
</for-each>
|
||||
</variable>
|
||||
|
||||
<out:sequence select="{$name-resolv}({$argstr})" />
|
||||
</out:template>
|
||||
</function>
|
||||
|
||||
</stylesheet>
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Stub stylesheet for apply-gen testing
|
||||
|
||||
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:foo="http://www.lovullo.com/_junk">
|
||||
|
||||
|
||||
<function name="foo:add-two" as="xs:decimal">
|
||||
<param name="x" as="xs:decimal" />
|
||||
<param name="y" as="xs:decimal" />
|
||||
|
||||
<sequence select="$x + $y" />
|
||||
</function>
|
||||
</stylesheet>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Tests boilerplate generation for dynamic function applications
|
||||
|
||||
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"
|
||||
xmlns:foo="http://www.lovullo.com/_junk">
|
||||
|
||||
|
||||
<!-- SUT -->
|
||||
<import href="../../src/transform/apply-gen.xsl" />
|
||||
|
||||
<!-- input stylesheet -->
|
||||
<import href="apply-gen-test-in.xsl" />
|
||||
|
||||
<!-- N.B. it is expected tha a build process has already built this
|
||||
document before running this test -->
|
||||
<import href="apply-gen-test-in.xsl.out" />
|
||||
|
||||
|
||||
<function name="foo:apply-add-two">
|
||||
<param name="x" as="xs:decimal" />
|
||||
<param name="y" as="xs:decimal" />
|
||||
|
||||
<apply-templates select="foo:add-two()"
|
||||
mode="f:apply">
|
||||
<with-param name="arg1" select="$x" />
|
||||
<with-param name="arg2" select="$y" />
|
||||
</apply-templates>
|
||||
</function>
|
||||
</stylesheet>
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
<description xmlns="http://www.jenitennison.com/xslt/xspec"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:foo="http://www.lovullo.com/_junk"
|
||||
stylesheet="../../src/transform/apply-gen.xsl">
|
||||
stylesheet="apply-gen-test.xsl">
|
||||
|
||||
<!-- basic case -->
|
||||
<scenario label="given a unary function">
|
||||
|
@ -54,6 +54,49 @@
|
|||
</expect>
|
||||
|
||||
|
||||
<!-- more detailed tests below -->
|
||||
<expect label="generates application template"
|
||||
test="xsl:stylesheet/xsl:template/@match = 'foo:bar'" />
|
||||
|
||||
<expect label="generated template has mode f:apply"
|
||||
test="xsl:stylesheet/xsl:template/@mode = 'f:apply'" />
|
||||
</scenario>
|
||||
|
||||
|
||||
<!-- we'll test the application directly; we won't parse the output,
|
||||
since that is error-prone, fragile, and misses the poin -->
|
||||
<scenario label="application templates">
|
||||
<scenario label="of N-ary functions">
|
||||
<context>
|
||||
<xsl:stylesheet>
|
||||
<xsl:function name="foo:bar">
|
||||
<xsl:param name="a" />
|
||||
<xsl:param name="b" as="xs:decimal" />
|
||||
<xsl:param name="c" />"
|
||||
</xsl:function>
|
||||
</xsl:stylesheet>
|
||||
</context>
|
||||
|
||||
<expect label="yields N template parameters"
|
||||
test="count( xsl:stylesheet/xsl:template/xsl:param )
|
||||
= 3" />
|
||||
|
||||
<!-- important for application! -->
|
||||
<expect label="template parameter names are sequential"
|
||||
test="xsl:stylesheet/xsl:template/xsl:param
|
||||
/@name = concat( 'arg', position() )" />
|
||||
|
||||
<expect label="mirrors params without @as"
|
||||
test="not( xsl:stylesheet/xsl:template
|
||||
/xsl:param[ 1 ]/@as )" />
|
||||
|
||||
<expect label="mirrors params with @as"
|
||||
test="xsl:stylesheet/xsl:template
|
||||
/xsl:param[ 2 ]/@as = 'xs:decimal'" />
|
||||
</scenario>
|
||||
</scenario>
|
||||
|
||||
|
||||
<!-- if a function is nullary, then it is either a thunk or used for
|
||||
its side-effects; we expect the user to take appropriate
|
||||
caution -->
|
||||
|
@ -100,4 +143,27 @@
|
|||
<xsl:stylesheet version="2.0" />
|
||||
</expect>
|
||||
</scenario>
|
||||
|
||||
|
||||
<!-- This actually tests the generated stylesheet to ensure proper
|
||||
execution. We test by invoking the application template with
|
||||
the result of the generated nullary. We expect that the
|
||||
application template will apply the arguments to the proper
|
||||
function and return the result of the expected type.
|
||||
|
||||
You can't see it here (check the imported stylesheet), but
|
||||
`foo:apply-add-two' defines a return type, so we also ensure
|
||||
that such type data are retained.
|
||||
|
||||
Exciting! -->
|
||||
<scenario label="given a generated document">
|
||||
<!-- calling the generated nullary -->
|
||||
<call function="foo:apply-add-two">
|
||||
<param name="x" select="2" />
|
||||
<param name="y" select="3" />
|
||||
</call>
|
||||
|
||||
<expect label="applying template to nullary yields proper result"
|
||||
test="$x:result = 5" />
|
||||
</scenario>
|
||||
</description>
|
||||
|
|
Loading…
Reference in New Issue