rdf-rdfxml 0.2.3 → 0.3.0

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/spec/writer_spec.rb CHANGED
@@ -13,389 +13,442 @@ describe "RDF::RDFXML::Writer" do
13
13
 
14
14
  it_should_behave_like RDF_Writer
15
15
 
16
- describe "with types" do
17
- it "should serialize resource without type" do
18
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
19
- check_xpaths(
20
- serialize(:max_depth => 1, :attributes => :untyped),
21
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
22
- "/rdf:RDF/rdf:Description/@dc:title" => "foo"
23
- )
24
- end
16
+ describe "#buffer" do
17
+ describe "with types" do
18
+ it "should serialize resource without type" do
19
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
20
+ check_xpaths(
21
+ serialize(:max_depth => 1, :attributes => :untyped),
22
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
23
+ "/rdf:RDF/rdf:Description/@dc:title" => "foo"
24
+ )
25
+ end
25
26
 
26
- it "should serialize resource with type" do
27
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
28
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
29
- check_xpaths(
30
- serialize(:max_depth => 1, :attributes => :untyped),
31
- "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
32
- "/rdf:RDF/foo:Release/@dc:title" =>"foo",
33
- "/rdf:RDF/foo:Release/rdf:type" => ""
34
- )
35
- end
27
+ it "should serialize resource with type" do
28
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
29
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
30
+ check_xpaths(
31
+ serialize(:max_depth => 1, :attributes => :untyped),
32
+ "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
33
+ "/rdf:RDF/foo:Release/@dc:title" =>"foo",
34
+ "/rdf:RDF/foo:Release/rdf:type" => ""
35
+ )
36
+ end
36
37
 
37
- it "should serialize resource with two types as attribute" do
38
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
39
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
40
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
41
- check_xpaths(
42
- serialize(:max_depth => 1, :attributes => :untyped),
43
- "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
44
- "/rdf:RDF/foo:Release/@dc:title" => "foo",
45
- "/rdf:RDF/foo:Release/@rdf:type" => FOO.XtraRelease.to_s
46
- )
47
- end
38
+ it "should serialize resource with two types as attribute" do
39
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
40
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
41
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
42
+ check_xpaths(
43
+ serialize(:max_depth => 1, :attributes => :untyped),
44
+ "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
45
+ "/rdf:RDF/foo:Release/@dc:title" => "foo",
46
+ "/rdf:RDF/foo:Release/@rdf:type" => FOO.XtraRelease.to_s
47
+ )
48
+ end
48
49
 
49
- it "should serialize resource with two types as element" do
50
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
51
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
52
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
53
- check_xpaths(
54
- serialize(:max_depth => 1, :attributes => :none),
55
- "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
56
- "/rdf:RDF/foo:Release/dc:title" => true,
57
- "/rdf:RDF/foo:Release/rdf:type" => %(<rdf:type rdf:resource="#{FOO.XtraRelease}"/>)
58
- )
59
- end
50
+ it "should serialize resource with two types as element" do
51
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
52
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
53
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
54
+ check_xpaths(
55
+ serialize(:max_depth => 1, :attributes => :none),
56
+ "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
57
+ "/rdf:RDF/foo:Release/dc:title" => true,
58
+ %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => true,
59
+ %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.Release}"]) => false
60
+ )
61
+ end
60
62
 
