<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        features="xquery_3_1"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <t:info>
      <t:title>p:xquery 040 (AB)</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2026-10-29</t:date>
            <t:author>
               <t:name>Achim Berndzen</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Initial commit</p>
            </t:description>
         </t:revision>
      </t:revision-history>
   </t:info>
   <t:description xmlns="http://www.w3.org/1999/xhtml">
      <p>Tests types in xquery result are set correctly (Part 2)</p>
   </t:description>
   <t:pipeline>
      <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" 
         xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0"
         exclude-inline-prefixes="#all">
         <p:output port="result" sequence="true" serialization="map{'indent' : true()}"/>
         
         <p:xquery version="3.1" >
            <p:with-input port="source">
               <p:empty />
            </p:with-input>
            <p:with-input port="query" xml:base="http://xquery-uri">
               <p:inline content-type="text/plain">
                  declare namespace xs ="http://www.w3.org/2001/XMLSchema";
                  (xs:integer('42'), (:1:)
                  xs:nonPositiveInteger('-10'), (:2:)
                  xs:negativeInteger('-42'), (:3:)
                  xs:long('42'), (:4:)
                  xs:int('42'), (:5:)
                  xs:short('42'), (:6:)
                  xs:byte('42'), (:7:)
                  xs:nonNegativeInteger('42'), (:8:)
                  xs:unsignedLong('42'), (:9:)
                  xs:unsignedInt('42'), (:10:)
                  xs:unsignedShort('42'), (:11:)
                  xs:unsignedByte('42'), (:12:)
                  xs:positiveInteger('42') (:13:)
                 )
               </p:inline>
            </p:with-input>
         </p:xquery>
         
         <p:for-each>
            <p:choose>
               <p:when test="p:iteration-position()=1">
                  <p:identity>
                     <p:with-input><integer-test>{. instance of xs:integer}</integer-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=2">
                  <p:identity>
                     <p:with-input><nonPositiveInteger-test>{. instance of xs:nonPositiveInteger}</nonPositiveInteger-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=3">
                  <p:identity>
                     <p:with-input><negativeInteger-test>{. instance of xs:negativeInteger}</negativeInteger-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=4">
                  <p:identity>
                     <p:with-input><long-test>{. instance of xs:long}</long-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=5">
                  <p:identity>
                     <p:with-input><int-test>{. instance of xs:int}</int-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=6">
                  <p:identity>
                     <p:with-input><short-test>{. instance of xs:short}</short-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=7">
                  <p:identity>
                     <p:with-input><byte-test>{. instance of xs:byte}</byte-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=8">
                  <p:identity>
                     <p:with-input><nonNegativeInteger-test>{. instance of xs:nonNegativeInteger}</nonNegativeInteger-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=9">
                  <p:identity>
                     <p:with-input><unsignedLong-test>{. instance of xs:unsignedLong}</unsignedLong-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=10">
                  <p:identity>
                     <p:with-input><unsignedInt-test>{. instance of xs:unsignedInt}</unsignedInt-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=11">
                  <p:identity>
                     <p:with-input><unsignedShort-test>{. instance of xs:unsignedShort}</unsignedShort-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=12">
                  <p:identity>
                     <p:with-input><unsignedByte-test>{. instance of xs:unsignedByte}</unsignedByte-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=13">
                  <p:identity>
                     <p:with-input><positiveInteger-test>{. instance of xs:positiveInteger}</positiveInteger-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:otherwise>
                  <p:identity>
                     <p:with-input><unidentified-value /></p:with-input>
                  </p:identity>
               </p:otherwise>
            </p:choose>
         </p:for-each>
         <p:wrap-sequence wrapper="tests" />
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema queryBinding="xslt2"
                xmlns:s="http://purl.oclc.org/dsdl/schematron"
                xmlns="http://www.w3.org/1999/xhtml">
         <s:pattern>
            <s:rule context="/">
               <s:assert test="tests">Root element is not 'tests'.</s:assert>
               <s:assert test="count(tests/unidentified-value)=0">There are identified values. Please check pipeline.</s:assert>
               <s:assert test="tests/integer-test/text()='true'">document[1] is not xs:integer</s:assert>
               <s:assert test="tests/nonPositiveInteger-test/text()='true'">document[2] is not xs:nonPositiveInteger</s:assert>
               <s:assert test="tests/negativeInteger-test/text()='true'">document[3] is not xs:negativeInteger</s:assert>
               <s:assert test="tests/long-test/text()='true'">document[4] is not xs:long</s:assert>
               <s:assert test="tests/int-test/text()='true'">document[5] is not xs:int</s:assert>
               <s:assert test="tests/short-test/text()='true'">document[6] is not xs:short</s:assert>
               <s:assert test="tests/byte-test/text()='true'">document[7] is not xs:byte</s:assert>
               <s:assert test="tests/nonNegativeInteger-test/text()='true'">document[8] is not xs:nonNegativeInteger</s:assert>
               <s:assert test="tests/unsignedLong-test/text()='true'">document[9] is not xs:unsignedLong</s:assert>
               <s:assert test="tests/unsignedInt-test/text()='true'">document[10] is not xs:unsignedInt</s:assert>
               <s:assert test="tests/unsignedShort-test/text()='true'">document[11] is not xs:unsignedShort</s:assert>
               <s:assert test="tests/unsignedByte-test/text()='true'">document[12] is not xs:unsignedByte</s:assert>
               <s:assert test="tests/positiveInteger-test/text()='true'">document[13] is not xs:positiveInteger</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
</t:test>