<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/compile-cache-002.xml"
        name="compile-cache-002.xml"
        expected="pass">
   <t:info>
      <t:title>compile-cache-002</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 the cache is used more than once.</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"
                      xmlns:s="http://purl.oclc.org/dsdl/schematron"
                      version="3.0">
         <p:import href="https://xmlcalabash.com/ext/library/pipeline-messages.xpl"/>
         <p:output port="result"/>
         <p:xslt cx:cache-stylesheet="true">
            <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"/>
         </p:xslt>
         <p:xslt cx:cache-stylesheet="true">
            <p:with-input port="stylesheet" href="../documents/identity.xsl"/>
         </p:xslt>
         <p:xslt name="xslt" cx:cache-stylesheet="true">
            <p:with-input port="stylesheet" href="../documents/identity.xsl"/>
         </p:xslt>
         <cx:pipeline-messages p:depends="xslt" level="debug"/>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
         <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:rule>
            <s:rule context="/cx:messages">
               <s:assert test="cx:message[@level='DEBUG'                             and matches(@message, 'Using cached.*documents/identity\.xsl')]                             /following-sibling::cx:message[@level='DEBUG'                             and matches(@message, 'Using cached.*documents/identity\.xsl')]">No second using cached message.</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="compile-cache-002.xml">
      <cx:messages xmlns:cx="http://xmlcalabash.com/ns/extensions">
         <cx:message date="2026-07-18T16:01:52+00:00"
                     level="DEBUG"
                     message="Caching compiled resource: !xslt|file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/extra-suite/test-suite/documents/identity.xsl"/>
         <cx:message date="2026-07-18T16:01:52+00:00"
                     level="DEBUG"
                     message="Caching compiled resource: !xslt_2|file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/extra-suite/test-suite/documents/identity.xsl"/>
         <cx:message date="2026-07-18T16:01:52+00:00"
                     level="DEBUG"
                     message="Caching compiled resource: xslt|file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/extra-suite/test-suite/documents/identity.xsl"/>
      </cx:messages>
   </t:result>
</t:test>