61
- it "should serialize resource with three types as element" do
62
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
63
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
64
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XXtraRelease]
65
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
66
- check_xpaths(
67
- serialize(:max_depth => 1, :attributes => :typed),
68
- "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
69
- "/rdf:RDF/foo:Release/@dc:title" => true,
70
- %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => true,
71
- %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XXtraRelease}"]) => true
72
- )
73
- end
74
- end
75
-
76
- describe "with children" do
77
- it "should serialize referenced resource by ref" do
78
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
79
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
80
- @graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
81
- @graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
82
- @graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
63
+ it "should serialize resource with three types as element" do
64
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
65
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
66
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XXtraRelease]
67
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
83
68
  check_xpaths(
84
- serialize(:max_depth => 1, :attributes => :untyped),
85
- "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
86
- "/rdf:RDF/foo:Release/@dc:title" => "foo",
87
- "/rdf:RDF/foo:Release/foo:releaseContributor/@rdf:resource" => "http://release/contributor",
88
- "/rdf:RDF/foo:Contributor/@rdf:about" => "http://release/contributor",
89
- "/rdf:RDF/foo:Contributor/@dc:title" => "bar"
90
- )
69
+ serialize(:max_depth => 1, :attributes => :typed),
70
+ "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
71
+ "/rdf:RDF/foo:Release/@dc:title" => true,
72
+ %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => true,
73
+ %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XXtraRelease}"]) => true
74
+ )
75
+ end
91
76
  end
92
77
 
93
- it "should serialize referenced resource by inclusion" do
94
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
95
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
96
- @graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
97
- @graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
98
- @graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
99
- check_xpaths(
100
- serialize(:max_depth => 3, :attributes => :untyped),
101
- "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
102
- "/rdf:RDF/foo:Release/@dc:title" => "foo",
103
- "/rdf:RDF/foo:Release/foo:releaseContributor/foo:Contributor/@rdf:about" => "http://release/contributor"
104
- )
105
- end
106
- end
78
+ describe "with children" do
79
+ it "should serialize referenced resource by ref" do
80
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
81
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
82
+ @graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
83
+ @graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
84
+ @graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
85
+ check_xpaths(
86
+ serialize(:max_depth => 1, :attributes => :untyped),
87
+ "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
88
+ "/rdf:RDF/foo:Release/@dc:title" => "foo",
89
+ "/rdf:RDF/foo:Release/foo:releaseContributor/@rdf:resource" => "http://release/contributor",
90
+ "/rdf:RDF/foo:Contributor/@rdf:about" => "http://release/contributor",
91
+ "/rdf:RDF/foo:Contributor/@dc:title" => "bar"
92
+ )
93
+ end
107
94
 
108
- describe "with sequences" do
109
- it "should serialize rdf:Seq with rdf:li" do
110
- @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
111
- @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
112
- @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
113
- check_xpaths(
114
- serialize(:max_depth => 1, :attributes => :untyped),
115
- "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
116
- %(/rdf:RDF/rdf:Seq/rdf:li[@rdf:resource="http://example/first"]) => true,
117
- %(/rdf:RDF/rdf:Seq/rdf:li[@rdf:resource="http://example/second"]) => true
118
- )
95
+ it "should serialize referenced resource by inclusion" do
96
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
97
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
98
+ @graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
99
+ @graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
100
+ @graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
101
+ check_xpaths(
102
+ serialize(:max_depth => 3, :attributes => :untyped),
103
+ "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
104
+ "/rdf:RDF/foo:Release/@dc:title" => "foo",
105
+ "/rdf:RDF/foo:Release/foo:releaseContributor/foo:Contributor/@rdf:about" => "http://release/contributor"
106
+ )
107
+ end
119
108
  end
120
109
 
