<?xml version="1.0"?>
<!-- $Id: testSuite.rng 1776 2013-01-29 18:34:35Z snajper $ -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0" ns="">
	<!--
		target namespace is intentionally set to "" so as not to interfere with
		prefix/URI bindings
	-->
	
	<start>
		<ref name="testSuite"/>
	</start>
	
	<define name="testSuite">
		<!-- a test suite represents a set of tests -->
		<element name="testSuite">
			<ref name="header"/>
			<oneOrMore>
				<choice>
					<!-- testSuites can be nested -->
					<ref name="testSuite"/>
					<!-- a single test case -->
					<ref name="testCase"/>
					<!--
						resources are by itself a RELAX NG pattern, and it can be 
						referenced from other patterns through <externalRef/>
						the scope of the resources are global.
					-->
					<element name="resource">
						<attribute name="href">
							<data type="token" key="moduleName" />
						</attribute>
						<ref name="anyElement"/>
					</element>
				</choice>
			</oneOrMore>
		</element>
	</define>

	<define name="testCase">
		<element name="testCase">
			<ref name="header"/>
			
			<choice>
				<!-- An incorrect schema -->
				<element name="incorrect">
					<ref name="anyElement"/>
				</element>
				
				<!-- A correct schema and test cases -->
				<group>
					<element name="correct">
						<!-- Compatibilities of this schema with various features -->
						<optional>
							<attribute name="annotation">
								<ref name="ok.ng"/>
							</attribute>
						</optional>
						<optional>
							<attribute name="ididref">
								<ref name="ok.ng"/>
							</attribute>
						</optional>
						<optional>
							<attribute name="defaultValue">
								<ref name="ok.ng"/>
							</attribute>
						</optional>
						
						<externalRef href="relaxng.rng"/>
					</element>
					
					<oneOrMore>
						<choice>
							<!-- Valid test cases -->
							<element name="valid">
								<!-- The soundness of this document -->
								<optional>
									<attribute name="ididref">
										<ref name="ok.ng"/>
									</attribute>
								</optional>
								<ref name="anyElement"/>
							</element>
							<!-- Invalid test cases -->
							<element name="invalid">
								<ref name="anyElement"/>
							</element>
						</choice>
					</oneOrMore>
				</group>
			</choice>
		</element>
	</define>
	
	<define name="ok.ng">
		<choice>
			<value>ok</value>
			<value>ng</value>
		</choice>
	</define>
	
	
	<define name="any">
		<zeroOrMore>
			<choice>
				<ref name="anyElement"/>
				<attribute>
					<anyName/>
					<text/>
				</attribute>
				<text/>
			</choice>
		</zeroOrMore>
	</define>
	
	<define name="anyElement">
		<element>
			<anyName/>
			<ref name="any"/>
		</element>
	</define>
	
	
	<define name="header">
		<interleave>
				<!-- title of the test -->
				<optional>
					<element name="title">
						<text/>
					</element>
				</optional>
				
				<!-- description of the test -->
				<optional>
					<element name="documentation">
						<text/>
					</element>
				</optional>
				
				<!-- sections of the spec which the test is intended to test -->
				<zeroOrMore>
					<element name="section">
						<text/>
					</element>
				</zeroOrMore>
				
				<!-- other meta information -->
				<zeroOrMore>
					<element>
						<anyName>
							<except>
								<nsName/>
							</except>
						</anyName>
						<ref name="any"/>
					</element>
			</choice>
		</zeroOrMore>
	</define>
	
	<define name="resources">
		<zeroOrMore>
			<choice>
				<element name="resource">
					<attribute name="name">
						<ref name="pathSegment"/>
					</attribute>
					<ref name="anyElement"/>
				</element>
        <element name="dir">
          <attribute name="name">
            <ref name="pathSegment"/>
          </attribute>
          <ref name="resources"/>
        </element>
      </choice>
    </zeroOrMore>
  </define>


  <!-- A relative URI segment. -->
  
  <define name="pathSegment">
    <data datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
          type="string">
      <!-- one or more RFC 2396 pchars -->
      <param name="pattern">[-A-Za-z0-9:@&amp;=+$,_.!~*'()]+</param>
    </data>
  </define>
	
</grammar>
