<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
  <t:info>
    <t:title>validate-rng-001</t:title>
    <t:revision-history>
      <t:revision>
        <t:date>2025-01-10</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 RNG errors are reported in the XVRL.</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:p="http://www.w3.org/ns/xproc">
      <p:output port="result" pipe="report@validation"/>

      <p:validate-with-relax-ng name="validation" assert-valid="false">
        <p:with-input port="source">
          <doc id="foo bar">
            <q>This is a test</q>
          </doc>
        </p:with-input>
        <p:with-input port="schema" expand-text="false">
          <p:inline content-type="application/relax-ng-compact-syntax">
start = doc

doc = element doc {
          attribute id { xsd:NCName },
          attribute class { text }?,
          p+
      }

p = element p { text }
          </p:inline>
        </p:with-input>
      </p:validate-with-relax-ng>
      <p:sink/>
    </p:declare-step>
  </t:pipeline>
  <t:schematron>
    <s:schema queryBinding="xslt2"
              xmlns:s="http://purl.oclc.org/dsdl/schematron">
      <s:ns prefix="xvrl" uri="http://www.xproc.org/ns/xvrl"/>
      <s:pattern>
        <s:rule context="/">
          <s:assert test="xvrl:report">The result isn’t a report.</s:assert>
        </s:rule>
      </s:pattern>
      <s:pattern>
        <s:rule context="/xvrl:report">
          <s:assert test="xvrl:digest">The report doesn’t include a digest.</s:assert>
          <s:assert test="xvrl:detection[@severity='error']">The result doesn’t include an error</s:assert>
        </s:rule>
      </s:pattern>
      <s:pattern>
        <s:rule context="/xvrl:report/xvrl:metadata">
          <s:assert test="xvrl:timestamp">The metadata isn’t timestamped.</s:assert>
          <s:assert test="xvrl:validator">The metadata doesn’t include the validator.</s:assert>
          <s:assert test="xvrl:validator[@name='Jing']">The validator is unexpected.</s:assert>
          <s:assert test="xvrl:creator">The metadata doesn’t include the creator.</s:assert>
          <s:assert test="xvrl:creator[@name='XML Calabash']">The creator is unexpected.</s:assert>
          <s:assert test="xvrl:schema">The metadata doesn’t include the schema.</s:assert>
          <s:assert test="xvrl:schema[@schematypens='http://relaxng.org/ns/structure/1.0']">The schema type is unexpected.</s:assert>
        </s:rule>
      </s:pattern>
      <s:pattern>
        <s:rule context="/xvrl:report/xvrl:digest">
          <s:assert test="@warning-count=0">The warning count is wrong</s:assert>
          <s:assert test="@error-count=3">The error count is wrong</s:assert>
        </s:rule>
      </s:pattern>
    </s:schema>
  </t:schematron>
</t:test>