121
- it "should serialize rdf:Seq with multiple rdf:li in proper sequence" do
122
- @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
123
- @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
124
- @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
125
- check_xpaths(
126
- serialize(:max_depth => 1, :attributes => :untyped),
127
- "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
128
- %(/rdf:RDF/rdf:Seq/rdf:li[@rdf:resource="http://example/first"]) => true,
129
- %(/rdf:RDF/rdf:Seq/rdf:li[@rdf:resource="http://example/second"]) => true
130
- )
131
- end
110
+ describe "with sequences" do
111
+ it "should serialize rdf:Seq with rdf:_n" do
112
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
113
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
114
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
115
+ check_xpaths(
116
+ serialize(:max_depth => 1, :attributes => :untyped),
117
+ "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
118
+ %(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => true,
119
+ %(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => true
120
+ )
121
+ end
122
+
123
+ it "should serialize rdf:Seq with rdf:_n in proper sequence" do
124
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
125
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
126
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
127
+ check_xpaths(
128
+ serialize(:max_depth => 1, :attributes => :untyped),
129
+ "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
130
+ %(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => true,
131
+ %(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => true
132
+ )
133
+ end
132
134
 
133
- it "should serialize rdf:Bag with multiple rdf:li" do
134
- @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Bag]
135
- @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
136
- @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
137
- check_xpaths(
138
- serialize(:max_depth => 1, :attributes => :untyped),
139
- "/rdf:RDF/rdf:Bag/@rdf:about" => "http://example/seq",
140
- %(/rdf:RDF/rdf:Bag/rdf:li[@rdf:resource="http://example/first"]) => true,
141
- %(/rdf:RDF/rdf:Bag/rdf:li[@rdf:resource="http://example/second"]) => true
142
- )
143
- end
135
+ it "should serialize rdf:Bag with rdf:_n" do
136
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Bag]
137
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
138
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
139
+ check_xpaths(
140
+ serialize(:max_depth => 1, :attributes => :untyped),
141
+ "/rdf:RDF/rdf:Bag/@rdf:about" => "http://example/seq",
142
+ %(/rdf:RDF/rdf:Bag/rdf:_1[@rdf:resource="http://example/first"]) => true,
143
+ %(/rdf:RDF/rdf:Bag/rdf:_2[@rdf:resource="http://example/second"]) => true
144
+ )
145
+ end
144
146
 
145
- it "should serialize rdf:Alt with multiple rdf:li" do
146
- @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Alt]
147
- @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
148
- @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
149
- check_xpaths(
150
- serialize(:max_depth => 1, :attributes => :untyped),
151
- "/rdf:RDF/rdf:Alt/@rdf:about" => "http://example/seq",
152
- %(/rdf:RDF/rdf:Alt/rdf:li[@rdf:resource="http://example/first"]) => true,
153
- %(/rdf:RDF/rdf:Alt/rdf:li[@rdf:resource="http://example/second"]) => true
154
- )
147
+ it "should serialize rdf:Alt with multiple rdf:_2" do
148
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Alt]
149
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
150
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
151
+ check_xpaths(
152
+ serialize(:max_depth => 1, :attributes => :untyped),
153
+ "/rdf:RDF/rdf:Alt/@rdf:about" => "http://example/seq",
154
+ %(/rdf:RDF/rdf:Alt/rdf:_1[@rdf:resource="http://example/first"]) => true,
155
+ %(/rdf:RDF/rdf:Alt/rdf:_2[@rdf:resource="http://example/second"]) => true
156
+ )
157
+ end
155
158
  end
156
- end
157
159
 
158
- describe "with lists" do
159
- # it "should serialize List rdf:first/rdf:rest" do
160
- # @graph.parse(%(@prefix foo: <http://foo/> . foo:author foo:is (Gregg Barnum Kellogg).), "http://foo/", :type => :ttl)
161
- # check_xpaths(
162
- # serialize({}),
163
- # "/rdf:RDF/rdf:Description/@rdf:about" => "http://foo/author",
164
- # "/rdf:RDF/rdf:Description/foo:is/@rdf:parseType" => "Collection",
165
- # %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) => true,
166
- # %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) => true,
167
- # %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) => true,
168
- # %(//rdf:first) => false
169
- # )
170
- # end
160
+ describe "with lists" do
161
+ it "should serialize List rdf:first/rdf:rest" do
162
+ @graph = parse(%(
163
+ @prefix foo: <http://foo/> . foo:author foo:is (:Gregg :Barnum :Kellogg) .
164
+ ), :base_uri => "http://foo/", :reader => RDF::N3::Reader)
165
+ check_xpaths(
166
+ serialize({}),
167
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://foo/author",
168
+ "/rdf:RDF/rdf:Description/foo:is/@rdf:parseType" => "Collection",
169
+ %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) => true,
170
+ %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) => true,
171
+ %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) => true,
172
+ %(//rdf:first) => false
173
+ )
174
+ end
171
175
 
