rdf-rdfxml 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,16 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
- include RdfContext
2
+ autoload :CGI, 'cgi'
3
3
 
4
- FOO_NS = Namespace.new("http://foo/", "foo")
4
+ class FOO < RDF::Vocabulary("http://foo/"); end
5
5
 
6
- describe "XML Serializer" do
6
+ describe "RDF::RDFXML::Writer" do
7
7
  before(:each) do
8
- @graph = Graph.new
8
+ @graph = RDF::Graph.new
9
9
  end
10
10
 
11
11
  describe "with types" do
12
12
  it "should serialize resource without type" do
13
- @graph.add_triple("http://release/", DC_NS.title, "foo")
13
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
14
14
  check_xpaths(
15
15
  serialize(:max_depth => 1, :attributes => :untyped),
16
16
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
@@ -19,8 +19,8 @@ describe "XML Serializer" do
19
19
  end
20
20
 
21
21
  it "should serialize resource with type" do
22
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.Release)
23
- @graph.add_triple("http://release/", DC_NS.title, "foo")
22
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
23
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
24
24
  check_xpaths(
25
25
  serialize(:max_depth => 1, :attributes => :untyped),
26
26
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
@@ -30,51 +30,51 @@ describe "XML Serializer" do
30
30
  end
31
31
 
32
32
  it "should serialize resource with two types as attribute" do
33
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.Release)
34
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.XtraRelease)
35
- @graph.add_triple("http://release/", DC_NS.title, "foo")
33
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
34
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
35
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
36
36
  check_xpaths(
37
37
  serialize(:max_depth => 1, :attributes => :untyped),
38
38
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
39
39
  "/rdf:RDF/foo:Release/@dc:title" => "foo",
40
- "/rdf:RDF/foo:Release/@rdf:type" => FOO_NS.XtraRelease.to_s
40
+ "/rdf:RDF/foo:Release/@rdf:type" => FOO.XtraRelease.to_s
41
41
  )
42
42
  end
43
43
 
44
44
  it "should serialize resource with two types as element" do
45
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.Release)
46
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.XtraRelease)
47
- @graph.add_triple("http://release/", DC_NS.title, "foo")
45
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
46
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
47
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
48
48
  check_xpaths(
49
49
  serialize(:max_depth => 1, :attributes => :none),
50
50
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
51
51
  "/rdf:RDF/foo:Release/dc:title" => true,
52
- "/rdf:RDF/foo:Release/rdf:type" => %(<rdf:type rdf:resource="#{FOO_NS.XtraRelease}"/>)
52
+ "/rdf:RDF/foo:Release/rdf:type" => %(<rdf:type rdf:resource="#{FOO.XtraRelease}"/>)
53
53
  )
54
54
  end
55
55
 
56
56
  it "should serialize resource with three types as element" do
57
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.Release)
58
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.XtraRelease)
59
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.XXtraRelease)
60
- @graph.add_triple("http://release/", DC_NS.title, "foo")
57
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
58
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
59
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XXtraRelease]
60
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
61
61
  check_xpaths(
62
62
  serialize(:max_depth => 1, :attributes => :typed),
63
63
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
64
64
  "/rdf:RDF/foo:Release/@dc:title" => true,
65
- %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO_NS.XtraRelease}"]) => true,
66
- %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO_NS.XXtraRelease}"]) => true
65
+ %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => true,
66
+ %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XXtraRelease}"]) => true
67
67
  )
68
68
  end
69
69
  end
70
70
 
71
71
  describe "with children" do
72
72
  it "should serialize referenced resource by ref" do
