rdf-rdfa 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/.gitignore +2 -0
  2. data/.yardopts +3 -1
  3. data/History.rdoc +52 -0
  4. data/README.rdoc +2 -2
  5. data/Rakefile +12 -17
  6. data/VERSION +1 -1
  7. data/lib/rdf/.gitignore +2 -0
  8. data/lib/rdf/rdfa.rb +1 -1
  9. data/lib/rdf/rdfa/patches/literal_hacks.rb +15 -17
  10. data/lib/rdf/rdfa/profile.rb +167 -0
  11. data/lib/rdf/rdfa/reader.rb +287 -199
  12. data/lib/rdf/rdfa/version.rb +4 -7
  13. data/lib/rdf/rdfa/vocab.rb +1 -0
  14. data/rdf-rdfa.gemspec +16 -125
  15. data/script/parse +16 -9
  16. data/script/tc +29 -13
  17. data/spec/html4-manifest.yml +491 -3855
  18. data/spec/html5-manifest.yml +491 -3855
  19. data/spec/literal_spec.rb +7 -8
  20. data/spec/profile_spec.rb +53 -0
  21. data/spec/rdfa_helper.rb +48 -47
  22. data/spec/rdfa_reader_spec.rb +312 -172
  23. data/spec/spec_helper.rb +12 -3
  24. data/spec/svgtiny-manifest.yml +37 -0
  25. data/spec/xhtml-manifest.yml +533 -2824
  26. metadata +19 -126
  27. data/History.txt +0 -30
  28. data/lib/rdf/rdfa/patches/uri_hacks.rb +0 -24
  29. data/spec/rdfa-triples/0001.nt +0 -1
  30. data/spec/rdfa-triples/0006.nt +0 -2
  31. data/spec/rdfa-triples/0007.nt +0 -3
  32. data/spec/rdfa-triples/0008.nt +0 -1
  33. data/spec/rdfa-triples/0009.nt +0 -1
  34. data/spec/rdfa-triples/0010.nt +0 -2
  35. data/spec/rdfa-triples/0011.nt +0 -3
  36. data/spec/rdfa-triples/0012.nt +0 -1
  37. data/spec/rdfa-triples/0013.nt +0 -1
  38. data/spec/rdfa-triples/0014.nt +0 -1
  39. data/spec/rdfa-triples/0015.nt +0 -2
  40. data/spec/rdfa-triples/0017.nt +0 -3
  41. data/spec/rdfa-triples/0018.nt +0 -1
  42. data/spec/rdfa-triples/0019.nt +0 -1
  43. data/spec/rdfa-triples/0020.nt +0 -1
  44. data/spec/rdfa-triples/0021.nt +0 -1
  45. data/spec/rdfa-triples/0023.nt +0 -1
  46. data/spec/rdfa-triples/0025.nt +0 -2
  47. data/spec/rdfa-triples/0026.nt +0 -1
  48. data/spec/rdfa-triples/0027.nt +0 -1
  49. data/spec/rdfa-triples/0029.nt +0 -1
  50. data/spec/rdfa-triples/0030.nt +0 -1
  51. data/spec/rdfa-triples/0031.nt +0 -1
  52. data/spec/rdfa-triples/0032.nt +0 -1
  53. data/spec/rdfa-triples/0033.nt +0 -2
  54. data/spec/rdfa-triples/0034.nt +0 -1
  55. data/spec/rdfa-triples/0035.nt +0 -1
  56. data/spec/rdfa-triples/0036.nt +0 -1
  57. data/spec/rdfa-triples/0037.nt +0 -1
  58. data/spec/rdfa-triples/0038.nt +0 -1
  59. data/spec/rdfa-triples/0039.nt +0 -1
  60. data/spec/rdfa-triples/0040.nt +0 -1
  61. data/spec/rdfa-triples/0041.nt +0 -1
  62. data/spec/rdfa-triples/0042.nt +0 -0
  63. data/spec/rdfa-triples/0046.nt +0 -3
  64. data/spec/rdfa-triples/0047.nt +0 -3
  65. data/spec/rdfa-triples/0048.nt +0 -3
  66. data/spec/rdfa-triples/0049.nt +0 -2
  67. data/spec/rdfa-triples/0050.nt +0 -2
  68. data/spec/rdfa-triples/0051.nt +0 -2
  69. data/spec/rdfa-triples/0052.nt +0 -1
  70. data/spec/rdfa-triples/0053.nt +0 -2
  71. data/spec/rdfa-triples/0054.nt +0 -2
  72. data/spec/rdfa-triples/0055.nt +0 -2
  73. data/spec/rdfa-triples/0056.nt +0 -3
  74. data/spec/rdfa-triples/0057.nt +0 -4
  75. data/spec/rdfa-triples/0058.nt +0 -6
  76. data/spec/rdfa-triples/0059.nt +0 -6
  77. data/spec/rdfa-triples/0060.nt +0 -2
  78. data/spec/rdfa-triples/0061.nt +0 -1
  79. data/spec/rdfa-triples/0062.nt +0 -1
  80. data/spec/rdfa-triples/0063.nt +0 -1
  81. data/spec/rdfa-triples/0064.nt +0 -1
  82. data/spec/rdfa-triples/0065.nt +0 -3
  83. data/spec/rdfa-triples/0066.nt +0 -1
  84. data/spec/rdfa-triples/0067.nt +0 -1
  85. data/spec/rdfa-triples/0068.nt +0 -1
  86. data/spec/rdfa-triples/0069.nt +0 -1
  87. data/spec/rdfa-triples/0070.nt +0 -1
  88. data/spec/rdfa-triples/0071.nt +0 -1
  89. data/spec/rdfa-triples/0072.nt +0 -1
  90. data/spec/rdfa-triples/0073.nt +0 -1
  91. data/spec/rdfa-triples/0074.nt +0 -1
  92. data/spec/rdfa-triples/0075.nt +0 -1
  93. data/spec/rdfa-triples/0076.nt +0 -23
  94. data/spec/rdfa-triples/0077.nt +0 -23
  95. data/spec/rdfa-triples/0078.nt +0 -6
  96. data/spec/rdfa-triples/0079.nt +0 -3
  97. data/spec/rdfa-triples/0080.nt +0 -1
  98. data/spec/rdfa-triples/0081.nt +0 -6
  99. data/spec/rdfa-triples/0082.nt +0 -8
  100. data/spec/rdfa-triples/0083.nt +0 -6
  101. data/spec/rdfa-triples/0084.nt +0 -8
  102. data/spec/rdfa-triples/0085.nt +0 -4
  103. data/spec/rdfa-triples/0086.nt +0 -0
  104. data/spec/rdfa-triples/0087.nt +0 -23
  105. data/spec/rdfa-triples/0088.nt +0 -3
  106. data/spec/rdfa-triples/0089.nt +0 -1
  107. data/spec/rdfa-triples/0090.nt +0 -1
  108. data/spec/rdfa-triples/0091.nt +0 -3
  109. data/spec/rdfa-triples/0092.nt +0 -3
  110. data/spec/rdfa-triples/0093.nt +0 -2
  111. data/spec/rdfa-triples/0094.nt +0 -3
  112. data/spec/rdfa-triples/0099.nt +0 -1
  113. data/spec/rdfa-triples/0100.nt +0 -1
  114. data/spec/rdfa-triples/0101.nt +0 -1
  115. data/spec/rdfa-triples/0102.nt +0 -1
  116. data/spec/rdfa-triples/0103.nt +0 -1
  117. data/spec/rdfa-triples/0104.nt +0 -3
  118. data/spec/rdfa-triples/0105.nt +0 -1
  119. data/spec/rdfa-triples/0106.nt +0 -1
  120. data/spec/rdfa-triples/0107.nt +0 -0
  121. data/spec/rdfa-triples/0108.nt +0 -1
  122. data/spec/rdfa-triples/0109.nt +0 -1
  123. data/spec/rdfa-triples/0110.nt +0 -1
  124. data/spec/rdfa-triples/0111.nt +0 -2
  125. data/spec/rdfa-triples/0112.nt +0 -1
  126. data/spec/rdfa-triples/0113.nt +0 -2
  127. data/spec/rdfa-triples/0114.nt +0 -3
  128. data/spec/rdfa-triples/0115.nt +0 -4
  129. data/spec/rdfa-triples/0116.nt +0 -2
  130. data/spec/rdfa-triples/0117.nt +0 -2
  131. data/spec/rdfa-triples/0118.nt +0 -1
  132. data/spec/rdfa-triples/0119.nt +0 -1
  133. data/spec/rdfa-triples/0120.nt +0 -1
  134. data/spec/rdfa-triples/0121.nt +0 -2
  135. data/spec/rdfa-triples/0122.nt +0 -1
  136. data/spec/rdfa-triples/0123.nt +0 -3
  137. data/spec/rdfa-triples/0124.nt +0 -4
  138. data/spec/rdfa-triples/0125.nt +0 -1
  139. data/spec/rdfa-triples/0126.nt +0 -3
  140. data/spec/rdfa-triples/1001.nt +0 -6
  141. data/spec/xhtml11-manifest.yml +0 -4707