172
- it "should serialize resource with multiple rdf:li in proper sequence" do
173
- @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
174
- @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
175
- @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
176
- check_xpaths(
177
- serialize(:max_depth => 1, :attributes => :untyped),
178
- "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
179
- %(/rdf:RDF/rdf:Seq/rdf:li[@rdf:resource="http://example/first"]) => true,
180
- %(/rdf:RDF/rdf:Seq/rdf:li[@rdf:resource="http://example/second"]) => true
181
- )
176
+ it "should serialize resource with rdf:_n in proper sequence" do
177
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
178
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
179
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
180
+ check_xpaths(
181
+ serialize(:max_depth => 1, :attributes => :untyped),
182
+ "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
183
+ %(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => true,
184
+ %(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => true
185
+ )
186
+ end
182
187
  end
183
- end
184
188
 
185
- describe "with untyped literals" do
186
- it "should seralize as element if :attributes == :none" do
187
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
188
- check_xpaths(
189
- serialize(:attributes => :none),
190
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
191
- "/rdf:RDF/rdf:Description/dc:title" => "<dc:title>foo</dc:title>"
192
- )
193
- end
189
+ describe "with untyped literals" do
190
+ it "should seralize as element if :attributes == :none" do
191
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
192
+ check_xpaths(
193
+ serialize(:attributes => :none),
194
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
195
+ "/rdf:RDF/rdf:Description/dc:title" => "<dc:title>foo</dc:title>"
196
+ )
197
+ end
194
198
 
195
- it "should seralize as attribute if :attributes == :untyped or :typed" do
196
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
197
- check_xpaths(
198
- serialize(:attributes => :untyped),
199
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
200
- "/rdf:RDF/rdf:Description/@dc:title" => "foo"
201
- )
202
- check_xpaths(
203
- serialize(:attributes => :typed),
204
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
205
- "/rdf:RDF/rdf:Description/@dc:title" => "foo"
206
- )
207
- end
199
+ it "should seralize as attribute if :attributes == :untyped or :typed" do
200
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
201
+ check_xpaths(
202
+ serialize(:attributes => :untyped),
203
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
204
+ "/rdf:RDF/rdf:Description/@dc:title" => "foo"
205
+ )
206
+ check_xpaths(
207
+ serialize(:attributes => :typed),
208
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
209
+ "/rdf:RDF/rdf:Description/@dc:title" => "foo"
210
+ )
211
+ end
208
212
 
209
- it "should output untyped without lang if attribute lang set" do
210
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
211
- check_xpaths(
212
- serialize(:attributes => :untyped, :lang => "de"),
213
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
214
- "/rdf:RDF/rdf:Description/@dc:title" => "foo"
215
- )
216
- end
213
+ it "should output untyped without lang if attribute lang set" do
214
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
215
+ check_xpaths(
216
+ serialize(:attributes => :untyped, :lang => "de"),
217
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
218
+ "/rdf:RDF/rdf:Description/@dc:title" => "foo"
219
+ )
220
+ end
217
221
 
218
- describe "with language" do
219
- it "should output property for title with language" do
220
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
222
+ describe "with language" do
223
+ it "should output property for title with language" do
224
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
225
+ check_xpaths(
226
+ serialize(:attributes => :untyped, :lang => "de"),
227
+ "/rdf:RDF/@xml:lang" => "de",
228
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
229
+ "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="en-us">foo</dc:title>)
230
+ )
231
+ end
232
+ end
233
+
234
+ it "should output untyped as attribute if lang is default" do
235
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
221
236
  check_xpaths(
222
237
  serialize(:attributes => :untyped, :lang => "de"),
223
238
  "/rdf:RDF/@xml:lang" => "de",
224
239
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
225
- "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="en-us">foo</dc:title>)
240
+ "/rdf:RDF/rdf:Description/@dc:title" => "foo"
226
241
  )
227
242
  end
228
- end
229
-
230
- it "should output untyped as attribute if lang is default" do
231
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
232
- check_xpaths(
233
- serialize(:attributes => :untyped, :lang => "de"),
234
- "/rdf:RDF/@xml:lang" => "de",
235
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
236
- "/rdf:RDF/rdf:Description/@dc:title" => "foo"
237
- )
238
- end
239
243
 
240
- it "should output untyped as property if lang set and no default" do
241
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
242
- check_xpaths(
243
- serialize(:attributes => :untyped),
244
- "/rdf:RDF/@xml:lang" => false,
245
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
246
- "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
247
- )
248
- end
249
-
250
- it "should output untyped as property if lang set and not default" do
251
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
252
- check_xpaths(
253
- serialize(:attributes => :untyped, :lang => "en-us"),
254
- "/rdf:RDF/@xml:lang" => "en-us",
255
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
256
- "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
257
- )
258
- end
244
+ it "should output untyped as property if lang set and no default" do
245
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
246
+ check_xpaths(
247
+ serialize(:attributes => :untyped),
248
+ "/rdf:RDF/@xml:lang" => false,
249
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
250
+ "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
251
+ )
252
+ end
259
253
 
260
- it "should output multiple untyped attributes values through properties" do
261
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
262
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
263
- check_xpaths(
264
- serialize(:attributes => :untyped, :lang => "en-us"),
265
- "/rdf:RDF/@xml:lang" => "en-us",
266
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
267
- "/rdf:RDF/rdf:Description/dc:title[lang('de')]" => %(<dc:title xml:lang="de">foo</dc:title>),
268
- "/rdf:RDF/rdf:Description/dc:title[lang('en-us')]" => %(<dc:title>foo</dc:title>)
269
- )
270
- end
254
+ it "should output untyped as property if lang set and not default" do
255
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
256
+ check_xpaths(
257
+ serialize(:attributes => :untyped, :lang => "en-us"),
258
+ "/rdf:RDF/@xml:lang" => "en-us",
259
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
260
+ "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
261
+ )
262
+ end
271
263
 
272
- it "should output typed node as attribute" do
273
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
274
- check_xpaths(
275
- serialize(:attributes => :untyped),
276
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
277
- "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>)
278
- )
279
- check_xpaths(
280
- serialize(:attributes => :typed),
281
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
282
- "/rdf:RDF/rdf:Description/@dc:title" => "foo"
283
- )
284
- end
264
+ it "should output multiple untyped attributes values through properties" do
265
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
266
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
267
+ check_xpaths(
268
+ serialize(:attributes => :untyped, :lang => "en-us"),
269
+ "/rdf:RDF/@xml:lang" => "en-us",
270
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
271
+ "/rdf:RDF/rdf:Description/dc:title[lang('de')]" => %(<dc:title xml:lang="de">foo</dc:title>),
272
+ "/rdf:RDF/rdf:Description/dc:title[lang('en-us')]" => %(<dc:title>foo</dc:title>)
273
+ )
274
+ end
285
275
 
286
- it "should output multiple typed values through properties" do
287
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
288
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("bar", :datatype => RDF::XSD.string)]
276
+ it "should output typed node as attribute" do
277
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
289
278
  check_xpaths(
290
279
  serialize(:attributes => :untyped),
291
280
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
292
- "/rdf:RDF/rdf:Description/dc:title[contains(., 'foo')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>),
293
- "/rdf:RDF/rdf:Description/dc:title[contains(., 'bar')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">bar</dc:title>)
281
+ "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>)
282
+ )
283
+ check_xpaths(
284
+ serialize(:attributes => :typed),
285
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
286
+ "/rdf:RDF/rdf:Description/@dc:title" => "foo"
294
287
  )
