Updated tests with update_index.rb script to parse test files and update index.
authorGregg Kellogg <gregg@kellogg-assoc.com>
Fri, 02 Mar 2012 13:09:04 -0800
changeset 110 1cd1d2028e68
parent 106 d3203d625b7a
child 111 4efcf02d36c3
Updated tests with update_index.rb script to parse test files and update index.
microdata-rdf/tests/0001.html
microdata-rdf/tests/index.html
microdata-rdf/tests/test-registry.json
microdata-rdf/tests/update_index.rb
--- a/microdata-rdf/tests/0001.html	Thu Mar 01 14:34:57 2012 -0800
+++ b/microdata-rdf/tests/0001.html	Fri Mar 02 13:09:04 2012 -0800
@@ -1,14 +1,17 @@
 <!DOCTYPE html>
 <html>
-  <head itemscope itemtype="http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#ManifestEntry">
-    <title>
+  <head>
+    <title itemscope itemtype="http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#ManifestEntry">
       <span itemprop="name">Test 0001</span>:
       <span itemprop="http://www.w3.org/2000/01/rdf-schema#comment">Item with no itemtype and literal itemprop</span>
+      (
       <span itemprop="action" itemscope itemtype="http://www.w3.org/2001/sw/DataAccess/tests/test-query#QueryTest">
-        <link itemprop="query" href="0001.rq"/>
-        <link itemprop="data" href="0001.html"/>
+        <a itemprop="data" href="0001.html">input</a> |
+        <a itemprop="query" href="0001.rq">query</a>
       </span>
+      <a itemprop="registry" href="test-registry.json">registry</a>
       <meta itemprop="result" content="true"/>
+      )
     </title>
   </head>
   <body>
--- a/microdata-rdf/tests/index.html	Thu Mar 01 14:34:57 2012 -0800
+++ b/microdata-rdf/tests/index.html	Fri Mar 02 13:09:04 2012 -0800
@@ -1,29 +1,204 @@
 <!DOCTYPE html>
 <html>
 <head>
-  <title>Microdata to RDF Tests</title>
-  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
-</head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Microdata to RDF Tests</title>
+<!--
+  === NOTA BENE ===
+  For the three scripts below, if your spec resides on dev.w3 you can check them
+  out in the same tree and use relative links so that they'll work offline,
+  --><script type="text/javascript" src="http://dev.w3.org/2009/dap/ReSpec.js/js/respec.js" class="remove">
+ </script><script type="text/javascript" class="remove">
 