data/spec/literal_spec.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # coding: utf-8
2
2
  $:.unshift "."
3
3
  require File.join(File.dirname(__FILE__), 'spec_helper')
4
- require 'nokogiri'
5
4
 
6
5
  describe RDF::Literal do
7
6
  require 'nokogiri' rescue nil
@@ -73,7 +72,7 @@ describe RDF::Literal do
73
72
  :dc => "http://purl.org/dc/terms/",
74
73
  })
75
74
  }
76
- it "should add namespace" do subject.to_s.should == "<svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"></svg:svg>" end
75
+ it "should add namespace" do subject.to_s.should == "<svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:dc=\"http://purl.org/dc/terms/\"></svg:svg>" end
77
76
  end
78
77
 
79
78
  describe "and language with an existing language embedded" do
@@ -91,7 +90,7 @@ describe RDF::Literal do
91
90
  describe "with a default namespace" do
92
91
  subject {
93
92
  @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral,
94
- :namespaces => {:__default__ => RDF::DC.to_s})
93
+ :namespaces => {"" => RDF::DC.to_s})
95
94
  }
96
95
 
97
96
  it "should add namespace" do subject.to_s.should == "foo <sup xmlns=\"http://purl.org/dc/terms/\">bar</sup> baz!" end
@@ -122,7 +121,7 @@ describe RDF::Literal do
122
121
  "my" => "http://my.example.org/",
123
122
  })
124
123
 
125
- pending("XML C14N") do
124
+ pending do
126
125
  l.to_s.should == "\n <html:h1 xmlns:html=\"http://NoHTML.example.org\">\n <b xmlns=\"http://www.w3.org/1999/xhtml\">John</b>\n </html:h1>\n "
127
126
  end
128
127
  end
@@ -197,7 +196,7 @@ describe RDF::Literal do
197
196
  "svg" => "http://www.w3.org/2000/svg",
198
197
  })
199
198
 
200
- pending("XML C14N") do
199
+ pending do
201
200
  l.to_s.should == "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>"
202
201
  end
203
202
  end
@@ -210,7 +209,7 @@ describe RDF::Literal do
210
209
  "svg" => "http://www.w3.org/2000/svg",
211
210
  })
212
211
 