288
+ end
289
+
290
+ it "should output multiple typed values through properties" do
291
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
292
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("bar", :datatype => RDF::XSD.string)]
293
+ check_xpaths(
294
+ serialize(:attributes => :untyped),
295
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
296
+ "/rdf:RDF/rdf:Description/dc:title[contains(., 'foo')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>),
297
+ "/rdf:RDF/rdf:Description/dc:title[contains(., 'bar')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">bar</dc:title>)
298
+ )
299
+ end
295
300
  end
296
- end
297
301
 
298
- describe "with default namespace" do
299
- it "should serialize with default namespace" do
300
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
301
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
302
- @graph << [RDF::URI.new("http://release/"), FOO.pred, FOO.obj]
302
+ describe "with default namespace" do
303
+ it "should serialize with default namespace" do
304
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
305
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
306
+ @graph << [RDF::URI.new("http://release/"), FOO.pred, FOO.obj]
303
307
 
304
- xml = serialize(:max_depth => 1, :attributes => :untyped, :default_namespace => FOO.to_s)
305
- xml.should =~ /<Release/
306
- xml.should =~ /<pred/
307
- doc = Nokogiri::XML.parse(xml)
308
- doc.at_xpath("/rdf:RDF/foo:Release/foo:pred/@rdf:resource", doc.namespaces).to_s.should == FOO.obj.to_s
308
+ xml = serialize(:max_depth => 1, :attributes => :untyped,
309
+ :default_namespace => FOO.to_s,
310
+ :prefixes => {:foo => FOO.to_s})
311
+ xml.should =~ /<Release/
312
+ xml.should =~ /<pred/
313
+ doc = Nokogiri::XML.parse(xml)
314
+ doc.at_xpath("/rdf:RDF/foo:Release/foo:pred/@rdf:resource", doc.namespaces).to_s.should == FOO.obj.to_s
315
+ end
316
+
317
+ it "should serialize with nil namespace" do
318
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
319
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
320
+ @graph << [RDF::URI.new("http://release/"), FOO.pred, FOO.obj]
321
+
322
+ xml = serialize(:max_depth => 1, :attributes => :untyped,
323
+ :prefixes => {nil => FOO.to_s, :foo => FOO.to_s})
324
+ xml.should =~ /<Release/
325
+ xml.should =~ /<pred/
326
+ doc = Nokogiri::XML.parse(xml)
327
+ doc.at_xpath("/rdf:RDF/foo:Release/foo:pred/@rdf:resource", doc.namespaces).to_s.should == FOO.obj.to_s
328
+ end
309
329
  end
