rdf-rdfa 0.0.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
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 @info.compare
6
- when :array
7
- array = case graph
8
- when Graph, Parser
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
- case graph
41
- when Graph then graph
42
- when Parser then graph.graph
43
- when IO, StringIO
44
- Parser.parse(graph, @info.about)
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.identifier : info[:about]
58
- Info.new(identifier, info[:information] || "", info[:trace], info[:compare])
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.identifier : info, info.to_s)
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#{@info.compare == :array ? '(array)' : ''}\n"
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
@@ -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\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">2</sup>: The Most Urgent Problem of Our Time"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
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> .
@@ -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\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">2</sup>: The Most Urgent Problem of Our Time"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
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> .
@@ -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\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:bla=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">2</sup>: The Most Urgent Problem of Our Time"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
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> .
@@ -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\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:ex=\"http://example.org/rdf/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:svg=\"http://www.w3.org/2000/svg\">bold</strong> and an svg rectangle: <svg:svg xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:ex=\"http://example.org/rdf/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:svg=\"http://www.w3.org/2000/svg\"><svg:rect svg:width=\"200\" svg:height=\"100\"></svg:rect></svg:svg>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
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> .
@@ -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\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:ex=\"http://example.org/rdf/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:ex=\"http://example.org/rdf/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"fr\"><svg:rect svg:width=\"200\" svg:height=\"100\"></svg:rect></svg:svg>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
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> .
@@ -1 +1 @@
1
- <http://www.example.org> <http://example.org/rdf/example> "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:ex=\"http://example.org/rdf/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xml:lang=\"hu\" xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:ex=\"http://example.org/rdf/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><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> .
@@ -1 +1 @@
1
- <http://www.example.org> <http://example.org/rdf/example> "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:ex=\"http://example.org/rdf/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">bold</strong> and an svg rectangle: <svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:ex=\"http://example.org/rdf/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><rect width=\"200\" height=\"100\"></rect></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 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?(BNode)
29
- #next unless statement.subject.uri.to_s.match(/0001/)
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 = Addressable::URI.parse(statement.subject.uri.to_s)
32
- self.name = statement.subject.short_name || self.about
45
+ self.about = statement.subject
46
+ self.name = self.about.to_s.split(/[\#\/]/).last || self.about
33
47
  end
34
-
35
- if statement.predicate.short_name == "expectedResults"
36
- self.expectedResults = statement.object.contents == "true"
48
+
49
+ if pred == "expectedResults"
50
+ self.expectedResults = obj == "true"
37
51
  #puts "expectedResults = #{statement.object.literal.value}"
38
- elsif self.respond_to?("#{statement.predicate.short_name}=")
39
- self.send("#{statement.predicate.short_name}=", statement.object.to_s)
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
- @parser = RdfaParser::RdfaParser.new(:graph => Graph.new(:identifier => about))
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
- @parser.graph.should be_equivalent_graph(triples, self)
156
+ graph.should be_equivalent_graph(triples, self)
145
157
  elsif $redland_enabled
146
158
  # Run SPARQL query
147
- @parser.graph.should pass_query(query_string, self)
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
- @parser.graph.to_rdfxml.should be_valid_xml
164
+ graph.to_rdfxml.should be_valid_xml
153
165
  end
154
166
 
155
167
  def trace
156
- @parser.debug.to_a.join("\n")
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
- manifest_str = File.read(File.join(RDFA_DIR, "#{suite}-manifest.rdf"))
167
- parser = RdfXmlParser.new
178
+ manifest_file = File.join(RDFA_DIR, "#{suite}-manifest.rdf")
179
+ yaml_file = File.join(File.dirname(__FILE__), "#{suite}-manifest.yml")
168
180
 
169
- begin
170
- parser.parse(manifest_str, @manifest_url)
171
- rescue
172
- raise "Parse error: #{$!}\n\t#{parser.debug.to_a.join("\t\n")}\n\n"
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
- graph = parser.graph
175
-
176
- # Group by subject
177
- test_hash = graph.triples.inject({}) do |hash, st|
178
- a = hash[st.subject] ||= []
179
- a << st
180
- hash
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
@@ -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
- [] #RdfaHelper::TestCase.test_cases(suite)
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 html4 html5).each do |suite|
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 =~ /0140/
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, rdfa_parser|
440
- rdfa_parser.parse(rdfa_string, t.informationResourceInput, :debug => [])
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, rdfa_parser|
456
- rdfa_parser.parse(rdfa_string, t.informationResourceInput, :debug => [])
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