213
- pending("XML C14N") do
212
+ pending do
214
213
  l.to_s.should == "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>"
215
214
  end
216
215
  end
@@ -223,7 +222,7 @@ describe RDF::Literal do
223
222
  "svg" => "http://www.w3.org/2000/svg",
224
223
  })
225
224
 
226
- pending("XML C14N") do
225
+ pending do
227
226
  l.to_s.should == "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=\"hu\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"
228
227
  end
229
228
  end
@@ -236,7 +235,7 @@ describe RDF::Literal do
236
235
  "svg" => "http://www.w3.org/2000/svg",
237
236
  })
238
237
 
239
- pending("XML C14N") do
238
+ pending do
240
239
  l.to_s.should == "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 height=\"100\" width=\"200\"></rect></svg>"
241
240
  end
242
241
  end
@@ -0,0 +1,53 @@
1
+ $:.unshift "."
2
+ require File.join(File.dirname(__FILE__), 'spec_helper')
3
+
4
+ describe RDF::RDFa::Profile do
5
+ describe ".new" do
6
+ describe "foaf" do
7
+ subject { RDF::RDFa::Profile.new("http://rdfa.digitalbazaar.com/test-suite/profiles/foaf") }
8
+
9
+ it "has 74 terms" do
10
+ subject.terms.keys.length.should == 74
11
+ end
12
+
13
+ it "has no vocabulary" do
14
+ subject.vocabulary.should be_nil
15
+ end
16
+
17
+ it "has no prefixes" do
18
+ subject.prefixes.should be_empty
19
+ end
20
+ end
21
+
22
+ describe "basic" do
23
+ subject { RDF::RDFa::Profile.new("http://rdfa.digitalbazaar.com/test-suite/profiles/basic") }
24
+
25
+ it "has no terms" do
26
+ subject.terms.should be_empty
27
+ end
28
+
29
+ it "has no vocabulary" do
30
+ subject.vocabulary.should be_nil
31
+ end
32
+
33
+ it "has 6 prefixes" do
34
+ subject.prefixes.keys.length.should == 6
35
+ end
36
+ end
37
+ end
38
+
39
+ describe ".find" do
40
+ before(:all) do
41
+ RDF::RDFa::Profile.find("http://rdfa.digitalbazaar.com/test-suite/profiles/basic")
42
+ RDF::RDFa::Profile.find("http://rdfa.digitalbazaar.com/test-suite/profiles/foaf")
43
+ end
44
+
45
+ it "cached basic" do
46
+ RDF::RDFa::Profile.cache[RDF::URI.intern("http://rdfa.digitalbazaar.com/test-suite/profiles/basic")].should be_a(RDF::RDFa::Profile)
47
+ end
48
+
49
+ it "cached foaf" do
50
+ RDF::RDFa::Profile.cache[RDF::URI.intern("http://rdfa.digitalbazaar.com/test-suite/profiles/foaf")].should be_a(RDF::RDFa::Profile)
51
+ end
52
+ end
53
+ end
data/spec/rdfa_helper.rb CHANGED
@@ -4,7 +4,6 @@ autoload :YAML, "yaml"
4
4
  autoload :CGI, 'cgi'
5
5
 
6
6
  RDFA_DIR = File.join(File.dirname(__FILE__), 'rdfa-test-suite')
7
- RDFA_NT_DIR = File.join(File.dirname(__FILE__), 'rdfa-triples')
8
7
  RDFA_MANIFEST_URL = "http://rdfa.digitalbazaar.com/test-suite/"
9
8
  RDFA_TEST_CASE_URL = "#{RDFA_MANIFEST_URL}test-cases/"
10
9
 
@@ -24,6 +23,7 @@ module RdfaHelper
24
23
  attr_accessor :informationResourceResults
25
24
  attr_accessor :purpose
26
25
  attr_accessor :reviewStatus
26
+ attr_accessor :classification
27
27
  attr_accessor :suite
28
28
  attr_accessor :specificationReference
29
29
  attr_accessor :expectedResults
@@ -43,7 +43,7 @@ module RdfaHelper
43
43
  puts "#{pred}: #{obj}" if ::RDF::RDFa::debug?
44
44
 
45
45
  unless self.about