310
- end
311
330
 
312
- describe "with base" do
313
- it "should generate relative about URI" do
314
- @graph << [RDF::URI.new("http://release/a"), FOO.ref, RDF::URI.new("http://release/b")]
315
- check_xpaths(
316
- serialize(:attributes => :untyped, :base_uri => "http://release/"),
317
- "/rdf:RDF/rdf:Description/@rdf:about" => "a",
318
- "/rdf:RDF/rdf:Description/foo:ref/@rdf:resource" => "b"
319
- )
331
+ describe "with base" do
332
+ it "should generate relative about URI" do
333
+ @graph << [RDF::URI.new("http://release/a"), FOO.ref, RDF::URI.new("http://release/b")]
334
+ check_xpaths(
335
+ serialize(:attributes => :untyped, :base_uri => "http://release/"),
336
+ "/rdf:RDF/rdf:Description/@rdf:about" => "a",
337
+ "/rdf:RDF/rdf:Description/foo:ref/@rdf:resource" => "b"
338
+ )
339
+ end
320
340
  end
321
- end
322
341
 
323
- describe "with bnodes" do
324
- it "should not generate nodeID attribute unless node is referenced as an object" do
325
- @graph << [RDF::Node.new("a"), RDF::DC.title, "foo"]
326
- check_xpaths(
327
- serialize(:attributes => :untyped, :base => "http://release/"),
328
- "/rdf:RDF/rdf:Description/@dc:title" => "foo",
329
- "/rdf:RDF/rdf:Description/@rdf:nodeID" => false
330
- )
331
- end
342
+ describe "with bnodes" do
343
+ it "should not generate nodeID attribute unless node is referenced as an object" do
344
+ @graph << [RDF::Node.new("a"), RDF::DC.title, "foo"]
345
+ check_xpaths(
346
+ serialize(:attributes => :untyped, :base => "http://release/"),
347
+ "/rdf:RDF/rdf:Description/@dc:title" => "foo",
348
+ "/rdf:RDF/rdf:Description/@rdf:nodeID" => false
349
+ )
350
+ end
332
351
 
