<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/polyglot-008.xml"
        name="polyglot-008.xml"
        expected="pass"
        features="polyglot">
   <t:info>
      <t:title>polyglot-008</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2025-01-03</t:date>
            <t:author>
               <t:name>Norm Tovey-Walsh</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Created test.</p>
            </t:description>
         </t:revision>
      </t:revision-history>
   </t:info>
   <t:description xmlns="http://www.w3.org/1999/xhtml">
      <p>Tests that the cx:javascript polyglot step returns XML.</p>
   </t:description>
   <t: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"
                      version="3.0">
         <p:import href="https://xmlcalabash.com/ext/library/polyglot.xpl"/>
         <p:output port="result"/>
         <cx:javascript variables="map{'x': 7, 'y': 9, 'now': current-dateTime()}"
                        result-content-type="application/xml">
            <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">
console.log("&lt;?xml version='1.0'?&gt;")
console.log(`&lt;doc&gt;${x*y}&lt;/doc&gt;`)
          </p:inline>
            </p:with-input>
         </cx:javascript>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
         <s:pattern>
            <s:rule context="/">
               <s:assert test="doc">The root element is incorrect.</s:assert>
               <s:assert test="doc='63'">The document element value is incorrect.</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="polyglot-008.xml">
      <doc>63</doc>
   </t:result>
</t:test>
