<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <t:info>
      <t:title>cast-content-type 004 (AB)</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2021-06-10</t:date>
            <t:author>
               <t:name>Achim Berndzen</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Added attribute 'queryBinding' to schematron's schema.</p>
            </t:description>
         </t:revision>
         <t:revision>
            <t:date>2019-12-27</t:date>
            <t:author>
               <t:name>Achim Berndzen</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Initial tests for the new iteration of p:cast-content-type</p>
            </t:description>
         </t:revision>
      </t:revision-history>
   </t:info>
   <t:description xmlns="http://www.w3.org/1999/xhtml">
      <p>Tests casting from an xml content type to a json content type (XPath style).</p>
   </t:description>
   <t:pipeline>
      <p:declare-step name="pipeline"
                      version="3.0"
                      xmlns:p="http://www.w3.org/ns/xproc"
                      xmlns:fn="http://www.w3.org/2005/xpath-functions"
                      xmlns:map="http://www.w3.org/2005/xpath-functions/map">
         <p:output port="result"/>
         <p:cast-content-type content-type="application/json"
                              name="caster">
            <p:with-input>
               <p:inline document-properties="map{'base-uri' : 'http://xproc-test.org',                         'serialization' : map{'indent' : true()},                         'additional' : 'property'}">
                  <fn:map>
                     <fn:string key="key">value</fn:string>
                  </fn:map>
               </p:inline>
            </p:with-input>
         </p:cast-content-type>
         <p:choose name="checker">
            <p:when test=". instance of map(*) and map:get(., 'key') = 'value' ">
               <p:identity>
                  <p:with-input>
                     <right/>
                  </p:with-input>
               </p:identity>
            </p:when>
            <p:otherwise>
               <p:identity>
                  <p:with-input>
                     <wrong/>
                  </p:with-input>
               </p:identity>
            </p:otherwise>
         </p:choose>
         <p:cast-content-type content-type="application/xml"
                              name="properties">
            <p:with-input select="p:document-properties(.)"
                          pipe="@caster"/>
         </p:cast-content-type>
         <p:wrap-sequence wrapper="result">
            <p:with-input pipe="@checker @properties"/>
         </p:wrap-sequence>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema queryBinding="xslt2"
                xmlns:s="http://purl.oclc.org/dsdl/schematron">
         <s:ns prefix="fn"
               uri="http://www.w3.org/2005/xpath-functions"/>
         <s:pattern>
            <s:rule context="/">
               <s:assert test="result">The root element is not result.</s:assert>
               <s:assert test="result/right">Root element does not have child 'right'.</s:assert>
               <s:assert test="result/fn:map">Root element does not have child 'fn:map'.</s:assert>
               <s:assert test="result/fn:map/fn:string[@key='base-uri']='http://xproc-test.org'">The base-uri property is not correct.</s:assert>
               <s:assert test="result/fn:map/fn:string[@key='content-type']='application/json'">The content-type property is not correct.</s:assert>
               <s:assert test="result/fn:map/fn:string[@key='additional']='property'">The additional property is not correct.</s:assert>
               <s:assert test="not(result/fn:map/fn:map[@key='serialization'])">There should be is no serialization property.</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
</t:test>