333
- it "should generate a nodeID attribute if node is referenced as an object" do
334
- bn = RDF::Node.new("a")
335
- @graph << [bn, RDF::DC.title, "foo"]
336
- @graph << [bn, RDF::OWL.equals, bn]
337
- check_xpaths(
338
- serialize(:attributes => :untyped, :base => "http://release/"),
339
- "/rdf:RDF/rdf:Description/@dc:title" => "foo",
340
- "/rdf:RDF/rdf:Description/@rdf:nodeID" => /a$/,
341
- "/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /a$/
342
- )
343
- end
352
+ it "should generate a nodeID attribute if node is referenced as an object" do
353
+ bn = RDF::Node.new("a")
354
+ @graph << [bn, RDF::DC.title, "foo"]
355
+ @graph << [bn, RDF::OWL.equals, bn]
356
+ check_xpaths(
357
+ serialize(:attributes => :untyped, :base => "http://release/"),
358
+ "/rdf:RDF/rdf:Description/@dc:title" => "foo",
359
+ "/rdf:RDF/rdf:Description/@rdf:nodeID" => /a$/,
360
+ "/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /a$/
361
+ )
362
+ end
344
363
 
345
- it "should replicate rdfcore/rdfms-seq-representation" do
346
- graph_expect = parse(%(
347
- <http://example.org/eg#eric> a [ <http://example.org/eg#intersectionOf> (<http://example.org/eg#Person> <http://example.org/eg#Male>)] .
348
- ), :reader => RDF::N3::Reader)
349
- graph_check = parse(serialize(:format => :xml)).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
364
+ it "should replicate rdfcore/rdfms-seq-representation" do
365
+ graph_expect = parse(%(
366
+ <http://example.org/eg#eric> a [ <http://example.org/eg#intersectionOf> (<http://example.org/eg#Person> <http://example.org/eg#Male>)] .
367
+ ), :reader => RDF::N3::Reader)
368
+ graph_check = parse(serialize(:format => :rdfxml)).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
369
+ end
350
370
  end
351
- end
352
371
 
353
- def check_xpaths(doc, paths)
354
- puts doc.to_s if $DEBUG || $verbose
355
- doc = Nokogiri::XML.parse(doc)
356
- doc.should be_a(Nokogiri::XML::Document)
357
- doc.root.should be_a(Nokogiri::XML::Element)
358
- paths.each_pair do |path, value|
359
- @debug << doc.root.at_xpath(path, @namespaces).to_s if $DEBUG
360
- case value
361
- when false
362
- doc.root.at_xpath(path, doc.namespaces).should be_nil
363
- when true
364
- doc.root.at_xpath(path, doc.namespaces).should_not be_nil
365
- when Array
366
- doc.root.at_xpath(path, doc.namespaces).to_s.split(" ").should include(*value)
367
- when Regexp
368
- doc.root.at_xpath(path, doc.namespaces).to_s.should =~ value
369
- else
370
- doc.root.at_xpath(path, doc.namespaces).to_s.should == value
372
+ describe "w3c rdfcore tests" do
373
+ require 'rdf_helper'
374
+
375
+ def self.positive_tests
376
+ RdfHelper::TestCase.positive_parser_tests(RDFCORE_TEST, RDFCORE_DIR)
377
+ end
378
+
379
+ positive_tests.each do |t|
380
+ #next unless t.about =~ /rdfms-not-id-and-resource-attr\/test001/
381
+ next if t.about =~ /rdfms-xml-literal-namespaces|xml-canon/ # Literal serialization adds namespace definitions
382
+ #next unless t.name =~ /11/
383
+ #puts t.inspect
384
+ specify "#{t.name}: " + (t.description || "#{t.outputDocument}") do
385
+ @graph = parse(t.output, :base_uri => t.about, :format => :ntriples)
386
+ parse(serialize(:format => :rdfxml, :base_uri => t.about), :base_uri => t.about).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
387
+ end
371
388
  end