46
- self.about = statement.subject
46
+ self.about = statement.subject.to_s
47
47
  self.name = self.about.to_s.split(/[\#\/]/).last || self.about
48
48
  end
49
49
 
@@ -66,6 +66,7 @@ module RdfaHelper
66
66
  informationResourceResults
67
67
  purpose
68
68
  reviewStatus
69
+ classification
69
70
  specificationReference
70
71
  expectedResults
71
72
  ).map {|a| v = self.send(a); "#{a}='#{v}'" if v}.compact.join(", ") +
@@ -96,6 +97,7 @@ module RdfaHelper
96
97
  if found_head
97
98
  line.chop
98
99
  else
100
+ found_head ||= line.match(%r(http://www.w3.org/2000/svg))
99
101
  namespaces << line
100
102
  nil
101
103
  end
@@ -105,26 +107,24 @@ module RdfaHelper
105
107
 
106
108
  case suite
107
109
  when "xhtml"
108
- head = "" +
109
- %(<?xml version="1.0" encoding="UTF-8"?>\n) +
110
- %(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">\n) +
111
- %(<html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.0"\n)
112
- head + "#{namespaces}>\n#{body.gsub(TCPATHRE, tcpath)}\n</html>"
113
- when "xhtml11"
114
110
  head = "" +
115
111
  %(<?xml version="1.0" encoding="UTF-8"?>\n) +
116
112
  %(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">\n) +
117
- %(<html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"\n)
113
+ %(<html xmlns="http://www.w3.org/1999/xhtml"\n)
118
114
  head + "#{namespaces}>\n#{body.gsub(TCPATHRE, tcpath)}\n</html>"
119
115
  when "html4"
120
116
  head ="" +
121
- %(<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n) +
122
- %(<html version="XHTML+RDFa 1.0"\n)
117
+ %(<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/MarkUp/DTD/html401-rdfa11-1.dtd">\n) +
118
+ %(<html\n)
123
119
  head + "#{namespaces}>\n#{body.gsub(TCPATHRE, tcpath).gsub(HTMLRE, '\1.html')}\n</html>"
124
120
  when "html5"
125
121
  head = "<!DOCTYPE html>\n"
126
- head += namespaces.empty? ? %(<html version="HTML+RDFa 1.0">) : "<html\n#{namespaces}>"
122
+ head += namespaces.empty? ? %(<html>) : "<html\n#{namespaces}>"
127
123
  head + "\n#{body.gsub(TCPATHRE, tcpath).gsub(HTMLRE, '\1.html')}\n</html>"
124
+ when "svgtiny"
125
+ head = %(<?xml version="1.0" encoding="UTF-8"?>\n)
126
+ head += namespaces.empty? ? %(<svg>) : "<svg\n#{namespaces}>"
127
+ head + "\n#{body.gsub(TCPATHRE, tcpath).gsub(HTMLRE, '\1.svg')}\n</svg>"
128
128
  else
129
129
  nil
130
130
  end
@@ -135,20 +135,18 @@ module RdfaHelper
135
135
  f = self.name + ".sparql"
136
136
  body = File.read(File.join(RDFA_DIR, "tests", f)).gsub(TCPATHRE, tcpath)
137
137
 
138
- suite =~ /xhtml/ ? body : body.gsub(HTMLRE, '\1.html')
139
- end
140
-
141
- def triples
142
- f = self.name + ".nt"
143
- body = File.read(File.join(RDFA_NT_DIR, f)).gsub(TCPATHRE, tcpath)
144
- suite =~ /xhtml/ ? body : body.gsub(HTMLRE, '\1.html')
138
+ case suite
139
+ when /xhtml/ then body
140
+ when /svg/ then body.gsub(HTMLRE, '\1.svg')
141
+ else body.gsub(HTMLRE, '\1.html')
142
+ end
145
143
  end
146
144
 
147
145
  def inputDocument; self.name + ".txt"; end
148
146
  def outputDocument; self.name + ".sparql"; end
149
147
 
150
148
  def version
151
- suite == "xhtml11" ? :rdfa_1_1 : :rdfa_1_0
149
+ :rdfa_1_1
152
150
  end
153
151
 
154
152
  # Run test case, yields input for parser to create triples
@@ -160,12 +158,7 @@ module RdfaHelper
160
158
 
161
159
  query_string = results
162
160
 
163
- triples = self.triples rescue nil
164
-
165
- if (query_string.match(/UNION|OPTIONAL/) || title.match(/XML/)) && triples
166
- # Check triples, as Rasql doesn't implement UNION
167
- graph.should be_equivalent_graph(triples, self)
168
- elsif $redland_enabled
161
+ if $redland_enabled
169
162
  # Run SPARQL query
170
163
  graph.should pass_query(query_string, self)
171
164
  else
@@ -190,9 +183,12 @@ module RdfaHelper
190
183
  yaml_file = File.join(File.dirname(__FILE__), "#{suite}-manifest.yml")
191
184
 
192
185
  @test_cases = unless File.file?(yaml_file)
186
+ t = Time.now
193
187
  puts "parse #{manifest_file} @#{Time.now}"
194
- graph = RDF::Graph.load(manifest_file, :base_uri => @manifest_url)
195
- puts "parsed #{graph.size} statements @#{Time.now}"
188
+ graph = RDF::Graph.new
189
+ graph << RDF::RDFXML::Reader.new(File.open(manifest_file), :base_url => @manifest_url)
190
+ diff = Time.now - t
191
+ puts "parsed #{graph.size} statements in #{diff} seconds (#{(graph.size / diff).to_i} statements/sec) @#{Time.now}"
196
192
 
197
193
  graph.subjects.map do |subj|
198
194
  t = TestCase.new(graph.query(:subject => subj), suite)
@@ -225,32 +221,37 @@ module RdfaHelper
225
221
  end
226
222
  end
227
223
 
224
+ # Stub RDF::Reader.open
228
225
  module RDF
229
- class Graph
230
- def self.load(url, options = {}, &block)
231
- url = case url.to_s
226
+ class Reader
227
+ class << self
228
+ alias orig_open open
229
+ end
230
+
231
+ def self.stub_file(filename)
232
+ case filename.to_s
233
+ when %r(http://rdfa.digitalbazaar.com/test-suite/profile/\w+)
234
+ filename.to_s.sub(%r(http://rdfa.digitalbazaar.com/test-suite/profile/\w+),
235
+ File.join(File.expand_path(File.dirname(__FILE__)), 'rdfa-test-suite', 'profile'))
232
236
  when %r(http://rdfa.digitalbazaar.com/test-suite/test-cases/\w+)
233
- file = url.to_s.sub(%r(http://rdfa.digitalbazaar.com/test-suite/test-cases/\w+),
237
+ filename.to_s.sub(%r(http://rdfa.digitalbazaar.com/test-suite/test-cases/\w+),
234
238
  File.join(File.expand_path(File.dirname(__FILE__)), 'rdfa-test-suite', 'tests'))
235
- file
236
239
  when "http://www.w3.org/1999/xhtml/vocab"
237
- file = File.join(File.expand_path(File.dirname(__FILE__)), 'rdfa-test-suite', 'profile', "xhv")
238
- file
240
+ File.join(File.expand_path(File.dirname(__FILE__)), 'rdfa-test-suite', 'profile', "xhv")
239
241
  when "http://www.w3.org/2005/10/profile"
240
- file = File.join(File.expand_path(File.dirname(__FILE__)), 'rdfa-test-suite', 'profile', "xhv")
242
+ File.join(File.expand_path(File.dirname(__FILE__)), 'rdfa-test-suite', 'profile', "xhv")
243
+ when "http://example.com/profile"
244
+ File.join(TMP_DIR, "profile.html")
241
245
  else
242
- url
243
- end
244
-
245
- self.new(url, options) do |graph|
246
- graph.load! unless graph.unnamed?
247
- if block_given?
248
- case block.arity
249
- when 1 then block.call(graph)
250
- else graph.instance_eval(&block)
251
- end
252
- end
246
+ filename
253
247
  end
254
248
  end
249
+
250
+ def self.open(filename, options = {}, &block)
251
+ filename = ::RDF::Reader.stub_file(filename)
252
+ options[:format] ||= :rdfa
253
+ puts "parse #{filename} with format #{options[:format]}" if $verbose
254
+ orig_open(filename, options, &block)
255
+ end
255
256
  end
256
257
  end
@@ -18,7 +18,7 @@ describe RDF::RDFa::Format do
18
18
  end
19
19
 
20
20
  describe "RDF::RDFa::Reader" do
21
- context "discovery" do
21
+ describe "discovery" do
22
22
  {
23
23
  "html" => RDF::Reader.for(:rdfa),
24
24
  "etc/foaf.html" => RDF::Reader.for("etc/foaf.html"),
@@ -32,21 +32,20 @@ describe "RDF::RDFa::Reader" do
32
32
  end
33
33
  end
34
34
 
35
- context :interface do
35
+ describe :interface do
36
36
  before(:each) do
37
- @sampledoc = <<-EOF;
38
- <?xml version="1.0" encoding="UTF-8"?>
39
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
40
- <html xmlns="http://www.w3.org/1999/xhtml"
41
- xmlns:dc="http://purl.org/dc/elements/1.1/">
42
- <head>
43
- <title>Test 0001</title>
44
- </head>
45
- <body>
46
- <p>This photo was taken by <span class="author" about="photo1.jpg" property="dc:creator">Mark Birbeck</span>.</p>
47
- </body>
48
- </html>
49
- EOF
37
+ @sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
38
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
39
+ <html xmlns="http://www.w3.org/1999/xhtml"
40
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
41
+ <head>
42
+ <title>Test 0001</title>
43
+ </head>
44
+ <body>
45
+ <p>This photo was taken by <span class="author" about="photo1.jpg" property="dc:creator">Mark Birbeck</span>.</p>
46
+ </body>
47
+ </html>
48
+ )
50
49
  end
51
50
 
52
51
  it "should yield reader" do
@@ -78,23 +77,22 @@ EOF
78
77
  end
79
78
  end
80
79
 
81
- context "parsing a simple doc" do
80
+ describe "parsing a simple doc" do
82
81
  before :each do
83
- sampledoc = <<-EOF;
84
- <?xml version="1.0" encoding="UTF-8"?>
85
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
86
- <html xmlns="http://www.w3.org/1999/xhtml"
87
- xmlns:dc="http://purl.org/dc/elements/1.1/">
88
- <head>
89
- <title>Test 0001</title>
90
- </head>
91
- <body>
92
- <p>This photo was taken by <span class="author" about="photo1.jpg" property="dc:creator">Mark Birbeck</span>.</p>
93
- </body>
94
- </html>
95
- EOF
96
-
97
- @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0001.xhtml", :strict => true)
82
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
83
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
84
+ <html xmlns="http://www.w3.org/1999/xhtml"
85
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
86
+ <head>
87
+ <title>Test 0001</title>
88
+ </head>
89
+ <body>
90
+ <p>This photo was taken by <span class="author" about="photo1.jpg" property="dc:creator">Mark Birbeck</span>.</p>
91
+ </body>
92
+ </html>
93
+ )
94
+
95
+ @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0001.xhtml", :validate => true)
98
96
  @statement = @graph.statements.first
99
97
  end
100
98
 
@@ -115,20 +113,19 @@ EOF
115
113
  end
116
114
  end
117
115
 
118
- context "parsing a simple doc without a base URI" do
116
+ describe "parsing a simple doc without a base URI" do
119
117
  before :each do
120
- sampledoc = <<-EOF;
121
- <?xml version="1.0" encoding="UTF-8"?>
122
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
123
- <html xmlns="http://www.w3.org/1999/xhtml"
124
- xmlns:dc="http://purl.org/dc/elements/1.1/">
125
- <body>
126
- <p>This photo was taken by <span class="author" about="_:photo" property="dc:creator">Mark Birbeck</span>.</p>
127
- </body>
128
- </html>
129
- EOF
130
-
131
- @graph = parse(sampledoc, :strict => true)
118
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
119
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
120
+ <html xmlns="http://www.w3.org/1999/xhtml"
121
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
122
+ <body>
123
+ <p>This photo was taken by <span class="author" about="_:photo" property="dc:creator">Mark Birbeck</span>.</p>
124
+ </body>
125
+ </html>
126
+ )
127
+
128
+ @graph = parse(sampledoc, :validate => true)
132
129
  @statement = @graph.statements.first
133
130
  end
134
131
 
@@ -149,27 +146,26 @@ EOF
149
146
  end
150
147
  end
151
148
 
152
- context "parsing a document containing an XML Literal" do
149
+ describe "parsing a document containing an XML Literal" do
153
150
  before :each do
154
- sampledoc = <<-EOF
155
- <?xml version="1.0" encoding="UTF-8"?>
156
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
157
- <html xmlns="http://www.w3.org/1999/xhtml"
158
- xmlns:dc="http://purl.org/dc/elements/1.1/"
159
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
160
- <head>
161
- <title>Test 0011</title>
162
- </head>
163
- <body>
164
- <div about="">
165
- Author: <span property="dc:creator">Albert Einstein</span>
166
- <h2 property="dc:title" datatype="rdf:XMLLiteral">E = mc<sup>2</sup>: The Most Urgent Problem of Our Time</h2>
167
- </div>
168
- </body>
169
- </html>
170
- EOF
171
-
172
- @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml", :strict => true)
151
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
152
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
153
+ <html xmlns="http://www.w3.org/1999/xhtml"
154
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
155
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
156
+ <head>
157
+ <title>Test 0011</title>
158
+ </head>
159
+ <body>
160
+ <div about="">
161
+ Author: <span property="dc:creator">Albert Einstein</span>
162
+ <h2 property="dc:title" datatype="rdf:XMLLiteral">E = mc<sup>2</sup>: The Most Urgent Problem of Our Time</h2>
163
+ </div>
164
+ </body>
165
+ </html>
166
+ )
167
+
168
+ @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml", :validate => true)
173
169
  end
174
170
 
175
171
  it "should return 2 triples" do
@@ -185,35 +181,38 @@ EOF
185
181
  end
186
182
 
187
183
  it "should have an XML Literal for the dc:title of the document" do
188
- @graph.should have_triple([
189
- RDF::URI('http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml'),
190
- RDF::DC11.title,
191
- RDF::Literal("E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time", :datatype => RDF.XMLLiteral)
192
- ])
184
+ begin
185
+ @graph.should have_triple([
186
+ RDF::URI('http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml'),
187
+ RDF::DC11.title,
188
+ RDF::Literal(%(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), :datatype => RDF.XMLLiteral)
189
+ ])
190
+ rescue RSpec::Expectations::ExpectationNotMetError => e
191
+ pending("XMLLiteral canonicalization not implemented yet")
192
+ end
193
193
  end
194
194
  end
195
195
 
196
- context "parsing a document containing sereral bnodes" do
196
+ describe "parsing a document containing sereral bnodes" do
197
197
  before :each do
198
- sampledoc = <<-EOF
199
- <?xml version="1.0" encoding="UTF-8"?>
200
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
201
- <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
202
- xmlns:foaf="http://xmlns.com/foaf/0.1/">
203
- <head>
204
- <title>Test 0017</title>
205
- </head>
206
- <body>
207
- <p>
208
- <span about="[_:a]" property="foaf:name">Manu Sporny</span>
209
- <span about="[_:a]" rel="foaf:knows" resource="[_:b]">knows</span>
210
- <span about="[_:b]" property="foaf:name">Ralph Swick</span>.
211
- </p>
212
- </body>
213
- </html>
214
- EOF
215
-
216
- @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0017.xhtml", :strict => true)
198
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
199
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
200
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
201
+ xmlns:foaf="http://xmlns.com/foaf/0.1/">
202
+ <head>
203
+ <title>Test 0017</title>
204
+ </head>
205
+ <body>
206
+ <p>
207
+ <span about="[_:a]" property="foaf:name">Manu Sporny</span>
208
+ <span about="[_:a]" rel="foaf:knows" resource="[_:b]">knows</span>
209
+ <span about="[_:b]" property="foaf:name">Ralph Swick</span>.
210
+ </p>
211
+ </body>
212
+ </html>
213
+ )
214
+
215
+ @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0017.xhtml", :validate => true)
217
216
  end
218
217
 
219
218
  it "should return 3 triples" do
@@ -245,25 +244,24 @@ EOF
245
244
  end
246
245
  end
247
246
 
248
- context "parsing a document that uses the typeof attribute" do
247
+ describe "parsing a document that uses the typeof attribute" do
249
248
  before :each do
250
- sampledoc = <<-EOF
251
- <?xml version="1.0" encoding="UTF-8"?>
252
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
253
- <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
254
- xmlns:foaf="http://xmlns.com/foaf/0.1/">
255
- <head>
256
- <title>Test 0049</title>
257
- </head>
258
- <body>
259
- <div about="http://www.example.org/#me" typeof="foaf:Person">
260
- <p property="foaf:name">John Doe</p>
261
- </div>
262
- </body>
263
- </html>
264
- EOF
265
-
266
- @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0049.xhtml", :strict => true)
249
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
250
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
251
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
252
+ xmlns:foaf="http://xmlns.com/foaf/0.1/">
253
+ <head>
254
+ <title>Test 0049</title>
255
+ </head>
256
+ <body>
257
+ <div about="http://www.example.org/#me" typeof="foaf:Person">
258
+ <p property="foaf:name">John Doe</p>
259
+ </div>
260
+ </body>
261
+ </html>
262
+ )
263
+
264
+ @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0049.xhtml", :validate => true)
267
265
  end
268
266
 
269
267
  it "should return 2 triples" do
@@ -287,27 +285,26 @@ EOF
287
285
  end
288
286
  end
289
287
 
290
- context "parsing a document with a <base> tag in the <head>" do
288
+ describe "parsing a document with a <base> tag in the <head>" do
291
289
  before :each do
292
- sampledoc = <<-EOF
293
- <?xml version="1.0" encoding="UTF-8"?>
294
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
295
- <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
296
- xmlns:dc="http://purl.org/dc/elements/1.1/">
297
- <head>
298
- <base href="http://www.example.org/"></base>
299
- <title>Test 0072</title>
300
- </head>
301
- <body>
302
- <p about="faq">
303
- Learn more by reading the example.org
304
- <span property="dc:title">Example FAQ</span>.
305
- </p>
306
- </body>
307
- </html>
308
- EOF
309
-
310
- @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0072.xhtml", :strict => true)
290
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
291
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
292
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
293
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
294
+ <head>
295
+ <base href="http://www.example.org/"></base>
296
+ <title>Test 0072</title>
297
+ </head>
298
+ <body>
299
+ <p about="faq">
300
+ Learn more by reading the example.org
301
+ <span property="dc:title">Example FAQ</span>.
302
+ </p>
303
+ </body>
304
+ </html>
305
+ )
306
+
307
+ @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0072.xhtml", :validate => true)
311
308
  end
312
309
 
313
310
  it "should return 1 triple" do
@@ -319,27 +316,26 @@ EOF
319
316
  end
320
317
  end
321
318
 
322
- context "parsing a document with a profile containing a prefix mapping" do
319
+ describe "parsing a document with a profile containing a prefix mapping" do
323
320
  before :each do
324
- sampledoc = <<-EOF
325
- <?xml version="1.0" encoding="UTF-8"?>
326
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
327
- <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1">
328
- <head>
329
- <title>Test</title>
330
- <base href="http://example.org/"/>
331
- </head>
332
- <body profile="http://rdfa.digitalbazaar.com/test-suite/test-cases/tests/../profiles/basic">
333
- <div about="#me">
334
- <p>
335
- <span property="foaf:name">Ivan Herman</span>
336
- </p>
337
- </div>
338
- </body>
339
- </html>
340
- EOF
321
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
322
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
323
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1">
324
+ <head>
325
+ <title>Test</title>
326
+ <base href="http://example.org/"/>
327
+ </head>
328
+ <body profile="http://rdfa.digitalbazaar.com/test-suite/test-cases/tests/../../profiles/basic">
329
+ <div about="#me">
330
+ <p>
331
+ <span property="foaf:name">Ivan Herman</span>
332
+ </p>
333
+ </div>
334
+ </body>
335
+ </html>
336
+ )
341
337
 
342
- @graph = parse(sampledoc, :strict => true)
338
+ @graph = parse(sampledoc, :validate => true)
343
339
  @statement = @graph.statements.first
344
340
  end
345
341
 
@@ -360,27 +356,26 @@ EOF
360
356
  end
361
357
  end
362
358
 
363
- context "parsing a document with a profile containing a term mapping" do
359
+ describe "parsing a document with a profile containing a term mapping" do
364
360
  before :each do
365
- sampledoc = <<-EOF
366
- <?xml version="1.0" encoding="UTF-8"?>
367
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
368
- <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1">
369
- <head>
370
- <title>Test</title>
371
- <base href="http://example.org/"/>
372
- </head>
373
- <body profile="http://rdfa.digitalbazaar.com/test-suite/test-cases/tests/../profiles/foaf">
374
- <div about="#me">
375
- <p>
376
- <span property="name">Ivan Herman</span>
377
- </p>
378
- </div>
379
- </body>
380
- </html>
381
- EOF
361
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
362
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
363
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1">
364
+ <head>
365
+ <title>Test</title>
366
+ <base href="http://example.org/"/>
367
+ </head>
368
+ <body profile="http://rdfa.digitalbazaar.com/test-suite/test-cases/tests/../../profiles/foaf">
369
+ <div about="#me">
370
+ <p>
371
+ <span property="name">Ivan Herman</span>
372
+ </p>
373
+ </div>
374
+ </body>
375
+ </html>
376
+ )
382
377
 
383
- @graph = parse(sampledoc, :strict => true)
378
+ @graph = parse(sampledoc, :validate => true)
384
379
  @statement = @graph.statements.first
385
380
  end
386
381
 
@@ -401,16 +396,133 @@ EOF
401
396
  end
402
397
  end
403
398
 
399
+ describe :profiles do
400
+ before(:all) do
401
+ FileUtils.mkdir(TMP_DIR)
402
+ File.open(File.join(TMP_DIR, "profile.html"), "w") do |f|
403
+ f.write(%(<?xml version="1.0" encoding="UTF-8"?>
404
+ <!DOCTYPE html>
405
+ <html xmlns="http://www.w3.org/1999/xhtml">
406
+ <head>
407
+ <title>Test mappings</title>
408
+ </head>
409
+ <body prefix="rdfa: http://www.w3.org/ns/rdfa#">
410
+ <p typeof=""><span property="rdfa:uri">#{RDF::DC}</span><span property="rdfa:prefix">dc</span></p>
411
+ <p typeof=""><span property="rdfa:uri">#{RDF::DC.title}</span><span property="rdfa:term">title</span></p>
412
+ </body>
413
+ </html>
414
+ )
415
+ )
416
+ end
417
+
418
+ @doc = %(<?xml version="1.0" encoding="UTF-8"?>
419
+ <!DOCTYPE html>
420
+ <html xmlns="http://www.w3.org/1999/xhtml">
421
+ <body profile="http://example.com/profile">
422
+ <div about ="http://example.com/doc" typeof="dc:Agent">
423
+ <p property="title">A particular agent</p>
424
+ </div>
425
+ </body>
426
+ </html>
427
+ )
428
+ end
429
+
430
+ before(:each) do
431
+ @profile_repository = RDF::Repository.new(:title => "Test Profile Repository")
432
+ @debug = []
433
+ @reader = RDF::RDFa::Reader.new(@doc, :profile_repository => @profile_repository, :debug => @debug, :validate => true)
434
+ end
435
+
436
+ after(:all) do
437
+ FileUtils.rm_rf(TMP_DIR)
438
+ end
439
+
440
+ describe "new profile" do
441
+ before(:each) do
442
+ # Clear vocabulary cache
443
+ RDF::RDFa::Profile.cache.send(:initialize)
444
+ @graph = RDF::Graph.new
445
+ @reader.each do |statement|
446
+ @graph << statement
447
+ end
448
+ end
449
+
450
+ describe "processed graph" do
451
+ it "should have type dc:Agent" do
452
+ @graph.should have_statement(RDF::Statement.new(RDF::URI.new("http://example.com/doc"), RDF.type, RDF::DC.Agent))
453
+ end
454
+
455
+ it "should have property dc:title" do
456
+ @graph.should have_statement(RDF::Statement.new(RDF::URI.new("http://example.com/doc"), RDF::DC.title, RDF::Literal.new("A particular agent")))
457
+ end
458
+ end
459
+ end
460
+
461
+ describe "cached profile" do
462
+ before(:each) do
463
+ # Clear vocabulary cache
464
+ RDF::RDFa::Profile.cache.send(:initialize)
465
+ @reader.each {|s|}
466
+ end
467
+
468
+ it "should not re-parse profile" do
469
+ RDF::RDFa::Profile.cache.send(:initialize)
470
+ RDF::Reader.should_not_receive(:open).with("http://example.com/profile")
471
+ RDF::RDFa::Reader.new(@doc, :profile_repository => @profile_repository).each {|p|}
472
+ end
473
+
474
+ it "should create vocab_cache" do
475
+ RDF::RDFa::Profile.cache.should be_a(RDF::Util::Cache)
476
+ end
477
+ end
478
+
479
+ describe "profile content" do
480
+ before(:each) do
481
+ bn_p = RDF::Node.new("prefix")
482
+ bn_t = RDF::Node.new("term")
483
+ @profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.prefix, RDF::Literal.new("dc"))
484
+ @profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.uri, RDF::Literal.new(RDF::DC.to_s))
485
+ @profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.term, RDF::Literal.new("title"))
486
+ @profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.uri, RDF::Literal.new(RDF::DC.title.to_s))
487
+
488
+ # Clear vocabulary cache
489
+ RDF::RDFa::Profile.cache.send(:initialize)
490
+ end
491
+
492
+ it "should not recieve RDF::Reader.open" do
493
+ RDF::Reader.should_not_receive(:open).with("http://example.com/profile")
494
+ end
495
+
496
+ it "should have type dc:Agent" do
497
+ @graph = RDF::Graph.new
498
+ @reader.each do |statement|
499
+ @graph << statement
500
+ end
501
+
502
+ @graph.should have_statement(RDF::Statement.new(RDF::URI.new("http://example.com/doc"), RDF.type, RDF::DC.Agent))
503
+ end
504
+
505
+ it "should have property dc:title" do
506
+ @graph = RDF::Graph.new
507
+ @reader.each do |statement|
508
+ @graph << statement
509
+ end
510
+
511
+ @graph.should have_statement(RDF::Statement.new(RDF::URI.new("http://example.com/doc"), RDF::DC.title, RDF::Literal.new("A particular agent")))
512
+ end
513
+ end
514
+ end
515
+
404
516
  def self.test_cases(suite)
405
517
  RdfaHelper::TestCase.test_cases(suite)
406
518
  end
407
519
 
408
520
  # W3C Test suite from http://www.w3.org/2006/07/SWD/RDFa/testsuite/
409
- %w(xhtml xhtml11).each do |suite| # html4 html5
521
+ %w(xhtml html5 html5 svgtiny).each do |suite| # html4 html5
410
522
  describe "w3c #{suite} testcases" do
411
- describe "that are approved" do
523
+ describe "that are required" do
412
524
  test_cases(suite).each do |t|
413
- next unless t.status == "approved"
525
+ next unless t.classification =~ /required/
414
526
  #next unless t.name =~ /0001/
415
527
  specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
416
528
  #puts t.input
@@ -423,7 +535,7 @@ EOF
423
535
  :debug => t.debug,
424
536
  :version => t.version)
425
537
  end
426
- rescue Spec::Expectations::ExpectationNotMetError => e
538
+ rescue RSpec::Expectations::ExpectationNotMetError => e
427
539
  if t.input =~ /XMLLiteral/
428
540
  pending("XMLLiteral canonicalization not implemented yet")
429
541
  else
@@ -435,9 +547,37 @@ EOF
435
547
  end
436
548
  end
437
549
  end
438
- describe "that are unreviewed" do
550
+
551
+ describe "that are optional" do
552
+ test_cases(suite).each do |t|
553
+ next unless t.classification =~ /optional/
554
+ #next unless t.name =~ /0185/
555
+ #puts t.inspect
556
+ specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
557
+ begin
558
+ t.run_test do |rdfa_string|
559
+ t.debug = []
560
+ parse(rdfa_string,
561
+ :base_uri => t.informationResourceInput,
562
+ :debug => t.debug,
563
+ :version => t.version)
564
+ end
565
+ rescue SparqlException => e
566
+ pending(e.message) { raise }
567
+ rescue RSpec::Expectations::ExpectationNotMetError => e
568
+ if t.name =~ /01[789]\d/
569
+ raise
570
+ else
571
+ pending() { raise }
572
+ end
573
+ end
574
+ end
575
+ end
576
+ end
577
+
578
+ describe "that are buggy" do
439
579
  test_cases(suite).each do |t|
440
- next unless t.status == "unreviewed"
580
+ next unless t.classification =~ /buggy/
441
581
  #next unless t.name =~ /0185/
442
582
  #puts t.inspect
443
583
  specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
@@ -451,7 +591,7 @@ EOF
451
591
  end
452
592
  rescue SparqlException => e
453
593
  pending(e.message) { raise }
454
- rescue Spec::Expectations::ExpectationNotMetError => e
594
+ rescue RSpec::Expectations::ExpectationNotMetError => e
455
595
  if t.name =~ /01[789]\d/
456
596
  raise
457
597
  else