<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
  <t:info>
    <t:title>try-catch-001</t:title>
    <t:revision-history>
      <t:revision>
        <t:date>2026-01-23</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 catch can receive multiple documents.</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:output port="result"/>
      <!-- h/t to Amanda Galtman for the test -->
      <p:try>
        <p:error name="my-error" code="ex:first-code">
          <p:with-input port="source">
            <p:inline><doc1/></p:inline>
            <p:inline><doc2/></p:inline>
            <p:inline><doc3/></p:inline>
          </p:with-input>
        </p:error>
        <p:catch name="catch">
          <p:identity>
            <p:with-input pipe="error@catch"/>
          </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:ns prefix="c" uri="http://www.w3.org/ns/xproc-step"/>
      <s:ns prefix="cx" uri="http://xmlcalabash.com/ns/extensions"/>
      <s:pattern>
        <s:rule context="/">
          <s:assert test="c:errors">The document is wrong</s:assert>
        </s:rule>
      </s:pattern>
      <s:pattern>
        <s:rule context="/c:errors">
          <s:assert test="count(c:error) = 1">Wrong number of errors</s:assert>
          <s:assert test="c:error/@name = 'my-error'">Wrong error</s:assert>
          <s:assert test="count(c:error/* except c:error/cx:*) = 3">Wrong number of documents</s:assert>
        </s:rule>
      </s:pattern>
    </s:schema>
  </t:schematron>
</t:test>