372
389
  end
390
+
391
+ def check_xpaths(doc, paths)
392
+ puts doc.to_s if ::RDF::RDFXML::debug? || $verbose
393
+ doc = Nokogiri::XML.parse(doc)
394
+ doc.should be_a(Nokogiri::XML::Document)
395
+ doc.root.should be_a(Nokogiri::XML::Element)
396
+ paths.each_pair do |path, value|
397
+ @debug << doc.root.at_xpath(path, doc.namespaces).to_s if ::RDF::RDFXML::debug?
398
+ case value
399
+ when false
400
+ doc.root.at_xpath(path, doc.namespaces).should be_nil
401
+ when true
402
+ doc.root.at_xpath(path, doc.namespaces).should_not be_nil
403
+ when Array
404
+ doc.root.at_xpath(path, doc.namespaces).to_s.split(" ").should include(*value)
405
+ when Regexp
406
+ doc.root.at_xpath(path, doc.namespaces).to_s.should =~ value
407
+ else
408
+ doc.root.at_xpath(path, doc.namespaces).to_s.should == value
409
+ end
410
+ end
373
411
 
374
- # Parse generated graph and compare to source
375
- #graph = RDF::Graph.new
376
- #RDF::RDFXML::Reader.new(doc, :base_uri => "http://release/", :format => :rdf).each {|st| graph << st}
377
- #graph.should be_equivalent_graph(@graph, :about => "http://release/", :trace => @debug.join("\n"))
378
- end
412
+ # Parse generated graph and compare to source
413
+ #graph = RDF::Graph.new
414
+ #RDF::RDFXML::Reader.new(doc, :base_uri => "http://release/", :format => :rdfxml).each {|st| graph << st}
415
+ #graph.should be_equivalent_graph(@graph, :about => "http://release/", :trace => @debug.join("\n"))
416
+ end
379
417
 
380
- require 'rdf/n3'
381
- def parse(input, options = {})
382
- reader_class = options.fetch(:reader, detect_format(input))
418
+ require 'rdf/n3'
419
+ def parse(input, options = {})
420
+ reader_class = options.fetch(:reader, detect_format(input))
383
421
 
384
- graph = RDF::Graph.new
385
- reader_class.new(input, options).each do |statement|
386
- graph << statement
422
+ graph = RDF::Graph.new
423
+ reader_class.new(input, options).each do |statement|
424
+ graph << statement
425
+ end
426
+ graph
387
427
  end
388
- graph
389
- end
390
428
 
391
- # Serialize ntstr to a string and compare against regexps
392
- def serialize(options = {})
393
- @debug = []
394
- result = @writer.buffer(options.merge(:debug => @debug)) do |writer|
395
- writer << @graph
429
+ # Serialize @graph to a string and compare against regexps
430
+ def serialize(options = {})
431
+ @debug = []
432
+ result = @writer.buffer({:debug => @debug, :standard_prefixes => true}.merge(options)) do |writer|
433
+ writer << @graph
434
+ end
435
+ require 'cgi'
436
+ puts CGI.escapeHTML(result) if $verbose
437
+ result
438
+ end
439
+ end
440
+
441
+ describe "#get_qname" do
442
+ subject { RDF::RDFXML::Writer.new }
443
+ describe "with undefined predicate URIs" do
444
+ {
445
+ "http://a/b" => [:ns0, :b],
446
+ "dc:title" => [:ns0, :title]
447
+ }.each_pair do |uri, qname|
448
+ it "returns #{qname.inspect} given #{uri}" do
449
+ subject.get_qname(uri).should == qname
450
+ end
451
+ end
396
452
  end
397
- require 'cgi'
398
- puts CGI.escapeHTML(result) if $verbose
399
- result
400
453
  end
401
454
  end