require 'rdf/rdfxml'
require 'open-uri'
autoload :YAML, "yaml"
autoload :CGI, 'cgi'
RDFA_DIR = File.join(File.dirname(__FILE__), 'rdfa-test-suite')
RDFA_MANIFEST_URL = "http://rdfa.digitalbazaar.com/test-suite/"
RDFA_TEST_CASE_URL = "#{RDFA_MANIFEST_URL}test-cases/"
class SparqlException < IOError; end
module RdfaHelper
# Class representing test cases in format http://www.w3.org/2006/03/test-description#
class TestCase
HTMLRE = Regexp.new('([0-9]{4,4})\.xhtml')
TCPATHRE = Regexp.compile('\$TCPATH')
attr_accessor :about
attr_accessor :name
attr_accessor :contributor
attr_accessor :title
attr_accessor :informationResourceInput
attr_accessor :informationResourceResults
attr_accessor :purpose
attr_accessor :reviewStatus
attr_accessor :classification
attr_accessor :suite
attr_accessor :specificationReference
attr_accessor :expectedResults
attr_accessor :parser
attr_accessor :debug
@@suite = ""
def initialize(statements, suite)
self.suite = suite
self.expectedResults = true
statements.each do |statement|
next if statement.subject.is_a?(RDF::Node)
pred = statement.predicate.to_s.split(/[\#\/]/).last
obj = statement.object.is_a?(RDF::Literal) ? statement.object.value : statement.object.to_s
puts "#{pred}: #{obj}" if ::RDF::RDFa::debug?
unless self.about
self.about = statement.subject.to_s
self.name = self.about.to_s.split(/[\#\/]/).last || self.about
end
if pred == "expectedResults"
self.expectedResults = obj == "true"
#puts "expectedResults = #{statement.object.literal.value}"
elsif self.respond_to?("#{pred}=")
self.send("#{pred}=", obj)
end
end
end
def inspect
"[Test Case " + %w(
about
name
contributor
title
informationResourceInput
informationResourceResults
purpose
reviewStatus
classification
specificationReference
expectedResults
).map {|a| v = self.send(a); "#{a}='#{v}'" if v}.compact.join(", ") +
"]"
end
def status
reviewStatus.to_s.split("#").last
end
def compare; :graph; end
def information
%w(purpose specificationReference).map {|a| v = self.send(a); "#{a}: #{v}" if v}.compact.join("\n")
end
def tcpath
RDFA_TEST_CASE_URL + (suite == "xhtml" ? "xhtml1" : suite)
end
# Read in file, and apply modifications to create a properly formatted HTML
def input
f = self.inputDocument
found_head = false
namespaces = ""
body = File.readlines(File.join(RDFA_DIR, "tests", f)).map do |line|
found_head ||= line.match(/
\n) +
%(\n) +
%(\n#{body.gsub(TCPATHRE, tcpath)}\n"
when "html4"
head ="" +
%(\n) +
%(\n#{body.gsub(TCPATHRE, tcpath).gsub(HTMLRE, '\1.html')}\n"
when "html5"
head = "\n"
head += namespaces.empty? ? %() : ""
head + "\n#{body.gsub(TCPATHRE, tcpath).gsub(HTMLRE, '\1.html')}\n"
when "svgtiny"
head = %(\n)
head += namespaces.empty? ? %(