Skip to content
This repository has been archived by the owner on Dec 21, 2017. It is now read-only.

Commit

Permalink
Updates for changes to RDFa 1.1 test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 15, 2010
1 parent 7823e9c commit 5f461e8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace :spec do
require 'rdf_helper'
require 'fileutils'

%w(xhtml xhtml11 html4 html5).each do |suite|
%w(xhtml html4 html5 svgtiny).each do |suite|
yaml = manifest_file = File.join(File.dirname(__FILE__), "spec", "#{suite}-manifest.yml")
FileUtils.rm_f(yaml)
RdfaHelper::TestCase.to_yaml(suite, yaml)
Expand Down
41 changes: 27 additions & 14 deletions spec/rdfa_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TestCase
attr_accessor :informationResourceResults
attr_accessor :purpose
attr_accessor :reviewStatus
attr_accessor :classification
attr_accessor :suite
attr_accessor :specificationReference
attr_accessor :expectedResults
Expand All @@ -36,7 +37,7 @@ def initialize(statements, suite)
next if statement.subject.is_a?(BNode)
#next unless statement.subject.uri.to_s.match(/0001/)
unless self.about
self.about = Addressable::URI.parse(statement.subject.uri.to_s)
self.about = statement.subject.uri.to_s
self.name = statement.subject.short_name || self.about
end

