<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
  <t:info>
    <t:title>cache-002</t:title>
    <t:revision-history>
      <t:revision>
        <t:date>2024-11-29</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 document can be added to the cache.</p>
  </t:description>
  <t:pipeline>
    <p:declare-step version="3.0"
                    xmlns:err="http://www.w3.org/ns/xproc-error"
                    xmlns:cx="http://xmlcalabash.com/ns/extensions"
                    xmlns:p="http://www.w3.org/ns/xproc">
      <p:import href="https://xmlcalabash.com/ext/library/cache.xpl"/>
      <p:output port="result"/>

      <cx:cache-add name="cache-add"
                    href="https://xmlcalabash.com/does/not/exist.xml">
        <p:with-input>
          <does-so/>
        </p:with-input>
      </cx:cache-add>

      <p:try>
        <p:xinclude depends="cache-add">
          <p:with-input>
            <doc xmlns:xi="http://www.w3.org/2001/XInclude">
              <xi:include href="https://xmlcalabash.com/does/not/exist.xml"/>
            </doc>
          </p:with-input>
        </p:xinclude>
        <p:catch code="err:XC0029">
          <p:identity>
            <p:with-input>
              <fail/>
            </p:with-input>
          </p:identity>
        </p:catch>
      </p:try>
    </p:declare-step>
  </t:pipeline>
  <t:schematron>
    <s:schema queryBinding="xslt2"
              xmlns:s="http://purl.oclc.org/dsdl/schematron">
      <s:pattern>
        <s:rule context="/">
          <s:assert test="doc">The document root is not doc.</s:assert>
          <s:assert test="doc/does-so">The document doesn’t contain does-so.</s:assert>
        </s:rule>
      </s:pattern>
    </s:schema>
  </t:schematron>
</t:test>
