<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
  <t:info>
    <t:title>issue-160-001</t:title>
    <t:revision-history>
      <t:revision>
        <t:date>2025-01-20</t:date>
        <t:author>
          <t:name>Norm Tovey-Walsh</t:name>
        </t:author>
        <t:description xmlns="http://www.w3.org/1999/xhtml">
          <p>Fixed typo in the test title.</p>
        </t:description>
      </t:revision>
      <t:revision>
        <t:date>2025-01-19</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 a variable defined as a function can be evaluated later on.</p>
  </t:description>
<t:pipeline>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:ex="https://xmlcalabash.com/ns/examples"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:cx="http://xmlcalabash.com/ns/extensions"
                exclude-inline-prefixes="ex xs cx"
                name="main"
                version="3.0">
  <p:import href="https://xmlcalabash.com/ext/library/pipeline-messages.xpl"/>
  <p:output port="result"/>

  <p:variable name="ex:document-info" as="function(*)" 
              select="function($d as item()) as xs:string
                      { p:document-property($d, 'content-type')
                        || ' at ' || p:document-property($d, 'base-uri') }"/>

  <p:identity>
    <p:with-input><doc/></p:with-input>
  </p:identity>

  <p:identity name="id" message="Seeing { $ex:document-info(.) }"/>

  <cx:pipeline-messages p:depends="id" level="info" clear="true"/>
</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='INFO' and contains(@message, 'Seeing application/xml')]"
                    >Did not find user message.</s:assert>
        </s:rule>
      </s:pattern>
    </s:schema>
  </t:schematron>
</t:test>
