polyglot-007
Tests that the cx:javascript polyglot step returns an array.
Test is expected to pass.
The pipeline
<p:declare-step xmlns:cx="http://xmlcalabash.com/ns/extensions"
xmlns:err="http://www.w3.org/ns/xproc-error" xmlns:p="http://www.w3.org/ns/xproc"
xmlns:t="http://xproc.org/ns/testsuite/3.0" version="3.0">
<p:import href="https://xmlcalabash.com/ext/library/polyglot.xpl"/>
<p:output port="result"/>
<cx:javascript parameters="map{'x': 7, 'y': 9, 'now': current-dateTime()}">
<p:with-input>
<doc>Test</doc>
</p:with-input>
<p:with-option name="args"
select="('a', 'b', 'c')"/>
<p:with-input port="program">
<p:inline content-type="text/plain"
expand-text="false">
[1, 2, x*y, "TEST"]
</p:inline>
</p:with-input>
</cx:javascript>
<p:cast-content-type content-type="application/xml"/>
</p:declare-step>
Result
<array xmlns="http://www.w3.org/2005/xpath-functions"
xmlns:t="http://xproc.org/ns/testsuite/3.0">
<number>1</number>
<number>2</number>
<number>63</number>
<string>TEST</string>
</array>
Schematron checks
<s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron"
xmlns:t="http://xproc.org/ns/testsuite/3.0" queryBinding="xslt2">
<s:ns prefix="fn"
uri="http://www.w3.org/2005/xpath-functions"/>
<s:pattern>
<s:rule context="/">
<s:assert test="fn:array">The result isn’t an array.</s:assert>
</s:rule>
</s:pattern>
<s:pattern>
<s:rule context="/fn:array">
<s:assert test="*[1]/self::fn:number and *[1] = '1'">The first element is incorrect.</s:assert>
<s:assert test="*[2]/self::fn:number and *[2] = '2'">The second element is incorrect.</s:assert>
<s:assert test="*[3]/self::fn:number and *[3] = '63'">The third element is incorrect.</s:assert>
<s:assert test="*[4]/self::fn:string and *[4] = 'TEST'">The fourth element is incorrect.</s:assert>
</s:rule>
</s:pattern>
</s:schema>
Revision history
- 03 Jan 2025, Norm Tovey-Walsh
- Created test.