+    var preProc = {
+        apply:  function(c) {
+                    // extend the bibliography entries
+                    berjon.biblio["MICRODATA-RDF"] = "<cite><a href=\"http://www.w3.org/TR/microdata-rdf/\">Microdata to RDF</a></cite> Gregg Kellogg Editor. World Wide Web Consortium (work in progress). 12 January 2011. This edition of the Microdata to RDF specification is http://www.w3.org/TR/2012/WD-microdata-rdf-20120112/. The <a href=\"http://www.w3.org/TR/2012/WD-microdata-rdf-20120112/\">latest edition of Microdata to RDF</a> is available at http://www.w3.org/TR/microdata-rdf/";
+                }
+        } ;
+
+      var respecConfig = {
+          // specification status (e.g. WD, LCWD, NOTE, etc.). If in doubt use ED.
+          specStatus:           "unofficial",
+          charterDisclosureURI: "http://www.w3.org/2006/07/swig-charter#Ipr",
+          //publishDate:          "2012-02-13",
+          //copyrightStart:       "2011",
+
+          // the specification's short name, as in http://www.w3.org/TR/short-name/
+          shortName:            "microdata-rdf-tests",
+          subtitle:             "Test suite for microdata to RDF",
+
+          edDraftURI:           "https://dvcs.w3.org/hg/htmldata/raw-file/default/microdata-rdf/tests/index.html",
+
+          // if this is a LCWD, uncomment and set the end of its review period
+          // lcEnd: "2009-08-05",
+
+          // if you want to have extra CSS, append them to this list
+          // it is recommended that the respec.css stylesheet be kept
+          extraCSS:             [
+              "http://dev.w3.org/2009/dap/ReSpec.js/css/respec.css"
+          ],
+
+          // editors, add as many as you like
+          // only "name" is required
+          editors:  [
+              { name: "Gregg Kellogg", url: "http://greggkellogg.net/",
+                company: "Kellogg Associates" },
+              { name: "Iván Herman", url: "http://www.w3.org/People/Ivan/",
+                company: "W3C", companyURL: "http://www.w3.org" }
+          ],
+
+          // authors, add as many as you like.
+          // This is optional, uncomment if you have authors as well as editors.
+          // only "name" is required. Same format as editors.
+
+          //authors:  [],
+
+          // name of the WG
+          wg:           "HTML Data Task Force, Semantic Web Interest Group",
+
+          // URI of the public WG page
+          wgURI:        "http://www.w3.org/2001/sw/interest/",
+
+          // name (with the @w3c.org) of the public mailing to which comments are due
+          wgPublicList: "public-html-data-tf",
+
+          // URI of the patent status for this WG, for Rec-track documents
+          // !!!! IMPORTANT !!!!
+          // This is important for Rec-track documents, do not copy a patent URI from a random
+          // document unless you know what you're doing. If in doubt ask your friendly neighbourhood
+          // Team Contact.
+          wgPatentURI:  "",
+          maxTocLevel: 4,
+          preProcess: [ preProc ]
+          //alternateFormats: [ {uri: "diff-20111118.html", label: "diff to previous version"} ],
+      };
+
+      function updateExample(doc, content) {
+        // perform transformations to make it render and prettier
+        content = content.replace(/<!--/, '');
+        content = content.replace(/-->/, '');
+        content = doc._esc(content);
+        content = content.replace(/\*\*\*\*([^*]*)\*\*\*\*/g, '<span class="diff">$1</span>') ;
+        return content ;
+      }
+
+      function updateDTD(doc, content) {
+        // perform transformations to
+        // make it render and prettier
+        content = '<pre class="dtd">' + doc._esc(content) + '</pre>';
+        content = content.replace(/!ENTITY % ([^ \t\r\n]*)/g, '!ENTITY <span class="entity">% $1</span>');
+        content = content.replace(/!ELEMENT ([^ \t$]*)/mg, '!ELEMENT <span class="element">$1</span>');
+        return content;
+      }
+
+      function updateSchema(doc, content) {
+        // perform transformations to
+        // make it render and prettier
+        content = '<pre class="dtd">' + doc._esc(content) + '</pre>';
+        content = content.replace(/&lt;xs:element\s+name=&quot;([^&]*)&quot;/g, '&lt;xs:element name="<span class="element" id="schema_element_$1">$1</span>"') ;
+        return content;
+      }
+
+      function updateTTL(doc, content) {
+        // perform transformations to
+        // make it render and prettier
+        content = '<pre class="sh_sourceCode">' + doc._esc(content) + '</pre>';
+        content = content.replace(/@prefix/g, '<span class="sh_keyword">@prefix</span>');
+        return content;
+      }
+  </script><style type="text/css">
+.diff { font-weight:bold; color:#0a3; }
+ol.algorithm { counter-reset:numsection; list-style-type: none; }
+ol.algorithm li { margin: 0.5em 0; }
+ol.algorithm li:before {
+  font-weight: bold;
+  counter-increment: numsection;
+  content: counters(numsection, ".") ") ";
+}
+dl.triple { padding: 0 0 0 1em; }
+dl.triple dt, dl.triple dd { margin: 0; display: inline }
+dl.triple dt:after { content: ':'; }
+dl.triple dd:after { content: '\A'; white-space: pre; }
+.adef { 
+	font-family: monospace; 
+	font-weight: bold; 
+    color: #ff4500 !important;
+}
+
+.aref { 
+	font-family: monospace; 
+	font-weight: bold; 
+    color: #ff4500 !important;
+}
+
+span.entity { color: red; }
+
+span.element { color: green; }
+span[itemprop=name] { font-weight: bold; }
+</style>
+</head>
 <body>
-<section id="abstract">
-  <p>This document serves as the manifest describing [[MICRODATA-RDF]] tests to be used by
+<section id="abstract"><p>This document serves as the manifest describing [[MICRODATA-RDF]] tests to be used by
     processor implementations claiming conformance.</p>
+</section><section><h2>Running tests</h2>
   <p>Tests are described with individual HTML files containing microdata, which when processed,
     will either pass or fail a SPARQL ASK query associated with the test. <a href="#positive-tests">Positive processor
     tests</a> tests MUST yield a value of <code>true</code> and <a href="#negative-tests">Negative processor tests</a>
     MUST yield a value of <code>false</code>.</p>
   <p>All tests should be performed with an assumed base of <code>http://www.w3.org/TR/microdata-rdf/tests/</code>
     along with the base-name of the specific test document (excluding any format extension).</p>
-</section>
+  <p>This document serves as the test manifest for both positive and negative parser tests using the
+    <a href="http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#">Data Access Test Manifest</a>
+    and <a href="http://www.w3.org/2001/sw/DataAccess/tests/test-query#">Data Access Test Query</a> vocabularies.</p>
+  <p>Properly parsing this document with a conforming Microdata to RDF processor, as well as the individual
+    test cases requires that the processor use the <a href="test-registry.json">Test Registry</a>. Additionally,
+    individual tests may require that the processor use a different registry using the
+    an additional <code>registry</code> property, indicating the URL of a registry to load to run the test,
+    typically a file co-located and numbered along with the test itself.</p>
+  <section><h3>Example Test Entry</h3>
+    <p>An example test entry parsed from this manifest might have the following form:</p>
+<pre class="example" data-transform="updateExample">
+<!--
[email protected] rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
[email protected] rdfs:	<http://www.w3.org/2000/01/rdf-schema#> .
[email protected] mf:     <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
[email protected] qt:     <http://www.w3.org/2001/sw/DataAccess/tests/test-query#> .
 
-<section id="positive-tests">
-  <h2>Positive processor tests</h2>
+[ rdf:type mf:Manifest ;
+  rdfs:comment "Turtle good syntax test cases (must pass)" ;
+  mf:entries (
+    [ a mf:ManifestEntry;
+      mf:name "Test 0001";
+      rdfs:comment  "Item with no itemtype and literal itemprop";
+      mf:action [
+        a qt:QueryTest;
+        qt:data <0001.html>;
+        qt:query <0001.rq>;
+      ];
+      mf:registry <test-registry.json>;
+      mf:result "true"
+    ]
+  )
+] .
+-->
+</pre>
+</section></section><section id="positive-tests" itemscope itemtype="http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#Manifest"><h2 itemprop="http://www.w3.org/2000/01/rdf-schema#comment">Positive processor tests</h2>
+  
+
+<div itemscope itemtype="http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#ManifestEntry" itemprop="entries" class="test-entry">
+<span itemprop="name">Test 0001</span>:
+      <span itemprop="http://www.w3.org/2000/01/rdf-schema#comment">Item with no itemtype and literal itemprop</span>
+      (
+      <span itemprop="action" itemscope itemtype="http://www.w3.org/2001/sw/DataAccess/tests/test-query#QueryTest">
+        <a itemprop="data" href="0001.html">input</a> |
+        <a itemprop="query" href="0001.rq">query</a>
+      </span>
+      <a itemprop="registry" href="test-registry.json">registry</a>
+      <meta itemprop="result" content="true">
+      )
+    </div></section><section id="negative-tests" itemscope itemtype="http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#Manifest"><h2 itemprop="http://www.w3.org/2000/01/rdf-schema#comment">Negative processor tests</h2>
+  
 </section>
-
-<section id="negative-tests">
-  <h2>Negative processor tests</h2>
-</section>
-
 </body>
 </html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/microdata-rdf/tests/test-registry.json	Fri Mar 02 13:09:04 2012 -0800
@@ -0,0 +1,45 @@
+{
+  "@comment": "This registry defines several artificial vocabularies used when running tests in the microdata to RDF test suite",
+  "http://vocabulary.unordered/": {
+    "propertyURI":    "vocabulary",
+    "multipleValues": "unordered",
+    "properties": {
+      "list": {"multipleValues": "list"},
+      "ordered": {"multipleValues": "ordered"},
+      "typed": {"daetatype": "http://typed"}
+    }
+  },
+  "http://vocabulary.list/": {
+    "propertyURI":    "vocabulary",
+    "multipleValues": "list",
+    "properties": {
+      "list": {"multipleValues": "list"},
+      "ordered": {"multipleValues": "ordered"},
+      "typed": {"daetatype": "http://typed"}
+    }
+  },
+  "http://contextual.unordered/": {
+    "propertyURI":    "contextual",
+    "multipleValues": "unordered",
+    "properties": {
+      "list": {"multipleValues": "list"},
+      "ordered": {"multipleValues": "ordered"},
+      "typed": {"daetatype": "http://typed"}
+    }
+  },
+  "http://contextual.list/": {
+    "propertyURI":    "contextual",
+    "multipleValues": "list",
+    "properties": {
+      "list": {"multipleValues": "list"},
+      "ordered": {"multipleValues": "ordered"},
+      "typed": {"daetatype": "http://typed"}
+    }
+  },
+  "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#": {
+    "properties": {
+      "include": {"multipleValues": "list"},
+      "entries": {"multipleValues": "list"}
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/microdata-rdf/tests/update_index.rb	Fri Mar 02 13:09:04 2012 -0800
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+# Processing the index file replacing test entries from tests found within this directory.
+
+require 'rubygems'
+require 'nokogiri'
+require 'getoptlong'
+
+def run(file, options)
+  index = Nokogiri::HTML.parse(file)
+  
+  # Remove existing tests
+  index.css("div.test-entry").remove
+
+  # Find Positive and Negative insertion points
+  pos_entries = index.at_css("section#positive-tests")
+  neg_entries = index.at_css("section#negative-tests")
+
+  num_pos = num_neg = 0
+
+  Dir.glob("*.html").each do |test_file|
+    next unless test_file =~ /^\d+\.html$/
+    test = Nokogiri::HTML.parse(File.open(test_file))
+    
+    # Extract head, replace as div.test-entry
+    test_info = test.at_css('title')
+    test_info.name = "div"
+    test_info['itemprop'] = 'entries'
+    test_info['class'] = 'test-entry'
+    test_info.css("title")
+    result = test_info.at_css("[itemprop=result]")
+    if !result || result['content'].downcase == 'true'
+      # Add entry to index
+      num_pos += 1
+      pos_entries.add_child(test_info)
+    else
+      num_neg += 1
+      neg_entries.add_child(test_info)
+    end
+  end
+  options[:output].puts index.to_s
+end
+
+options = {
+  :output => STDOUT,
+}
+input = nil
+opts = GetoptLong.new(
+  ["--output", "-o", GetoptLong::REQUIRED_ARGUMENT],
+)
+opts.each do |opt, arg|
+  case opt
+  when '--output'       then options[:output] = File.open(arg, "w")
+  end
+end
+
+if ARGV.empty?
+  run($stdin, options)
+else
+  run(Kernel.open(ARGV.first), options)
+end