我想测试一个eXistdbXQuery函数
Map datatype
论点根据
eXist-db test framework guide
:
XQuery注释参数需要是文字值,因此仅
允许使用字符串和数字。XQSuite因此应用类型转换
每个参数以及断言中使用的值。
然而,我找不到如何将Map数据类型指定为字符串。下面是我的示例代码:
declare
%test:arg("input", "{p1}?id={id}")
%test:arg("props", "id")
%test:arg("props", "ABC")
%test:assertEquals("{p1}?id=ABC")
function properties:substitute($input as xs:string, $props as map (xs:string, xs:string)) as xs:string {
let $keys := map:keys($props)
let $tokens := $keys ! concat('\{', ., '\}')
let $replacements := $keys ! $props(.)
return functx:replace-multi($input, $tokens, $replacements)
};
测试失败,错误如下:
<testcase name="substitute" class="properties:substitute">
<error type="java:org.exist.xquery.XPathException" message="exerr:ERROR XPTY0004: The actual cardinality for parameter 2 does not match the cardinality declared in the function's signature: properties:substitute($input as xs:string, $props as map) xs:string. Expected cardinality: exactly one, got 3. [at line 7, column 5]
In function:
properties:substitute(xs:string, map) [7:5:/db/apps/ssg/modules/properties.xql]
test:apply(function, item()*) [327:9:jar:file:/C:/Programs/eXist-db/exist.jar!/org/exist/xquery/lib/xqsuite/xqsuite.xql]
test:apply(function, element(), item()*) [234:9:jar:file:/C:/Programs/eXist-db/exist.jar!/org/exist/xquery/lib/xqsuite/xqsuite.xql]
test:call-test(function, element(), element()*) [135:32:jar:file:/C:/Programs/eXist-db/exist.jar!/org/exist/xquery/lib/xqsuite/xqsuite.xql]"/>
</testcase>
有什么办法让它工作吗?