<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/rdf-srj-002.xml"
        name="rdf-srj-002.xml"
        expected="pass">
   <t:info>
      <t:title>rdf-srj-002</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2025-02-15</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 cx:sparql can produce application/sparql-results+json.</p>
   </t:description>
   <t:pipeline>
      <p:declare-step xmlns:cx="http://xmlcalabash.com/ns/extensions"
                      xmlns:p="http://www.w3.org/ns/xproc"
                      name="main"
                      version="3.0"
                      expand-text="false">
         <p:import href="https://xmlcalabash.com/ext/library/rdf.xpl"/>
         <p:output port="result"/>
         <cx:sparql content-type="application/sparql-results+json">
            <p:with-input port="source" href="../documents/address-book.rdf"/>
            <p:with-input port="query" href="../documents/query2.rq"/>
         </cx:sparql>
         <p:cast-content-type content-type="application/xml"/>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
         <s:ns prefix="fn" uri="http://www.w3.org/2005/xpath-functions"/>
         <s:pattern>
            <s:rule context="/">
               <s:assert test="fn:map">The root is not a map.</s:assert>
               <s:assert test="fn:map/fn:map[@key='head']">There is no head</s:assert>
               <s:assert test="fn:map/fn:map[@key='results']">There are no results</s:assert>
            </s:rule>
         </s:pattern>
         <s:pattern>
            <s:rule context="fn:map/fn:map[@key='head']">
               <s:assert test="fn:array">The head isn’t an array</s:assert>
               <s:assert test="count(fn:array/fn:string) = 3">Wrong number of columns</s:assert>
               <s:assert test="fn:array/fn:string = 'category'">No category.</s:assert>
               <s:assert test="fn:array/fn:string = 'name'">No name.</s:assert>
               <s:assert test="fn:array/fn:string = 'locality'">No locality.</s:assert>
            </s:rule>
         </s:pattern>
         <s:pattern>
            <s:rule context="fn:map/fn:map[@key='results']">
               <s:assert test="fn:array">The results isn’t an array</s:assert>
               <s:assert test="count(fn:array/fn:map) = 13">Wrong number of columns</s:assert>
               <s:assert test="fn:array/fn:map/fn:map/fn:string = 'Patina'">One of the expected results is missing.</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="rdf-srj-002.xml">
      <map xmlns="http://www.w3.org/2005/xpath-functions">
         <map key="head">
            <array key="vars">
               <string>category</string>
               <string>name</string>
               <string>locality</string>
            </array>
         </map>
         <map key="results">
            <array key="bindings">
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">San Francisco</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Timo’s</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Palo Alto</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Tamarine Restaurant</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Los Angeles</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Patina</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">San Francisco</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Masa’s Restaurant</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Oakland</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Luka’s Taproom &amp; Lounge</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">San Jose</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Le Papillon</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">San Carlos</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Kabul Afghan Cuisine</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">San Jose</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">71 Saint Peter</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Oakland</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">À Côté</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Mountain View</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Amber Indian Restaurant</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">San Francisco</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Boulevard</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">San Francisco</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Charles Nob Hill</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
               <map>
                  <map key="locality">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">San Francisco</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="name">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">El Farolito</string>
                     <string key="type">literal</string>
                  </map>
                  <map key="category">
                     <string key="datatype">http://www.w3.org/2001/XMLSchema#string</string>
                     <string key="value">Restaurants</string>
                     <string key="type">literal</string>
                  </map>
               </map>
            </array>
         </map>
      </map>
   </t:result>
</t:test>