73
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.Release)
74
- @graph.add_triple("http://release/", DC_NS.title, "foo")
75
- @graph.add_triple("http://release/contributor", RDF_TYPE, FOO_NS.Contributor)
76
- @graph.add_triple("http://release/contributor", DC_NS.title, "bar")
77
- @graph.add_triple("http://release/", FOO_NS.releaseContributor, "http://release/contributor")
73
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
74
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
75
+ @graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
76
+ @graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
77
+ @graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
78
78
  check_xpaths(
79
79
  serialize(:max_depth => 1, :attributes => :untyped),
80
80
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
@@ -86,11 +86,11 @@ describe "XML Serializer" do
86
86
  end
87
87
 
88
88
  it "should serialize referenced resource by inclusion" do
89
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.Release)
90
- @graph.add_triple("http://release/", DC_NS.title, "foo")
91
- @graph.add_triple("http://release/contributor", RDF_TYPE, FOO_NS.Contributor)
92
- @graph.add_triple("http://release/contributor", DC_NS.title, "bar")
93
- @graph.add_triple("http://release/", FOO_NS.releaseContributor, "http://release/contributor")
89
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
90
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
91
+ @graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
92
+ @graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
93
+ @graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
94
94
  check_xpaths(
95
95
  serialize(:max_depth => 3, :attributes => :untyped),
96
96
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
@@ -102,9 +102,9 @@ describe "XML Serializer" do
102
102
 
103
103
  describe "with sequences" do
104
104
  it "should serialize rdf:Seq with rdf:li" do
105
- @graph.add_triple("http://example/seq", RDF_TYPE, RDF_NS.Seq)
106
- @graph.add_triple("http://example/seq", RDF_NS._1, "http://example/first")
107
- @graph.add_triple("http://example/seq", RDF_NS._2, "http://example/second")
105
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
106
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
107
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
108
108
  check_xpaths(
109
109
  serialize(:max_depth => 1, :attributes => :untyped),
110
110
  "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
@@ -114,9 +114,9 @@ describe "XML Serializer" do
114
114
  end
115
115
 
116
116
  it "should serialize rdf:Seq with multiple rdf:li in proper sequence" do
117
- @graph.add_triple("http://example/seq", RDF_TYPE, RDF_NS.Seq)
118
- @graph.add_triple("http://example/seq", RDF_NS._2, "http://example/second")
119
- @graph.add_triple("http://example/seq", RDF_NS._1, "http://example/first")
117
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
118
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
119
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
120
120
  check_xpaths(
121
121
  serialize(:max_depth => 1, :attributes => :untyped),
122
122
  "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
@@ -126,9 +126,9 @@ describe "XML Serializer" do
126
126
  end
127
127
 
128
128
  it "should serialize rdf:Bag with multiple rdf:li" do
129
- @graph.add_triple("http://example/seq", RDF_TYPE, RDF_NS.Bag)
130
- @graph.add_triple("http://example/seq", RDF_NS._2, "http://example/second")
131
- @graph.add_triple("http://example/seq", RDF_NS._1, "http://example/first")
129
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Bag]
130
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
131
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
132
132
  check_xpaths(
133
133
  serialize(:max_depth => 1, :attributes => :untyped),
134
134
  "/rdf:RDF/rdf:Bag/@rdf:about" => "http://example/seq",
@@ -138,9 +138,9 @@ describe "XML Serializer" do
138
138
  end
139
139
 
140
140
  it "should serialize rdf:Alt with multiple rdf:li" do
141
- @graph.add_triple("http://example/seq", RDF_TYPE, RDF_NS.Alt)
142
- @graph.add_triple("http://example/seq", RDF_NS._2, "http://example/second")
143
- @graph.add_triple("http://example/seq", RDF_NS._1, "http://example/first")
141
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Alt]
142
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
143
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
144
144
  check_xpaths(
145
145
  serialize(:max_depth => 1, :attributes => :untyped),
146
146
  "/rdf:RDF/rdf:Alt/@rdf:about" => "http://example/seq",
@@ -151,23 +151,23 @@ describe "XML Serializer" do
151
151
  end
152
152
 
153
153
  describe "with lists" do
154
- it "should serialize List rdf:first/rdf:rest" do
155
- @graph.parse(%(@prefix foo: <http://foo/> . foo:author foo:is (Gregg Barnum Kellogg).), "http://foo/", :type => :ttl)
156
- check_xpaths(
157
- serialize({}),
158
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://foo/author",
159
- "/rdf:RDF/rdf:Description/foo:is/@rdf:parseType" => "Collection",
160
- %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) => true,
161
- %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) => true,
162
- %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) => true,
163
- %(//rdf:first) => false
164
- )
165
- end
154
+ # it "should serialize List rdf:first/rdf:rest" do
155
+ # @graph.parse(%(@prefix foo: <http://foo/> . foo:author foo:is (Gregg Barnum Kellogg).), "http://foo/", :type => :ttl)
156
+ # check_xpaths(
157
+ # serialize({}),
158
+ # "/rdf:RDF/rdf:Description/@rdf:about" => "http://foo/author",
159
+ # "/rdf:RDF/rdf:Description/foo:is/@rdf:parseType" => "Collection",
160
+ # %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) => true,
161
+ # %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) => true,
162
+ # %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) => true,
163
+ # %(//rdf:first) => false
164
+ # )
165
+ # end
166
166
 
167
167
  it "should serialize resource with multiple rdf:li in proper sequence" do
168
- @graph.add_triple("http://example/seq", RDF_TYPE, RDF_NS.Seq)
169
- @graph.add_triple("http://example/seq", RDF_NS._2, "http://example/second")
170
- @graph.add_triple("http://example/seq", RDF_NS._1, "http://example/first")
168
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
169
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
170
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
171
171
  check_xpaths(
172
172
  serialize(:max_depth => 1, :attributes => :untyped),
173
173
  "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
@@ -179,7 +179,7 @@ describe "XML Serializer" do
179
179
 
180
180
  describe "with untyped literals" do
181
181
  it "should seralize as element if :attributes == :none" do
182
- @graph.add_triple("http://release/", DC_NS.title, "foo")
182
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
183
183
  check_xpaths(
184
184
  serialize(:attributes => :none),
185
185
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
@@ -188,7 +188,7 @@ describe "XML Serializer" do
188
188
  end
189
189
 
190
190
  it "should seralize as attribute if :attributes == :untyped or :typed" do
191
- @graph.add_triple("http://release/", DC_NS.title, "foo")
191
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
192
192
  check_xpaths(
193
193
  serialize(:attributes => :untyped),
194
194
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
@@ -201,8 +201,8 @@ describe "XML Serializer" do
201
201
  )
202
202
  end
203
203
 
204
- it "should output untyped without lang as attribute lang set" do
205
- @graph.add_triple("http://release/", DC_NS.title, "foo")
204
+ it "should output untyped without lang if attribute lang set" do
205
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
206
206
  check_xpaths(
207
207
  serialize(:attributes => :untyped, :lang => "de"),
208
208
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
@@ -212,7 +212,7 @@ describe "XML Serializer" do
212
212
 
213
213
  describe "with language" do
214
214
  it "should output property for title with language" do
215
- @graph.add_triple("http://release/", DC_NS.title, Literal.untyped("foo", "en-us"))
215
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
216
216
  check_xpaths(
217
217
  serialize(:attributes => :untyped, :lang => "de"),
218
218
  "/rdf:RDF/@xml:lang" => "de",
@@ -223,7 +223,7 @@ describe "XML Serializer" do
223
223
  end
224
224
 
225
225
  it "should output untyped as attribute if lang is default" do
226
- @graph.add_triple("http://release/", DC_NS.title, Literal.untyped("foo", "de"))
226
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
227
227
  check_xpaths(
228
228
  serialize(:attributes => :untyped, :lang => "de"),
229
229
  "/rdf:RDF/@xml:lang" => "de",
@@ -233,7 +233,7 @@ describe "XML Serializer" do
233
233
  end
234
234
 
235
235
  it "should output untyped as property if lang set and no default" do
236
- @graph.add_triple("http://release/", DC_NS.title, Literal.untyped("foo", "de"))
236
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
237
237
  check_xpaths(
238
238
  serialize(:attributes => :untyped),
239
239
  "/rdf:RDF/@xml:lang" => false,
@@ -243,7 +243,7 @@ describe "XML Serializer" do
243
243
  end
244
244
 
245
245
  it "should output untyped as property if lang set and not default" do
246
- @graph.add_triple("http://release/", DC_NS.title, Literal.untyped("foo", "de"))
246
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
247
247
  check_xpaths(
248
248
  serialize(:attributes => :untyped, :lang => "en-us"),
249
249
  "/rdf:RDF/@xml:lang" => "en-us",
@@ -253,8 +253,8 @@ describe "XML Serializer" do
253
253
  end
254
254
 
255
255
  it "should output multiple untyped attributes values through properties" do
256
- @graph.add_triple("http://release/", DC_NS.title, Literal.untyped("foo", "de"))
257
- @graph.add_triple("http://release/", DC_NS.title, Literal.untyped("foo", "en-us"))
256
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
257
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
258
258
  check_xpaths(
259
259
  serialize(:attributes => :untyped, :lang => "en-us"),
260
260
  "/rdf:RDF/@xml:lang" => "en-us",
@@ -265,11 +265,11 @@ describe "XML Serializer" do
265
265
  end
266
266
 
267
267
  it "should output typed node as attribute" do
268
- @graph.add_triple("http://release/", DC_NS.title, Literal.typed("foo", XSD_NS.string))
268
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
269
269
  check_xpaths(
270
270
  serialize(:attributes => :untyped),
271
271
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
272
- "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title rdf:datatype="#{XSD_NS.string}">foo</dc:title>)
272
+ "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>)
273
273
  )
274
274
  check_xpaths(
275
275
  serialize(:attributes => :typed),
@@ -279,48 +279,46 @@ describe "XML Serializer" do
279
279
  end
280
280
 
281
281
  it "should output multiple typed values through properties" do
282
- @graph.add_triple("http://release/", DC_NS.title, Literal.typed("foo", XSD_NS.string))
283
- @graph.add_triple("http://release/", DC_NS.title, Literal.typed("bar", XSD_NS.string))
282
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
283
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("bar", :datatype => RDF::XSD.string)]
284
284
  check_xpaths(
285
285
  serialize(:attributes => :untyped),
286
286
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
287
- "/rdf:RDF/rdf:Description/dc:title[contains(., 'foo')]" => %(<dc:title rdf:datatype="#{XSD_NS.string}">foo</dc:title>),
288
- "/rdf:RDF/rdf:Description/dc:title[contains(., 'bar')]" => %(<dc:title rdf:datatype="#{XSD_NS.string}">bar</dc:title>)
287
+ "/rdf:RDF/rdf:Description/dc:title[contains(., 'foo')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>),
288
+ "/rdf:RDF/rdf:Description/dc:title[contains(., 'bar')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">bar</dc:title>)
289
289
  )
290
290
  end
291
291
  end
292
-
292
+
293
+ # FIXME
293
294
  describe "with default namespace" do
294
295
  it "should serialize with default namespace" do
295
- @graph.add_triple("http://release/", RDF_TYPE, FOO_NS.Release)
296
- @graph.add_triple("http://release/", DC_NS.title, "foo")
297
- @graph.add_triple("http://release/", FOO_NS.pred, FOO_NS.obj)
298
- @graph.bind(Namespace.new(FOO_NS.uri, ""))
296
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
297
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
298
+ @graph << [RDF::URI.new("http://release/"), FOO.pred, FOO.obj]
299
299
 
300
- #$DEBUG = true
301
- xml = serialize(:max_depth => 1, :attributes => :untyped)
302
- #puts xml
300
+ xml = serialize(:max_depth => 1, :attributes => :untyped, :default_namespace => FOO.to_s)
303
301
  xml.should =~ /<Release/
304
302
  xml.should =~ /<pred/
305
303
  doc = Nokogiri::XML.parse(xml)
306
- doc.at_xpath("/rdf:RDF/#{FOO_NS.prefix}:Release/#{FOO_NS.prefix}:pred/@rdf:resource", doc.namespaces).to_s.should == FOO_NS.obj.to_s
304
+ doc.at_xpath("/rdf:RDF/foo:Release/foo:pred/@rdf:resource", doc.namespaces).to_s.should == FOO.obj.to_s
307
305
  end
308
306
  end
309
307
 
310
308
  describe "with base" do
311
309
  it "should generate relative about URI" do
312
- @graph.add_triple("http://release/a", FOO_NS.ref, "http://release/b")
313
- check_xpaths(
314
- serialize(:attributes => :untyped, :base => "http://release/"),
315
- "/rdf:RDF/rdf:Description/@rdf:about" => "a",
316
- "/rdf:RDF/rdf:Description/foo:ref/@rdf:resource" => "b"
317
- )
310
+ @graph << [RDF::URI.new("http://release/a"), FOO.ref, RDF::URI.new("http://release/b")]
311
+ check_xpaths(
312
+ serialize(:attributes => :untyped, :base_uri => "http://release/"),
313
+ "/rdf:RDF/rdf:Description/@rdf:about" => "a",
314
+ "/rdf:RDF/rdf:Description/foo:ref/@rdf:resource" => "b"
315
+ )
318
316
  end
319
317
  end
320
318
 
321
319
  describe "with bnodes" do
322
320
  it "should not generate nodeID attribute unless node is referenced as an object" do
323
- @graph.add_triple(BNode.new("a"), DC_NS.title, "foo")
321
+ @graph << [RDF::Node.new("a"), RDF::DC.title, "foo"]
324
322
  check_xpaths(
325
323
  serialize(:attributes => :untyped, :base => "http://release/"),
326
324
  "/rdf:RDF/rdf:Description/@dc:title" => "foo",
@@ -329,34 +327,37 @@ describe "XML Serializer" do
329
327
  end
330
328
 
331
329
  it "should generate a nodeID attribute if node is referenced as an object" do
332
- bn = BNode.new("a")
333
- @graph.add_triple(bn, DC_NS.title, "foo")
334
- @graph.add_triple(bn, OWL_NS.equals, bn)
330
+ bn = RDF::Node.new("a")
331
+ @graph << [bn, RDF::DC.title, "foo"]
332
+ @graph << [bn, RDF::OWL.equals, bn]
335
333
  check_xpaths(
336
334
  serialize(:attributes => :untyped, :base => "http://release/"),
337
335
  "/rdf:RDF/rdf:Description/@dc:title" => "foo",
338
- "/rdf:RDF/rdf:Description/@rdf:nodeID" => /Na$/,
339
- "/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /Na$/
336
+ "/rdf:RDF/rdf:Description/@rdf:nodeID" => /a$/,
337
+ "/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /a$/
340
338
  )
341
339
  end
342
340
 
343
341
  it "should replicate rdfcore/rdfms-seq-representation" do
344
- @graph.parse(%(
345
- <http://example.org/eg#eric> a [ <http://example.org/eg#intersectionOf> (<http://example.org/eg#Person> <http://example.org/eg#Male>)] .
346
- ))
347
- graph2 = Graph.new
348
- graph2.parse(serialize(:format => :xml)).should be_equivalent_graph(@graph)
342
+ begin
343
+ @graph.parse(%(
344
+ <http://example.org/eg#eric> a [ <http://example.org/eg#intersectionOf> (<http://example.org/eg#Person> <http://example.org/eg#Male>)] .
345
+ ))
346
+ graph2 = Graph.new
347
+ graph2.parse(serialize(:format => :xml)).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
348
+ rescue
349
+ pending("Requires Turtle reader")
350
+ end
349
351
  end
350
352
  end
351
353
 
352
354
  def check_xpaths(doc, paths)
353
- puts doc if $DEBUG || $verbose
355
+ puts doc.to_s if $DEBUG || $verbose
354
356
  doc = Nokogiri::XML.parse(doc)
355
- #puts "doc: #{doc.to_s}"
356
357
  doc.should be_a(Nokogiri::XML::Document)
358
+ doc.root.should be_a(Nokogiri::XML::Element)
357
359
  paths.each_pair do |path, value|
358
- puts "xpath: #{path.inspect}" if $DEBUG
359
- puts doc.root.at_xpath(path, @namespaces).inspect if $DEBUG
360
+ @debug << doc.root.at_xpath(path, @namespaces).to_s if $DEBUG
360
361
  case value
361
362
  when false
362
363
  doc.root.at_xpath(path, doc.namespaces).should be_nil
@@ -372,15 +373,18 @@ describe "XML Serializer" do
372
373
  end
373
374
 
374
375
  # Parse generated graph and compare to source
375
- Graph.new.parse(doc, "http://release/", :format => :xml).should
376
- be_equivalent_graph(@graph, :about => "http://release/")
376
+ #graph = RDF::Graph.new
377
+ #RDF::RDFXML::Reader.new(doc, :base_uri => "http://release/", :format => :rdf).each {|st| graph << st}
378
+ #graph.should be_equivalent_graph(@graph, :about => "http://release/", :trace => @debug.join("\n"))
377
379
  end
378
380
 
379
381
  # Serialize ntstr to a string and compare against regexps
380
- def serialize(options)
381
- #$DEBUG = true
382
- result = @graph.serialize(options.merge(:format => :xml))
383
- #$DEBUG = false
382
+ def serialize(options = {})
383
+ @debug = []
384
+ result = RDF::RDFXML::Writer.buffer(options.merge(:debug => @debug)) do |writer|
385
+ writer.write_graph(@graph)
386
+ end
387
+ puts @debug.join("\n") if $DEBUG
384
388
  result
385
389
  end
386
390
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-rdfxml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gregg Kellogg
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-07 00:00:00 -04:00
18
+ date: 2010-06-12 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -117,8 +117,13 @@ files:
117
117
  - lib/rdf/rdfxml.rb
118
118
  - lib/rdf/rdfxml/format.rb
119
119
  - lib/rdf/rdfxml/patches/array_hacks.rb
120
+ - lib/rdf/rdfxml/patches/graph_properties.rb
121
+ - lib/rdf/rdfxml/patches/literal_hacks.rb
120
122
  - lib/rdf/rdfxml/patches/nokogiri_hacks.rb
123
+ - lib/rdf/rdfxml/patches/qname_hacks.rb
121
124
  - lib/rdf/rdfxml/patches/rdf_escape.rb
125
+ - lib/rdf/rdfxml/patches/seq.rb
126
+ - lib/rdf/rdfxml/patches/uri_hacks.rb
122
127
  - lib/rdf/rdfxml/reader.rb
123
128
  - lib/rdf/rdfxml/version.rb
124
129
  - lib/rdf/rdfxml/vocab.rb
@@ -126,7 +131,10 @@ files:
126
131
  - rdf-rdfxml.gemspec
127
132
  - script/console
128
133
  - spec/format_spec.rb
134
+ - spec/graph_spec.rb
135
+ - spec/literal_spec.rb
129
136
  - spec/matchers.rb
137
+ - spec/rdf_escape_spec.rb
130
138
  - spec/rdf_helper.rb
131
139
  - spec/rdf_tests/cc197bad-dc9c-440d-a5b5-d52ba2e14234.nt
132
140
  - spec/rdf_tests/cc197bad-dc9c-440d-a5b5-d52ba2e14234.rdf
@@ -490,7 +498,8 @@ files:
490
498
  - spec/reader_spec.rb
491
499
  - spec/spec.opts
492
500
  - spec/spec_helper.rb
493
- - spec/xml_serializer_spec.rb
501
+ - spec/uri_spec.rb
502
+ - spec/writer_spec.rb
494
503
  has_rdoc: true
495
504
  homepage: http://github.com/gkellogg/rdf-rdfxml
496
505
  licenses: []
@@ -527,8 +536,12 @@ specification_version: 3
527
536
  summary: RDF/XML reader/writer for RDF.rb.
528
537
  test_files:
529
538
  - spec/format_spec.rb
539
+ - spec/graph_spec.rb
540
+ - spec/literal_spec.rb
530
541
  - spec/matchers.rb
542
+ - spec/rdf_escape_spec.rb
531
543
  - spec/rdf_helper.rb
532
544
  - spec/reader_spec.rb
533
545
  - spec/spec_helper.rb
534
- - spec/xml_serializer_spec.rb
546
+ - spec/uri_spec.rb
547
+ - spec/writer_spec.rb