代码之家  ›  专栏  ›  技术社区  ›  lagivan

如何使用map参数测试XQuery函数

  •  1
  • lagivan  · 技术社区  · 11 年前

    我想测试一个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>
    

    有什么办法让它工作吗?

    1 回复  |  直到 11 年前
        1
  •  2
  •   lagivan    11 年前

    在邮件列表中收到以下回复:

    对不起,这是不可能的。映射没有简单的字符串 代表。您必须为测试编写一个助手函数, 它生成映射,例如通过获取xml片段并转换 它

    沃尔夫冈