<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
  <t:info>
    <t:title>compile-cache-001</t:title>
    <t:revision-history>
      <t:revision>
        <t:date>2026-01-21</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 p:xslt stylesheet caching “works”.</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:ex="http://example.com/ns/step"
                    xmlns:p="http://www.w3.org/ns/xproc">
      <p:import href="https://xmlcalabash.com/ext/library/pipeline-messages.xpl"/>
      <p:output port="result"/>

      <p:declare-step type="ex:xslt">
        <p:input port="source" primary="true"/>
        <p:input port="stylesheet"/>
        <p:output port="result"/>
        <p:xslt cx:cache-stylesheet="true">
          <p:with-input port="source" pipe="source"/>
          <p:with-input port="stylesheet" pipe="stylesheet"/>
        </p:xslt>
      </p:declare-step>

      <ex:xslt>
        <p:with-input port="source">
          <doc>
            <p>It doesn’t matter what goes here</p>
          </doc>
        </p:with-input>
        <p:with-input port="stylesheet" href="../documents/identity.xsl"/>
      </ex:xslt>

      <ex:xslt name="xslt">
        <p:with-input port="stylesheet" href="../documents/identity.xsl"/>
      </ex:xslt>

      <cx:pipeline-messages p:depends="xslt" level="debug"/>
    </p:declare-step>
  </t:pipeline>

  <t:schematron>
    <s:schema queryBinding="xslt2"
              xmlns:s="http://purl.oclc.org/dsdl/schematron">
      <s:ns prefix="cx" uri="http://xmlcalabash.com/ns/extensions"/>
      <s:pattern>
        <s:rule context="/">
          <s:assert test="cx:messages">The document root is not correct.</s:assert>
        </s:rule>
      </s:pattern>
      <s:pattern>
        <s:rule context="/cx:messages">
          <s:assert test="cx:message[@level='DEBUG'
                            and matches(@message, 'Caching compiled.*documents/identity\.xsl')]"
                    >No caching message.</s:assert>
          <s:assert test="cx:message[@level='DEBUG'
                            and matches(@message, 'Using cached.*documents/identity\.xsl')]"
                    >No using cached message.</s:assert>
        </s:rule>
      </s:pattern>
    </s:schema>
  </t:schematron>

</t:test>
