<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
  <t:info>
    <t:title>jsonpath-002</t:title>
    <t:revision-history>
      <t:revision>
        <t:date>2025-05-11</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 a JSONPath indefinite query.</p>
  </t:description>
  <t:pipeline>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:cx="http://xmlcalabash.com/ns/extensions"
                name="main" version="3.0" expand-text="false">
  <p:import href="https://xmlcalabash.com/ext/library/jsonpath.xpl"/>
  <p:output port="result"/>

  <cx:jsonpath query="$..book[1].author">
    <p:with-input href="../documents/find/bookstore.json"/>
  </cx:jsonpath>

  <p:cast-content-type content-type="application/xml"/>
</p:declare-step>
  </t:pipeline>
  <t:schematron>
    <s:schema queryBinding="xslt2"
              xmlns:s="http://purl.oclc.org/dsdl/schematron">
      <s:ns prefix="fn" uri="http://www.w3.org/2005/xpath-functions"/>
      <s:pattern>
        <s:rule context="/">
          <s:assert test="fn:array">The root is not an array.</s:assert>
        </s:rule>
        <s:rule context="fn:array">
          <s:assert test="count(*) = 1">Wrong number of results.</s:assert>
          <s:assert test="fn:string = 'Evelyn Waugh'">The author is incorrect.</s:assert>
        </s:rule>
      </s:pattern>
    </s:schema>
  </t:schematron>
</t:test>
