rdf-rdfa 0.0.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +8 -0
- data/README.rdoc +1 -3
- data/Rakefile +27 -4
- data/VERSION +1 -1
- data/lib/rdf/rdfa.rb +2 -0
- data/lib/rdf/rdfa/patches/literal_hacks.rb +147 -0
- data/lib/rdf/rdfa/patches/uri_hacks.rb +19 -0
- data/lib/rdf/rdfa/reader.rb +43 -32
- data/lib/rdf/rdfa/version.rb +2 -2
- data/rdf-rdfa.gemspec +27 -14
- data/script/tc +44 -0
- data/spec/html4-manifest.yml +5113 -0
- data/spec/html5-manifest.yml +5113 -0
- data/spec/matchers.rb +18 -52
- data/spec/rdfa-triples/0011.nt +1 -1
- data/spec/rdfa-triples/0092.nt +1 -1
- data/spec/rdfa-triples/0094.nt +1 -1
- data/spec/rdfa-triples/0100.nt +1 -3
- data/spec/rdfa-triples/0101.nt +1 -3
- data/spec/rdfa-triples/0102.nt +1 -1
- data/spec/rdfa-triples/0103.nt +1 -1
- data/spec/rdfa_helper.rb +62 -35
- data/spec/rdfa_reader_spec.rb +61 -32
- data/spec/spec_helper.rb +49 -0
- data/spec/xhtml-manifest.yml +4504 -0
- metadata +45 -27
data/spec/matchers.rb
CHANGED
@@ -2,51 +2,16 @@ module Matchers
|
|
2
2
|
class BeEquivalentGraph
|
3
3
|
Info = Struct.new(:about, :information, :trace, :compare, :inputDocument, :outputDocument)
|
4
4
|
def normalize(graph)
|
5
|
-
case
|
6
|
-
when
|
7
|
-
|
8
|
-
|
9
|
-
graph = graph.graph if graph.respond_to?(:graph)
|
10
|
-
anon = "a"
|
11
|
-
anon_ctx = {}
|
12
|
-
graph.triples.collect {|triple| triple.to_ntriples }.each do |t|
|
13
|
-
t.gsub(/_:nbn\d+[a-z]+N/, "_:").
|
14
|
-
gsub!(/_:bn\d+[a-z]+/) do |bn|
|
15
|
-
# Normalize anon BNodes
|
16
|
-
if anon_ctx[bn]
|
17
|
-
anon_ctx[bn]
|
18
|
-
else
|
19
|
-
anon_ctx[bn] = anon
|
20
|
-
anon = anon.succ
|
21
|
-
end
|
22
|
-
"_:#{anon_ctx[bn]}"
|
23
|
-
end
|
24
|
-
end.sort
|
25
|
-
when Array
|
26
|
-
graph.sort
|
27
|
-
else
|
28
|
-
graph.to_s.split("\n").
|
29
|
-
map {|t| t.gsub(/^\s*(.*)\s*$/, '\1')}.
|
30
|
-
reject {|t2| t2.match(/^\s*$/)}.
|
31
|
-
compact.
|
32
|
-
sort.
|
33
|
-
uniq
|
34
|
-
end
|
35
|
-
|
36
|
-
# Implement to_ntriples on array, to simplify logic later
|
37
|
-
def array.to_ntriples; self.join("\n") + "\n"; end
|
38
|
-
array
|
5
|
+
case graph
|
6
|
+
when RDF::Graph then graph
|
7
|
+
when IO, StringIO
|
8
|
+
RDF::Graph.new.load(graph, :base_uri => @info.about)
|
39
9
|
else
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
else
|
46
|
-
parser = Parser.new(:struct => true)
|
47
|
-
fmt = parser.detect_format(graph.to_s)
|
48
|
-
parser.parse(graph.to_s, @info.about, :type => fmt)
|
49
|
-
end
|
10
|
+
# Figure out which parser to use
|
11
|
+
g = RDF::Graph.new
|
12
|
+
reader_class = detect_format(graph)
|
13
|
+
reader_class.new(graph, :base_uri => @info.about).each {|s| g << s}
|
14
|
+
g
|
50
15
|
end
|
51
16
|
end
|
52
17
|
|
@@ -54,10 +19,12 @@ module Matchers
|
|
54
19
|
@info = if info.respond_to?(:about)
|
55
20
|
info
|
56
21
|
elsif info.is_a?(Hash)
|
57
|
-
identifier = info[:identifier] || expected.is_a?(Graph) ? expected.
|
58
|
-
|
22
|
+
identifier = info[:identifier] || expected.is_a?(RDF::Graph) ? expected.context : info[:about]
|
23
|
+
trace = info[:trace]
|
24
|
+
trace = trace.join("\n") if trace.is_a?(Array)
|
25
|
+
Info.new(identifier, info[:information] || "", trace, info[:compare])
|
59
26
|
else
|
60
|
-
Info.new(expected.is_a?(Graph) ? expected.
|
27
|
+
Info.new(expected.is_a?(RDF::Graph) ? expected.context : info, info.to_s)
|
61
28
|
end
|
62
29
|
@expected = normalize(expected)
|
63
30
|
end
|
@@ -68,15 +35,13 @@ module Matchers
|
|
68
35
|
end
|
69
36
|
|
70
37
|
def failure_message_for_should
|
71
|
-
info = @info.respond_to?(:information) ? @info.information :
|
72
|
-
if @expected.is_a?(Graph) && @actual.size != @expected.size
|
38
|
+
info = @info.respond_to?(:information) ? @info.information : @info.inspect
|
39
|
+
if @expected.is_a?(RDF::Graph) && @actual.size != @expected.size
|
73
40
|
"Graph entry count differs:\nexpected: #{@expected.size}\nactual: #{@actual.size}"
|
74
41
|
elsif @expected.is_a?(Array) && @actual.size != @expected.length
|
75
42
|
"Graph entry count differs:\nexpected: #{@expected.length}\nactual: #{@actual.size}"
|
76
|
-
elsif @expected.is_a?(Graph) && @actual.identifier != @expected.identifier
|
77
|
-
"Graph identifiers differ:\nexpected: #{@expected.identifier}\nactual: #{@actual.identifier}"
|
78
43
|
else
|
79
|
-
"Graph differs
|
44
|
+
"Graph differs"
|
80
45
|
end +
|
81
46
|
"\n#{info + "\n" unless info.empty?}" +
|
82
47
|
(@info.inputDocument ? "Input file: #{@info.inputDocument}\n" : "") +
|
@@ -101,6 +66,7 @@ module Matchers
|
|
101
66
|
@expected = expected
|
102
67
|
@query = Redland::Query.new(expected)
|
103
68
|
@info = info
|
69
|
+
#puts "PassQuery: expected #{expected.inspect}"
|
104
70
|
end
|
105
71
|
def matches?(actual)
|
106
72
|
@actual = actual
|
data/spec/rdfa-triples/0011.nt
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
<$TCPATH/0011.xhtml> <http://purl.org/dc/elements/1.1/creator> "Albert Einstein" .
|
2
2
|
# This is one of the allowed result XML Literals
|
3
|
-
<$TCPATH/0011.xhtml> <http://purl.org/dc/elements/1.1/title> "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\"
|
3
|
+
<$TCPATH/0011.xhtml> <http://purl.org/dc/elements/1.1/title> "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
|
data/spec/rdfa-triples/0092.nt
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
<$TCPATH/0092.xhtml> <http://purl.org/dc/elements/1.1/creator> "Albert Einstein" .
|
2
2
|
# One of the allowed results
|
3
|
-
<$TCPATH/0092.xhtml> <http://purl.org/dc/elements/1.1/title> "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\"
|
3
|
+
<$TCPATH/0092.xhtml> <http://purl.org/dc/elements/1.1/title> "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
|
data/spec/rdfa-triples/0094.nt
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
<$TCPATH/0094.xhtml> <http://purl.org/dc/elements/1.1/creator> "Albert Einstein" .
|
2
2
|
# One of the allowed results
|
3
|
-
<$TCPATH/0094.xhtml> <http://purl.org/dc/elements/1.1/title> "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\"
|
3
|
+
<$TCPATH/0094.xhtml> <http://purl.org/dc/elements/1.1/title> "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
|
data/spec/rdfa-triples/0100.nt
CHANGED
@@ -1,3 +1 @@
|
|
1
|
-
<http://www.example.org> <http://example.org/rdf/example> "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\"
|
2
|
-
# Another
|
3
|
-
# <http://www.example.org> <http://example.org/rdf/example> "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\">bold</strong> and an svg rectangle: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
|
1
|
+
<http://www.example.org> <http://example.org/rdf/example> "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\">bold</strong> and an svg rectangle: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
|
data/spec/rdfa-triples/0101.nt
CHANGED
@@ -1,3 +1 @@
|
|
1
|
-
<http://www.example.org> <http://example.org/rdf/example> "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\"
|
2
|
-
# Another
|
3
|
-
# <http://www.example.org> <http://example.org/rdf/example> "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"fr\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
|
1
|
+
<http://www.example.org> <http://example.org/rdf/example> "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"fr\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
|
data/spec/rdfa-triples/0102.nt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<http://www.example.org> <http://example.org/rdf/example> "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\"
|
1
|
+
<http://www.example.org> <http://example.org/rdf/example> "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"fr\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
|
data/spec/rdfa-triples/0103.nt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<http://www.example.org> <http://example.org/rdf/example> "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\"
|
1
|
+
<http://www.example.org> <http://example.org/rdf/example> "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\">bold</strong> and an svg rectangle: <svg xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"200\" height=\"100\"></rect></svg>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
|
data/spec/rdfa_helper.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
+
require 'rdf/rdfxml'
|
2
|
+
autoload :YAML, "yaml"
|
3
|
+
autoload :CGI, 'cgi'
|
4
|
+
|
5
|
+
RDFA_DIR = File.join(File.dirname(__FILE__), 'rdfa-test-suite')
|
6
|
+
RDFA_NT_DIR = File.join(File.dirname(__FILE__), 'rdfa-triples')
|
7
|
+
RDFA_MANIFEST_URL = "http://rdfa.digitalbazaar.com/test-suite/"
|
8
|
+
RDFA_TEST_CASE_URL = "#{RDFA_MANIFEST_URL}test-cases/"
|
9
|
+
|
10
|
+
class SparqlException < IOError; end
|
11
|
+
|
1
12
|
module RdfaHelper
|
2
13
|
# Class representing test cases in format http://www.w3.org/2006/03/test-description#
|
3
14
|
class TestCase
|
4
|
-
include Matchers
|
5
|
-
|
6
15
|
HTMLRE = Regexp.new('([0-9]{4,4})\.xhtml')
|
7
16
|
TCPATHRE = Regexp.compile('\$TCPATH')
|
8
17
|
|
@@ -18,6 +27,7 @@ module RdfaHelper
|
|
18
27
|
attr_accessor :specificationReference
|
19
28
|
attr_accessor :expectedResults
|
20
29
|
attr_accessor :parser
|
30
|
+
attr_accessor :debug
|
21
31
|
|
22
32
|
@@suite = ""
|
23
33
|
|
@@ -25,19 +35,22 @@ module RdfaHelper
|
|
25
35
|
self.suite = suite
|
26
36
|
self.expectedResults = true
|
27
37
|
statements.each do |statement|
|
28
|
-
next if statement.subject.is_a?(
|
29
|
-
|
38
|
+
next if statement.subject.is_a?(RDF::Node)
|
39
|
+
pred = statement.predicate.to_s.split(/[\#\/]/).last
|
40
|
+
obj = statement.object.is_a?(RDF::Literal) ? statement.object.value : statement.object.to_s
|
41
|
+
|
42
|
+
puts "#{pred}: #{obj}" if $DEBUG
|
43
|
+
|
30
44
|
unless self.about
|
31
|
-
self.about =
|
32
|
-
self.name =
|
45
|
+
self.about = statement.subject
|
46
|
+
self.name = self.about.to_s.split(/[\#\/]/).last || self.about
|
33
47
|
end
|
34
|
-
|
35
|
-
if
|
36
|
-
self.expectedResults =
|
48
|
+
|
49
|
+
if pred == "expectedResults"
|
50
|
+
self.expectedResults = obj == "true"
|
37
51
|
#puts "expectedResults = #{statement.object.literal.value}"
|
38
|
-
elsif self.respond_to?("#{
|
39
|
-
self.send("#{
|
40
|
-
#puts "#{statement.predicate.uri.short_name} = #{s.to_s}"
|
52
|
+
elsif self.respond_to?("#{pred}=")
|
53
|
+
self.send("#{pred}=", obj)
|
41
54
|
end
|
42
55
|
end
|
43
56
|
end
|
@@ -132,8 +145,7 @@ module RdfaHelper
|
|
132
145
|
rdfa_string = input
|
133
146
|
|
134
147
|
# Run
|
135
|
-
|
136
|
-
yield(rdfa_string, @parser)
|
148
|
+
graph = yield(rdfa_string)
|
137
149
|
|
138
150
|
query_string = results
|
139
151
|
|
@@ -141,19 +153,19 @@ module RdfaHelper
|
|
141
153
|
|
142
154
|
if (query_string.match(/UNION|OPTIONAL/) || title.match(/XML/)) && triples
|
143
155
|
# Check triples, as Rasql doesn't implement UNION
|
144
|
-
|
156
|
+
graph.should be_equivalent_graph(triples, self)
|
145
157
|
elsif $redland_enabled
|
146
158
|
# Run SPARQL query
|
147
|
-
|
159
|
+
graph.should pass_query(query_string, self)
|
148
160
|
else
|
149
161
|
raise SparqlException, "Query skipped, Redland not installed"
|
150
162
|
end
|
151
163
|
|
152
|
-
|
164
|
+
graph.to_rdfxml.should be_valid_xml
|
153
165
|
end
|
154
166
|
|
155
167
|
def trace
|
156
|
-
@
|
168
|
+
@debug.to_a.join("\n")
|
157
169
|
end
|
158
170
|
|
159
171
|
def self.test_cases(suite)
|
@@ -163,26 +175,41 @@ module RdfaHelper
|
|
163
175
|
@suite = suite # Process the given test suite
|
164
176
|
@manifest_url = "#{RDFA_MANIFEST_URL}#{suite}-manifest.rdf"
|
165
177
|
|
166
|
-
|
167
|
-
|
178
|
+
manifest_file = File.join(RDFA_DIR, "#{suite}-manifest.rdf")
|
179
|
+
yaml_file = File.join(File.dirname(__FILE__), "#{suite}-manifest.yml")
|
168
180
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
181
|
+
@test_cases = unless File.file?(yaml_file)
|
182
|
+
puts "parse #{manifest_file} @#{Time.now}"
|
183
|
+
graph = RDF::Graph.load(manifest_file, :base_uri => @manifest_url)
|
184
|
+
puts "parsed #{graph.size} statements @#{Time.now}"
|
185
|
+
|
186
|
+
graph.subjects.map do |subj|
|
187
|
+
t = TestCase.new(graph.query(:subject => subj), suite)
|
188
|
+
t.name ? t : nil
|
189
|
+
end.
|
190
|
+
compact.
|
191
|
+
sort_by{|t| t.name.to_s}
|
192
|
+
else
|
193
|
+
# Read tests from Manifest.yml
|
194
|
+
self.from_yaml(yaml_file)
|
173
195
|
end
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.to_yaml(suite, file)
|
199
|
+
test_cases = self.test_cases(suite)
|
200
|
+
puts "write test cases to #{file}"
|
201
|
+
File.open(file, 'w') do |out|
|
202
|
+
YAML.dump(test_cases, out )
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def self.from_yaml(file)
|
207
|
+
YAML::add_private_type("RdfaHelper::TestCase") do |type, val|
|
208
|
+
TestCase.new( val )
|
209
|
+
end
|
210
|
+
File.open(file, 'r') do |input|
|
211
|
+
@test_cases = YAML.load(input)
|
181
212
|
end
|
182
|
-
|
183
|
-
@test_cases = test_hash.values.map {|statements| TestCase.new(statements, suite)}.
|
184
|
-
compact.
|
185
|
-
sort_by{|t| t.name }
|
186
213
|
end
|
187
214
|
end
|
188
215
|
end
|
data/spec/rdfa_reader_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
require 'rdfa_helper'
|
2
3
|
|
3
4
|
describe RDF::RDFa::Format do
|
4
5
|
it "should be discoverable" do
|
@@ -16,6 +17,49 @@ describe RDF::RDFa::Format do
|
|
16
17
|
end
|
17
18
|
|
18
19
|
describe "RDF::RDFa::Reader" do
|
20
|
+
before(:all) do
|
21
|
+
# Don't load external profiles when testing
|
22
|
+
{
|
23
|
+
"basic" => {
|
24
|
+
:base_uri => "http://www.w3.org/2007/08/pyRdfa/profiles/basic",
|
25
|
+
:format => :rdfa,
|
26
|
+
:file => File.join(File.dirname(__FILE__), "..", "etc", "basic.html"),
|
27
|
+
},
|
28
|
+
"foaf" => {
|
29
|
+
:base_uri => "http://www.w3.org/2007/08/pyRdfa/profiles/foaf",
|
30
|
+
:format => :rdfa,
|
31
|
+
:file => File.join(File.dirname(__FILE__), "..", "etc", "foaf.html"),
|
32
|
+
},
|
33
|
+
"xhv" => {
|
34
|
+
:base_uri => "http://www.w3.org/1999/xhtml/vocab",
|
35
|
+
:format => :rdfa,
|
36
|
+
:file => File.join(File.dirname(__FILE__), "..", "etc", "xhv.html"),
|
37
|
+
},
|
38
|
+
"profile" => {
|
39
|
+
:base_uri => "http://www.w3.org/2005/10/profile",
|
40
|
+
:format => :rdfa,
|
41
|
+
:value => "PROFILE",
|
42
|
+
},
|
43
|
+
"hcard" => {
|
44
|
+
:base_uri => "http://microformats.org/profiles/hcard",
|
45
|
+
:format => :rdfa,
|
46
|
+
:value => "HCARD",
|
47
|
+
},
|
48
|
+
}.each_pair do |name, opts|
|
49
|
+
if opts[:file]
|
50
|
+
graph = RDF::Graph.new
|
51
|
+
RDF::Reader.for(opts[:format]).new(File.read(opts[:file]),
|
52
|
+
:base_uri => opts[:base_uri]).each do |statement|
|
53
|
+
graph << statement
|
54
|
+
end
|
55
|
+
opts[:value] = graph
|
56
|
+
end
|
57
|
+
RDF::Graph.stub!(:load).with(opts[:base_uri],
|
58
|
+
:base_uri => opts[:base_uri],
|
59
|
+
:format => opts[:format]).and_return(opts[:value])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
19
63
|
context "discovery" do
|
20
64
|
{
|
21
65
|
"html" => RDF::Reader.for(:rdfa),
|
@@ -185,7 +229,7 @@ EOF
|
|
185
229
|
@graph.should have_triple([
|
186
230
|
RDF::URI('http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml'),
|
187
231
|
RDF::DC11.title,
|
188
|
-
RDF::Literal("E = mc<sup>2</sup>: The Most Urgent Problem of Our Time", :datatype => RDF.XMLLiteral)
|
232
|
+
RDF::Literal("E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time", :datatype => RDF.XMLLiteral)
|
189
233
|
])
|
190
234
|
end
|
191
235
|
end
|
@@ -336,17 +380,6 @@ EOF
|
|
336
380
|
</html>
|
337
381
|
EOF
|
338
382
|
|
339
|
-
basic = File.open(File.join(File.dirname(__FILE__), "..", "etc", "basic.html"))
|
340
|
-
basic_graph = RDF::Graph.new
|
341
|
-
RDF::RDFa::Reader.new(basic,
|
342
|
-
:base_uri => "http://www.w3.org/2007/08/pyRdfa/profiles/basic").each do |statement|
|
343
|
-
basic_graph << statement
|
344
|
-
end
|
345
|
-
|
346
|
-
RDF::Graph.stub!(:load).with("http://www.w3.org/2007/08/pyRdfa/profiles/basic",
|
347
|
-
:base_uri => "http://www.w3.org/2007/08/pyRdfa/profiles/basic",
|
348
|
-
:format => :rdfa).and_return(basic_graph)
|
349
|
-
|
350
383
|
@graph = parse(sampledoc, :strict => true)
|
351
384
|
@statement = @graph.statements.first
|
352
385
|
end
|
@@ -388,17 +421,6 @@ EOF
|
|
388
421
|
</html>
|
389
422
|
EOF
|
390
423
|
|
391
|
-
foaf = File.open(File.join(File.dirname(__FILE__), "..", "etc", "foaf.html"))
|
392
|
-
foaf_graph = RDF::Graph.new
|
393
|
-
RDF::RDFa::Reader.new(foaf,
|
394
|
-
:base_uri => "http://www.w3.org/2007/08/pyRdfa/profiles/foaf").each do |statement|
|
395
|
-
foaf_graph << statement
|
396
|
-
end
|
397
|
-
|
398
|
-
RDF::Graph.stub!(:load).with("http://www.w3.org/2007/08/pyRdfa/profiles/foaf",
|
399
|
-
:base_uri => "http://www.w3.org/2007/08/pyRdfa/profiles/foaf",
|
400
|
-
:format => :rdfa).and_return(foaf_graph)
|
401
|
-
|
402
424
|
@graph = parse(sampledoc, :strict => true)
|
403
425
|
@statement = @graph.statements.first
|
404
426
|
end
|
@@ -421,23 +443,26 @@ EOF
|
|
421
443
|
end
|
422
444
|
|
423
445
|
def self.test_cases(suite)
|
424
|
-
|
446
|
+
RdfaHelper::TestCase.test_cases(suite)
|
425
447
|
end
|
426
448
|
|
427
449
|
# W3C Test suite from http://www.w3.org/2006/07/SWD/RDFa/testsuite/
|
428
|
-
%w(xhtml
|
450
|
+
%w(xhtml).each do |suite| # html4 html5
|
429
451
|
describe "w3c #{suite} testcases" do
|
430
452
|
describe "that are approved" do
|
431
453
|
test_cases(suite).each do |t|
|
432
|
-
puts t.inspect
|
433
454
|
next unless t.status == "approved"
|
434
|
-
#next unless t.name =~ /
|
455
|
+
#next unless t.name =~ /0001/
|
435
456
|
specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
|
436
457
|
#puts t.input
|
437
458
|
#puts t.results
|
438
459
|
begin
|
439
|
-
t.run_test do |rdfa_string
|
440
|
-
|
460
|
+
t.run_test do |rdfa_string|
|
461
|
+
t.debug = []
|
462
|
+
parse(rdfa_string,
|
463
|
+
:base_uri => t.informationResourceInput,
|
464
|
+
:strict => true,
|
465
|
+
:debug => t.debug)
|
441
466
|
end
|
442
467
|
rescue SparqlException => e
|
443
468
|
pending(e.message) { raise }
|
@@ -452,8 +477,12 @@ EOF
|
|
452
477
|
#puts t.inspect
|
453
478
|
specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
|
454
479
|
begin
|
455
|
-
t.run_test do |rdfa_string
|
456
|
-
|
480
|
+
t.run_test do |rdfa_string|
|
481
|
+
t.debug = []
|
482
|
+
parse(rdfa_string,
|
483
|
+
:base_uri => t.informationResourceInput,
|
484
|
+
:strict => true,
|
485
|
+
:debug => t.debug)
|
457
486
|
end
|
458
487
|
rescue SparqlException => e
|
459
488
|
pending(e.message) { raise }
|
@@ -471,7 +500,7 @@ EOF
|
|
471
500
|
end
|
472
501
|
|
473
502
|
def parse(input, options)
|
474
|
-
@debug = []
|
503
|
+
@debug = options[:debug] || []
|
475
504
|
graph = RDF::Graph.new
|
476
505
|
RDF::RDFa::Reader.new(input, options.merge(:debug => @debug)).each do |statement|
|
477
506
|
graph << statement
|