Expand All @@ -60,6 +61,7 @@ def inspect
informationResourceResults
purpose
reviewStatus
classification
specificationReference
expectedResults
).map {|a| v = self.send(a); "#{a}='#{v}'" if v}.compact.join(", ") +
Expand Down Expand Up @@ -90,6 +92,7 @@ def input
if found_head
line.chop
else
found_head ||= line.match(%r(http://www.w3.org/2000/svg))
namespaces << line
nil
end
Expand All @@ -99,26 +102,25 @@ def input

case suite
when "xhtml"
head = "" +
%(<?xml version="1.0" encoding="UTF-8"?>\n) +
%(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">\n) +
%(<html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.0"\n)
head + "#{namespaces}>\n#{body.gsub(TCPATHRE, tcpath)}\n</html>"
when "xhtml11"
head = "" +
%(<?xml version="1.0" encoding="UTF-8"?>\n) +
%(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">\n) +
%(<html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"\n)
%(<html xmlns="http://www.w3.org/1999/xhtml"\n)
head + "#{namespaces}>\n#{body.gsub(TCPATHRE, tcpath)}\n</html>"
when "html4"
head ="" +
%(<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n) +
%(<html version="XHTML+RDFa 1.0"\n)
%(<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/MarkUp/DTD/html401-rdfa11-1.dtd">\n) +
%(<html\n)
head + "#{namespaces}>\n#{body.gsub(TCPATHRE, tcpath).gsub(HTMLRE, '\1.html')}\n</html>"
when "html5"
head = "<!DOCTYPE html>\n"
head += namespaces.empty? ? %(<html version="HTML+RDFa 1.0">) : "<html\n#{namespaces}>"
head += namespaces.empty? ? %(<html>) : "<html\n#{namespaces}>"
head + "\n#{body.gsub(TCPATHRE, tcpath).gsub(HTMLRE, '\1.html')}\n</html>"
when "svgtiny"
head = "" +
%(<?xml version="1.0" encoding="UTF-8"?>\n)
head += namespaces.empty? ? %(<svg>) : "<svg\n#{namespaces}>"
head + "\n#{body.gsub(TCPATHRE, tcpath).gsub(HTMLRE, '\1.svg')}\n</svg>"
else
nil
end
Expand All @@ -129,20 +131,28 @@ def results
f = self.name + ".sparql"
body = File.read(File.join(RDFA_DIR, "tests", f)).gsub(TCPATHRE, tcpath)

suite =~ /xhtml/ ? body : body.gsub(HTMLRE, '\1.html')
case suite
when /xhtml/ then body
when /svg/ then body.gsub(HTMLRE, '\1.svg')
else body.gsub(HTMLRE, '\1.html')
end
end

def triples
f = self.name + ".nt"
body = File.read(File.join(RDFA_NT_DIR, f)).gsub(TCPATHRE, tcpath)
suite =~ /xhtml/ ? body : body.gsub(HTMLRE, '\1.html')
case suite
when /xhtml/ then body
when /svg/ then body.gsub(HTMLRE, '\1.svg')
else body.gsub(HTMLRE, '\1.html')
end
end

def inputDocument; self.name + ".txt"; end
def outputDocument; self.name + ".sparql"; end

def version
suite == "xhtml11" ? :rdfa_1_1 : :rdfa_1_0
:rdfa_1_1
end

# Run test case, yields input for parser to create triples
Expand Down Expand Up @@ -185,6 +195,7 @@ def self.test_cases(suite)
yaml_file = File.join(File.dirname(__FILE__), "#{suite}-manifest.yml")

@test_cases = unless File.file?(yaml_file)
t = Time.now
puts "parse #{manifest_file} @#{Time.now}"
parser = RdfXmlParser.new

Expand All @@ -194,6 +205,8 @@ def self.test_cases(suite)
raise "Parse error: #{$!}\n\t#{parser.debug.to_a.join("\t\n")}\n\n"
end
graph = parser.graph
diff = Time.now - t
puts "parsed #{graph.size} statements in #{diff} seconds (#{(graph.size / diff).to_i} statements/sec) @#{Time.now}"

# Group by subject
test_hash = graph.triples.inject({}) do |hash, st|
Expand Down
45 changes: 37 additions & 8 deletions spec/rdfa_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,29 +219,58 @@ def self.test_cases(suite)
end

# W3C Test suite from http://www.w3.org/2006/07/SWD/RDFa/testsuite/
%w(xhtml xhtml11).each do |suite| #html4 html5
%w(xhtml html5 html5 svgtiny).each do |suite| #html4 html5
describe "w3c #{suite} testcases" do
describe "that are approved" do
describe "that are required" do
test_cases(suite).each do |t|
next unless t.status == "approved"
#next unless t.name =~ /0140/
#puts t.inspect
next unless t.classification =~ /required/
#next unless t.name =~ /0001/
specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
#puts t.input
#puts t.results
begin
t.run_test do |rdfa_string, rdfa_parser|
rdfa_parser.parse(rdfa_string, t.informationResourceInput, :debug => [], :version => t.version)
end
rescue RSpec::Expectations::ExpectationNotMetError => e
if t.input =~ /XMLLiteral/
pending("XMLLiteral canonicalization not implemented yet")
else
raise
end
rescue SparqlException => e
pending(e.message) { raise }
end
end
end
end
describe "that are unreviewed" do

describe "that are optional" do
test_cases(suite).each do |t|
next unless t.classification =~ /optional/
#next unless t.name =~ /0185/
#puts t.inspect
specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
begin
t.run_test do |rdfa_string, rdfa_parser|
rdfa_parser.parse(rdfa_string, t.informationResourceInput, :debug => [], :version => t.version)
end
rescue SparqlException => e
pending(e.message) { raise }
rescue RSpec::Expectations::ExpectationNotMetError => e
if t.name =~ /01[789]\d/
raise
else
pending() { raise }
end
end
end
end
end

describe "that are buggy" do
test_cases(suite).each do |t|
next unless t.status == "unreviewed"
next unless t.classification =~ /buggy/
#next unless t.name =~ /0185/
#puts t.inspect
specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
Expand All @@ -251,7 +280,7 @@ def self.test_cases(suite)
end
rescue SparqlException => e
pending(e.message) { raise }
rescue Spec::Expectations::ExpectationNotMetError => e
rescue RSpec::Expectations::ExpectationNotMetError => e
if t.name =~ /01[789]\d/
raise
else
Expand Down

0 comments on commit 5f461e8

Please sign in to comment.