|
181 | 181 | ], @debug) |
182 | 182 | end |
183 | 183 | end |
184 | | - |
| 184 | + |
185 | 185 | context "lists" do |
186 | | - it "should generate literal list" do |
187 | | - input = %( |
188 | | - @prefix : <http://example.com/> . |
189 | | - @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
190 | | - :a :b ("apple" "banana") . |
191 | | - ) |
192 | | - expect(serialize(input)).to produce([{ |
193 | | - '@id' => "http://example.com/a", |
194 | | - "http://example.com/b" => [{ |
195 | | - "@list" => [ |
196 | | - {"@value" => "apple"}, |
197 | | - {"@value" => "banana"} |
198 | | - ] |
| 186 | + { |
| 187 | + "literal list" => [ |
| 188 | + %q( |
| 189 | + @prefix : <http://example.com/> . |
| 190 | + @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
| 191 | + :a :b ("apple" "banana") . |
| 192 | + ), |
| 193 | + [{ |
| 194 | + '@id' => "http://example.com/a", |
| 195 | + "http://example.com/b" => [{ |
| 196 | + "@list" => [ |
| 197 | + {"@value" => "apple"}, |
| 198 | + {"@value" => "banana"} |
| 199 | + ] |
| 200 | + }] |
199 | 201 | }] |
200 | | - }], @debug) |
201 | | - end |
202 | | - |
203 | | - it "should generate iri list" do |
204 | | - input = %(@prefix : <http://example.com/> . :a :b (:c) .) |
205 | | - expect(serialize(input)).to produce([{ |
206 | | - '@id' => "http://example.com/a", |
207 | | - "http://example.com/b" => [{ |
208 | | - "@list" => [ |
209 | | - {"@id" => "http://example.com/c"} |
210 | | - ] |
| 202 | + ], |
| 203 | + "iri list" => [ |
| 204 | + %q(@prefix : <http://example.com/> . :a :b (:c) .), |
| 205 | + [{ |
| 206 | + '@id' => "http://example.com/a", |
| 207 | + "http://example.com/b" => [{ |
| 208 | + "@list" => [ |
| 209 | + {"@id" => "http://example.com/c"} |
| 210 | + ] |
| 211 | + }] |
211 | 212 | }] |
212 | | - }], @debug) |
213 | | - end |
214 | | - |
215 | | - it "should generate empty list" do |
216 | | - input = %(@prefix : <http://example.com/> . :a :b () .) |
217 | | - expect(serialize(input)).to produce([{ |
218 | | - '@id' => "http://example.com/a", |
219 | | - "http://example.com/b" => [{"@list" => []}] |
220 | | - }], @debug) |
221 | | - end |
222 | | - |
223 | | - it "should generate single element list" do |
224 | | - input = %(@prefix : <http://example.com/> . :a :b ( "apple" ) .) |
225 | | - expect(serialize(input)).to produce([{ |
226 | | - '@id' => "http://example.com/a", |
227 | | - "http://example.com/b" => [{"@list" => [{"@value" => "apple"}]}] |
228 | | - }], @debug) |
229 | | - end |
230 | | - |
231 | | - it "should generate single element list without @type" do |
232 | | - input = %( |
233 | | - @prefix : <http://example.com/> . :a :b ( _:a ) . _:a :b "foo" .) |
234 | | - expect(serialize(input)).to produce([ |
235 | | - { |
236 | | - '@id' => "_:a", |
237 | | - "http://example.com/b" => [{"@value" => "foo"}] |
238 | | - }, |
239 | | - { |
| 213 | + ], |
| 214 | + "empty list" => [ |
| 215 | + %q(@prefix : <http://example.com/> . :a :b () .), |
| 216 | + [{ |
240 | 217 | '@id' => "http://example.com/a", |
241 | | - "http://example.com/b" => [{"@list" => [{"@id" => "_:a"}]}] |
| 218 | + "http://example.com/b" => [{"@list" => []}] |
| 219 | + }] |
| 220 | + ], |
| 221 | + "single element list" => [ |
| 222 | + %q(@prefix : <http://example.com/> . :a :b ( "apple" ) .), |
| 223 | + [{ |
| 224 | + '@id' => "http://example.com/a", |
| 225 | + "http://example.com/b" => [{"@list" => [{"@value" => "apple"}]}] |
| 226 | + }] |
| 227 | + ], |
| 228 | + "single element list without @type" => [ |
| 229 | + %q(@prefix : <http://example.com/> . :a :b ( _:a ) . _:a :b "foo" .), |
| 230 | + [ |
| 231 | + { |
| 232 | + '@id' => "_:a", |
| 233 | + "http://example.com/b" => [{"@value" => "foo"}] |
| 234 | + }, |
| 235 | + { |
| 236 | + '@id' => "http://example.com/a", |
| 237 | + "http://example.com/b" => [{"@list" => [{"@id" => "_:a"}]}] |
| 238 | + }, |
| 239 | + ] |
| 240 | + ], |
| 241 | + "multiple graphs with shared BNode" => [ |
| 242 | + %q( |
| 243 | + <http://www.example.com/z> <http://www.example.com/q> _:z0 <http://www.example.com/G> . |
| 244 | + _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "cell-A" <http://www.example.com/G> . |
| 245 | + _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:z1 <http://www.example.com/G> . |
| 246 | + _:z1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "cell-B" <http://www.example.com/G> . |
| 247 | + _:z1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://www.example.com/G> . |
| 248 | + <http://www.example.com/x> <http://www.example.com/p> _:z1 <http://www.example.com/G1> . |
| 249 | + ), |
| 250 | + [{ |
| 251 | + "@id" => "http://www.example.com/G", |
| 252 | + "@graph" => [{ |
| 253 | + "@id" => "_:z0", |
| 254 | + "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" => [{"@value" => "cell-A"}], |
| 255 | + "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest" => [{"@id" => "_:z1"}] |
| 256 | + }, { |
| 257 | + "@id" => "_:z1", |
| 258 | + "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" => [{"@value" => "cell-B"}], |
| 259 | + "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest" => [{"@list" => []}] |
| 260 | + }, { |
| 261 | + "@id" => "http://www.example.com/z", |
| 262 | + "http://www.example.com/q" => [{"@id" => "_:z0"}] |
| 263 | + }] |
242 | 264 | }, |
243 | | - ], @debug) |
| 265 | + { |
| 266 | + "@id" => "http://www.example.com/G1", |
| 267 | + "@graph" => [{ |
| 268 | + "@id" => "http://www.example.com/x", |
| 269 | + "http://www.example.com/p" => [{"@id" => "_:z1"}] |
| 270 | + }] |
| 271 | + }], |
| 272 | + RDF::NQuads::Reader |
| 273 | + ], |
| 274 | + }.each do |name, (input, output, reader)| |
| 275 | + it name do |
| 276 | + r = serialize(input, :reader => reader) |
| 277 | + expect(r).to produce(output, @debug) |
| 278 | + end |
244 | 279 | end |
245 | 280 | end |
246 | 281 |
|
|
363 | 398 | end |
364 | 399 |
|
365 | 400 | def parse(input, options = {}) |
366 | | - reader = options[:reader] || RDF::Turtle::Reader |
| 401 | + reader = options[:reader] || RDF::TriG::Reader |
367 | 402 | RDF::Repository.new << reader.new(input, options) |
368 | 403 | end |
369 | 404 |
|
|
0 commit comments