json-ld 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/History.markdown +3 -0
  2. data/VERSION +1 -1
  3. data/bin/jsonld +134 -0
  4. data/lib/json/ld/api.rb +4 -4
  5. data/lib/json/ld/frame.rb +2 -1
  6. data/lib/json/ld/from_rdf.rb +1 -1
  7. data/spec/api_spec.rb +66 -0
  8. data/spec/compact_spec.rb +420 -0
  9. data/spec/evaluation_context_spec.rb +1039 -0
  10. data/spec/expand_spec.rb +625 -0
  11. data/spec/format_spec.rb +71 -0
  12. data/spec/frame_spec.rb +542 -0
  13. data/spec/from_rdf_spec.rb +316 -0
  14. data/spec/matchers.rb +67 -0
  15. data/spec/reader_spec.rb +79 -0
  16. data/spec/spec_helper.rb +56 -0
  17. data/spec/suite_helper.rb +184 -0
  18. data/spec/suite_spec.rb +104 -0
  19. data/spec/support/extensions.rb +10 -0
  20. data/spec/test-files/test-1-automatic.json +10 -0
  21. data/spec/test-files/test-1-compacted.json +10 -0
  22. data/spec/test-files/test-1-context.json +7 -0
  23. data/spec/test-files/test-1-expanded.json +5 -0
  24. data/spec/test-files/test-1-input.json +10 -0
  25. data/spec/test-files/test-1-normalized.json +8 -0
  26. data/spec/test-files/test-1-rdf.ttl +7 -0
  27. data/spec/test-files/test-2-automatic.json +27 -0
  28. data/spec/test-files/test-2-compacted.json +20 -0
  29. data/spec/test-files/test-2-context.json +7 -0
  30. data/spec/test-files/test-2-expanded.json +16 -0
  31. data/spec/test-files/test-2-input.json +20 -0
  32. data/spec/test-files/test-2-normalized.json +32 -0
  33. data/spec/test-files/test-2-rdf.ttl +14 -0
  34. data/spec/test-files/test-3-compacted.json +11 -0
  35. data/spec/test-files/test-3-context.json +8 -0
  36. data/spec/test-files/test-3-expanded.json +10 -0
  37. data/spec/test-files/test-3-input.json +11 -0
  38. data/spec/test-files/test-3-normalized.json +13 -0
  39. data/spec/test-files/test-3-rdf.ttl +7 -0
  40. data/spec/test-files/test-4-automatic.json +10 -0
  41. data/spec/test-files/test-4-compacted.json +10 -0
  42. data/spec/test-files/test-4-context.json +7 -0
  43. data/spec/test-files/test-4-expanded.json +6 -0
  44. data/spec/test-files/test-4-input.json +10 -0
  45. data/spec/test-files/test-4-rdf.ttl +5 -0
  46. data/spec/test-files/test-5-automatic.json +13 -0
  47. data/spec/test-files/test-5-compacted.json +13 -0
  48. data/spec/test-files/test-5-context.json +7 -0
  49. data/spec/test-files/test-5-expanded.json +9 -0
  50. data/spec/test-files/test-5-input.json +13 -0
  51. data/spec/test-files/test-5-rdf.ttl +6 -0
  52. data/spec/test-files/test-6-automatic.json +10 -0
  53. data/spec/test-files/test-6-compacted.json +10 -0
  54. data/spec/test-files/test-6-context.json +7 -0
  55. data/spec/test-files/test-6-expanded.json +10 -0
  56. data/spec/test-files/test-6-input.json +10 -0
  57. data/spec/test-files/test-6-rdf.ttl +5 -0
  58. data/spec/test-files/test-7-automatic.json +20 -0
  59. data/spec/test-files/test-7-compacted.json +23 -0
  60. data/spec/test-files/test-7-context.json +4 -0
  61. data/spec/test-files/test-7-expanded.json +20 -0
  62. data/spec/test-files/test-7-input.json +23 -0
  63. data/spec/test-files/test-7-rdf.ttl +13 -0
  64. data/spec/test-files/test-8-automatic.json +1 -0
  65. data/spec/test-files/test-8-compacted.json +34 -0
  66. data/spec/test-files/test-8-context.json +11 -0
  67. data/spec/test-files/test-8-expanded.json +24 -0
  68. data/spec/test-files/test-8-frame.json +18 -0
  69. data/spec/test-files/test-8-framed.json +29 -0
  70. data/spec/test-files/test-8-input.json +30 -0
  71. data/spec/test-files/test-8-rdf.ttl +15 -0
  72. data/spec/test-files/test-9-compacted.json +20 -0
  73. data/spec/test-files/test-9-context.json +13 -0
  74. data/spec/test-files/test-9-expanded.json +14 -0
  75. data/spec/test-files/test-9-input.json +12 -0
  76. data/spec/to_rdf_spec.rb +640 -0
  77. data/spec/writer_spec.rb +161 -0
  78. metadata +150 -22
@@ -0,0 +1,625 @@
1
+ # coding: utf-8
2
+ $:.unshift "."
3
+ require 'spec_helper'
4
+
5
+ describe JSON::LD::API do
6
+ before(:each) { @debug = []}
7
+
8
+ describe ".expand" do
9
+ {
10
+ "empty doc" => {
11
+ :input => {},
12
+ :output => [{}]
13
+ },
14
+ "coerced IRI" => {
15
+ :input => {
16
+ "@context" => {
17
+ "a" => {"@id" => "http://example.com/a"},
18
+ "b" => {"@id" => "http://example.com/b", "@type" => "@id"},
19
+ "c" => {"@id" => "http://example.com/c"},
20
+ },
21
+ "@id" => "a",
22
+ "b" => "c"
23
+ },
24
+ :output => [{
25
+ "@id" => "http://example.com/a",
26
+ "http://example.com/b" => [{"@id" =>"http://example.com/c"}]
27
+ }]
28
+ },
29
+ "coerced IRI in array" => {
30
+ :input => {
31
+ "@context" => {
32
+ "a" => {"@id" => "http://example.com/a"},
33
+ "b" => {"@id" => "http://example.com/b", "@type" => "@id"},
34
+ "c" => {"@id" => "http://example.com/c"},
35
+ },
36
+ "@id" => "a",
37
+ "b" => ["c"]
38
+ },
39
+ :output => [{
40
+ "@id" => "http://example.com/a",
41
+ "http://example.com/b" => [{"@id" => "http://example.com/c"}]
42
+ }]
43
+ },
44
+ "empty term" => {
45
+ :input => {
46
+ "@context" => {"" => "http://example.com/"},
47
+ "@id" => "",
48
+ "@type" => "#{RDF::RDFS.Resource}"
49
+ },
50
+ :output => [{
51
+ "@id" => "http://example.com/",
52
+ "@type" => ["#{RDF::RDFS.Resource}"]
53
+ }]
54
+ },
55
+ "@list coercion" => {
56
+ :input => {
57
+ "@context" => {
58
+ "foo" => {"@id" => "http://example.com/foo", "@container" => "@list"}
59
+ },
60
+ "foo" => [{"@value" => "bar"}]
61
+ },
62
+ :output => [{
63
+ "http://example.com/foo" => [{"@list" => [{"@value" => "bar"}]}]
64
+ }]
65
+ },
66
+ "native values in list" => {
67
+ :input => {
68
+ "http://example.com/foo" => {"@list" => [1, 2]}
69
+ },
70
+ :output => [{
71
+ "http://example.com/foo" => [{"@list" => [{"@value" => 1}, {"@value" => 2}]}]
72
+ }]
73
+ },
74
+ "@graph" => {
75
+ :input => {
76
+ "@context" => {"ex" => "http://example.com/"},
77
+ "@graph" => [
78
+ {"ex:foo" => {"@value" => "foo"}},
79
+ {"ex:bar" => {"@value" => "bar"}}
80
+ ]
81
+ },
82
+ :output => [
83
+ {"http://example.com/foo" => [{"@value" => "foo"}]},
84
+ {"http://example.com/bar" => [{"@value" => "bar"}]}
85
+ ]
86
+ },
87
+ "@type with empty object" => {
88
+ :input => {
89
+ "@type" => {}
90
+ },
91
+ :output => [
92
+ {"@type" => [{}]}
93
+ ]
94
+ },
95
+ "@type with CURIE" => {
96
+ :input => {
97
+ "@context" => {"ex" => "http://example.com/"},
98
+ "@type" => "ex:type"
99
+ },
100
+ :output => [
101
+ {"@type" => ["http://example.com/type"]}
102
+ ]
103
+ },
104
+ "@type with CURIE and muliple values" => {
105
+ :input => {
106
+ "@context" => {"ex" => "http://example.com/"},
107
+ "@type" => ["ex:type1", "ex:type2"]
108
+ },
109
+ :output => [
110
+ {"@type" => ["http://example.com/type1", "http://example.com/type2"]}
111
+ ]
112
+ },
113
+ }.each_pair do |title, params|
114
+ it title do
115
+ jld = JSON::LD::API.expand(params[:input], nil, nil, :debug => @debug)
116
+ jld.should produce(params[:output], @debug)
117
+ end
118
+ end
119
+
120
+ context "with relative IRIs" do
121
+ {
122
+ "base" => {
123
+ :input => {
124
+ "@id" => "",
125
+ "@type" => "#{RDF::RDFS.Resource}"
126
+ },
127
+ :output => [{
128
+ "@id" => "http://example.org/",
129
+ "@type" => ["#{RDF::RDFS.Resource}"]
130
+ }]
131
+ },
132
+ "relative" => {
133
+ :input => {
134
+ "@id" => "a/b",
135
+ "@type" => "#{RDF::RDFS.Resource}"
136
+ },
137
+ :output => [{
138
+ "@id" => "http://example.org/a/b",
139
+ "@type" => ["#{RDF::RDFS.Resource}"]
140
+ }]
141
+ },
142
+ "hash" => {
143
+ :input => {
144
+ "@id" => "#a",
145
+ "@type" => "#{RDF::RDFS.Resource}"
146
+ },
147
+ :output => [{
148
+ "@id" => "http://example.org/#a",
149
+ "@type" => ["#{RDF::RDFS.Resource}"]
150
+ }]
151
+ },
152
+ "unmapped @id" => {
153
+ :input => {
154
+ "http://example.com/foo" => {"@id" => "bar"}
155
+ },
156
+ :output => [{
157
+ "http://example.com/foo" => [{"@id" => "http://example.org/bar"}]
158
+ }]
159
+ },
160
+ }.each do |title, params|
161
+ it title do
162
+ jld = JSON::LD::API.expand(params[:input], nil, nil, :base => "http://example.org/", :debug => @debug)
163
+ jld.should produce(params[:output], @debug)
164
+ end
165
+ end
166
+ end
167
+
168
+ context "keyword aliasing" do
169
+ {
170
+ "@id" => {
171
+ :input => {
172
+ "@context" => {"id" => "@id"},
173
+ "id" => "",
174
+ "@type" => "#{RDF::RDFS.Resource}"
175
+ },
176
+ :output => [{
177
+ "@id" => "",
178
+ "@type" =>[ "#{RDF::RDFS.Resource}"]
179
+ }]
180
+ },
181
+ "@type" => {
182
+ :input => {
183
+ "@context" => {"type" => "@type"},
184
+ "type" => RDF::RDFS.Resource.to_s,
185
+ "http://example.com/foo" => {"@value" => "bar", "type" => "http://example.com/baz"}
186
+ },
187
+ :output => [{
188
+ "@type" => [RDF::RDFS.Resource.to_s],
189
+ "http://example.com/foo" => [{"@value" => "bar", "@type" => "http://example.com/baz"}]
190
+ }]
191
+ },
192
+ "@language" => {
193
+ :input => {
194
+ "@context" => {"language" => "@language"},
195
+ "http://example.com/foo" => {"@value" => "bar", "language" => "baz"}
196
+ },
197
+ :output => [{
198
+ "http://example.com/foo" => [{"@value" => "bar", "@language" => "baz"}]
199
+ }]
200
+ },
201
+ "@value" => {
202
+ :input => {
203
+ "@context" => {"literal" => "@value"},
204
+ "http://example.com/foo" => {"literal" => "bar"}
205
+ },
206
+ :output => [{
207
+ "http://example.com/foo" => [{"@value" => "bar"}]
208
+ }]
209
+ },
210
+ "@list" => {
211
+ :input => {
212
+ "@context" => {"list" => "@list"},
213
+ "http://example.com/foo" => {"list" => ["bar"]}
214
+ },
215
+ :output => [{
216
+ "http://example.com/foo" => [{"@list" => [{"@value" => "bar"}]}]
217
+ }]
218
+ },
219
+ }.each do |title, params|
220
+ it title do
221
+ jld = JSON::LD::API.expand(params[:input], nil, nil, :debug => @debug)
222
+ jld.should produce(params[:output], @debug)
223
+ end
224
+ end
225
+ end
226
+
227
+ context "native types" do
228
+ {
229
+ "true" => {
230
+ :input => {
231
+ "@context" => {"e" => "http://example.org/vocab#"},
232
+ "e:bool" => true
233
+ },
234
+ :output => [{
235
+ "http://example.org/vocab#bool" => [{"@value" => true}]
236
+ }]
237
+ },
238
+ "false" => {
239
+ :input => {
240
+ "@context" => {"e" => "http://example.org/vocab#"},
241
+ "e:bool" => false
242
+ },
243
+ :output => [{
244
+ "http://example.org/vocab#bool" => [{"@value" => false}]
245
+ }]
246
+ },
247
+ "double" => {
248
+ :input => {
249
+ "@context" => {"e" => "http://example.org/vocab#"},
250
+ "e:double" => 1.23
251
+ },
252
+ :output => [{
253
+ "http://example.org/vocab#double" => [{"@value" => 1.23}]
254
+ }]
255
+ },
256
+ "double-zero" => {
257
+ :input => {
258
+ "@context" => {"e" => "http://example.org/vocab#"},
259
+ "e:double-zero" => 0.0e0
260
+ },
261
+ :output => [{
262
+ "http://example.org/vocab#double-zero" => [{"@value" => 0.0e0}]
263
+ }]
264
+ },
265
+ "integer" => {
266
+ :input => {
267
+ "@context" => {"e" => "http://example.org/vocab#"},
268
+ "e:integer" => 123
269
+ },
270
+ :output => [{
271
+ "http://example.org/vocab#integer" => [{"@value" => 123}]
272
+ }]
273
+ },
274
+ }.each do |title, params|
275
+ it title do
276
+ jld = JSON::LD::API.expand(params[:input], nil, nil, :debug => @debug)
277
+ jld.should produce(params[:output], @debug)
278
+ end
279
+ end
280
+ end
281
+
282
+ context "coerced typed values" do
283
+ {
284
+ "boolean" => {
285
+ :input => {
286
+ "@context" => {"foo" => {"@id" => "http://example.org/foo", "@type" => RDF::XSD.boolean.to_s}},
287
+ "foo" => "true"
288
+ },
289
+ :output => [{
290
+ "http://example.org/foo" => [{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}]
291
+ }]
292
+ },
293
+ "date" => {
294
+ :input => {
295
+ "@context" => {"foo" => {"@id" => "http://example.org/foo", "@type" => RDF::XSD.date.to_s}},
296
+ "foo" => "2011-03-26"
297
+ },
298
+ :output => [{
299
+ "http://example.org/foo" => [{"@value" => "2011-03-26", "@type" => RDF::XSD.date.to_s}]
300
+ }]
301
+ },
302
+ }.each do |title, params|
303
+ it title do
304
+ jld = JSON::LD::API.expand(params[:input], nil, nil, :debug => @debug)
305
+ jld.should produce(params[:output], @debug)
306
+ end
307
+ end
308
+ end
309
+
310
+ context "null" do
311
+ {
312
+ "value" => {
313
+ :input => {
314
+ "http://example.com/foo" => nil
315
+ },
316
+ :output => [{
317
+ }]
318
+ },
319
+ "@value" => {
320
+ :input => {
321
+ "http://example.com/foo" => {"@value" => nil}
322
+ },
323
+ :output => [{
324
+ }]
325
+ },
326
+ "@value and non-null @type" => {
327
+ :input => {
328
+ "http://example.com/foo" => {"@value" => nil, "@type" => "http://type"}
329
+ },
330
+ :output => [{
331
+ }]
332
+ },
333
+ "@value and non-null @language" => {
334
+ :input => {
335
+ "http://example.com/foo" => {"@value" => nil, "@language" => "en"}
336
+ },
337
+ :output => [{
338
+ }]
339
+ },
340
+ "non-null @value and null @type" => {
341
+ :input => {
342
+ "http://example.com/foo" => {"@value" => "foo", "@type" => nil}
343
+ },
344
+ :output => [{
345
+ "http://example.com/foo" => [{"@value" => "foo"}]
346
+ }]
347
+ },
348
+ "non-null @value and null @language" => {
349
+ :input => {
350
+ "http://example.com/foo" => {"@value" => "foo", "@language" => nil}
351
+ },
352
+ :output => [{
353
+ "http://example.com/foo" => [{"@value" => "foo"}]
354
+ }]
355
+ },
356
+ "array with null elements" => {
357
+ :input => {
358
+ "http://example.com/foo" => [nil]
359
+ },
360
+ :output => [{
361
+ "http://example.com/foo" => []
362
+ }]
363
+ },
364
+ "@set with null @value" => {
365
+ :input => {
366
+ "http://example.com/foo" => [
367
+ {"@value" => nil, "@type" => "http://example.org/Type"}
368
+ ]
369
+ },
370
+ :output => [{
371
+ "http://example.com/foo" => []
372
+ }]
373
+ }
374
+ }.each do |title, params|
375
+ it title do
376
+ jld = JSON::LD::API.expand(params[:input], nil, nil, :debug => @debug)
377
+ jld.should produce(params[:output], @debug)
378
+ end
379
+ end
380
+ end
381
+
382
+ context "default language" do
383
+ {
384
+ "value with null language" => {
385
+ :input => {
386
+ "@context" => {"@language" => "en"},
387
+ "http://example.org/nolang" => {"@value" => "no language", "@language" => nil}
388
+ },
389
+ :output => [{
390
+ "http://example.org/nolang" => [{"@value" => "no language"}]
391
+ }]
392
+ },
393
+ "value with coerced null language" => {
394
+ :input => {
395
+ "@context" => {
396
+ "@language" => "en",
397
+ "ex" => "http://example.org/vocab#",
398
+ "ex:german" => { "@language" => "de" },
399
+ "ex:nolang" => { "@language" => nil }
400
+ },
401
+ "ex:german" => "german",
402
+ "ex:nolang" => "no language"
403
+ },
404
+ :output => [
405
+ {
406
+ "http://example.org/vocab#german" => [{"@value" => "german", "@language" => "de"}],
407
+ "http://example.org/vocab#nolang" => [{"@value" => "no language"}]
408
+ }
409
+ ]
410
+ },
411
+ }.each do |title, params|
412
+ it title do
413
+ jld = JSON::LD::API.expand(params[:input], nil, nil, :debug => @debug)
414
+ jld.should produce(params[:output], @debug)
415
+ end
416
+ end
417
+ end
418
+
419
+ context "unmapped properties" do
420
+ {
421
+ "unmapped key" => {
422
+ :input => {
423
+ "foo" => "bar"
424
+ },
425
+ :output => [{
426
+ }]
427
+ },
428
+ "unmapped @type as datatype" => {
429
+ :input => {
430
+ "http://example.com/foo" => {"@value" => "bar", "@type" => "baz"}
431
+ },
432
+ :output => [{
433
+ "http://example.com/foo" => [{"@value" => "bar"}]
434
+ }]
435
+ },
436
+ "unknown keyword" => {
437
+ :input => {
438
+ "@foo" => "bar"
439
+ },
440
+ :output => [{
441
+ "@foo" => [{"@value" => "bar"}]
442
+ }]
443
+ },
444
+ "value" => {
445
+ :input => {
446
+ "@context" => {"ex" => {"@id" => "http://example.org/idrange", "@type" => "@id"}},
447
+ "@id" => "http://example.org/Subj",
448
+ "idrange" => "unmapped"
449
+ },
450
+ :output => [{
451
+ "@id" => "http://example.org/Subj",
452
+ }]
453
+ },
454
+ "context reset" => {
455
+ :input => {
456
+ "@context" => {"ex" => "http://example.org/", "prop" => "ex:prop"},
457
+ "@id" => "http://example.org/id1",
458
+ "prop" => "prop",
459
+ "ex:chain" => {
460
+ "@context" => nil,
461
+ "@id" => "http://example.org/id2",
462
+ "prop" => "prop"
463
+ }
464
+ },
465
+ :output => [{
466
+ "@id" => "http://example.org/id1",
467
+ "http://example.org/prop" => [{"@value" => "prop"}],
468
+ "http://example.org/chain" => [{"@id" => "http://example.org/id2"}]
469
+ }
470
+ ]}
471
+ }.each do |title, params|
472
+ it title do
473
+ jld = JSON::LD::API.expand(params[:input], nil, nil, :debug => @debug)
474
+ jld.should produce(params[:output], @debug)
475
+ end
476
+ end
477
+ end
478
+
479
+ context "lists" do
480
+ {
481
+ "empty" => {
482
+ :input => {
483
+ "http://example.com/foo" => {"@list" => []}
484
+ },
485
+ :output => [{
486
+ "http://example.com/foo" => [{"@list" => []}]
487
+ }]
488
+ },
489
+ "coerced empty" => {
490
+ :input => {
491
+ "@context" => {"http://example.com/foo" => {"@container" => "@list"}},
492
+ "http://example.com/foo" => []
493
+ },
494
+ :output => [{
495
+ "http://example.com/foo" => [{"@list" => []}]
496
+ }]
497
+ },
498
+ "coerced single element" => {
499
+ :input => {
500
+ "@context" => {"http://example.com/foo" => {"@container" => "@list"}},
501
+ "http://example.com/foo" => [ "foo" ]
502
+ },
503
+ :output => [{
504
+ "http://example.com/foo" => [{"@list" => [{"@value" => "foo"}]}]
505
+ }]
506
+ },
507
+ "coerced multiple elements" => {
508
+ :input => {
509
+ "@context" => {"http://example.com/foo" => {"@container" => "@list"}},
510
+ "http://example.com/foo" => [ "foo", "bar" ]
511
+ },
512
+ :output => [{
513
+ "http://example.com/foo" => [{"@list" => [ {"@value" => "foo"}, {"@value" => "bar"} ]}]
514
+ }]
515
+ },
516
+ "explicit list with coerced @id values" => {
517
+ :input => {
518
+ "@context" => {"http://example.com/foo" => {"@type" => "@id"}},
519
+ "http://example.com/foo" => {"@list" => ["http://foo", "http://bar"]}
520
+ },
521
+ :output => [{
522
+ "http://example.com/foo" => [{"@list" => [{"@id" => "http://foo"}, {"@id" => "http://bar"}]}]
523
+ }]
524
+ },
525
+ "explicit list with coerced datatype values" => {
526
+ :input => {
527
+ "@context" => {"http://example.com/foo" => {"@type" => RDF::XSD.date.to_s}},
528
+ "http://example.com/foo" => {"@list" => ["2012-04-12"]}
529
+ },
530
+ :output => [{
531
+ "http://example.com/foo" => [{"@list" => [{"@value" => "2012-04-12", "@type" => RDF::XSD.date.to_s}]}]
532
+ }]
533
+ },
534
+ }.each do |title, params|
535
+ it title do
536
+ jld = JSON::LD::API.expand(params[:input], nil, nil, :debug => @debug)
537
+ jld.should produce(params[:output], @debug)
538
+ end
539
+ end
540
+ end
541
+
542
+ context "sets" do
543
+ {
544
+ "empty" => {
545
+ :input => {
546
+ "http://example.com/foo" => {"@set" => []}
547
+ },
548
+ :output => [{
549
+ "http://example.com/foo" => []
550
+ }]
551
+ },
552
+ "coerced empty" => {
553
+ :input => {
554
+ "@context" => {"http://example.com/foo" => {"@container" => "@set"}},
555
+ "http://example.com/foo" => []
556
+ },
557
+ :output => [{
558
+ "http://example.com/foo" => []
559
+ }]
560
+ },
561
+ "coerced single element" => {
562
+ :input => {
563
+ "@context" => {"http://example.com/foo" => {"@container" => "@set"}},
564
+ "http://example.com/foo" => [ "foo" ]
565
+ },
566
+ :output => [{
567
+ "http://example.com/foo" => [ {"@value" => "foo"} ]
568
+ }]
569
+ },
570
+ "coerced multiple elements" => {
571
+ :input => {
572
+ "@context" => {"http://example.com/foo" => {"@container" => "@set"}},
573
+ "http://example.com/foo" => [ "foo", "bar" ]
574
+ },
575
+ :output => [{
576
+ "http://example.com/foo" => [ {"@value" => "foo"}, {"@value" => "bar"} ]
577
+ }]
578
+ },
579
+ "array containing set" => {
580
+ :input => {
581
+ "http://example.com/foo" => [{"@set" => []}]
582
+ },
583
+ :output => [{
584
+ "http://example.com/foo" => []
585
+ }]
586
+ },
587
+ }.each do |title, params|
588
+ it title do
589
+ jld = JSON::LD::API.expand(params[:input], nil, nil, :debug => @debug)
590
+ jld.should produce(params[:output], @debug)
591
+ end
592
+ end
593
+ end
594
+
595
+ context "exceptions" do
596
+ {
597
+ "@list containing @list" => {
598
+ :input => {
599
+ "http://example.com/foo" => {"@list" => [{"@list" => ["baz"]}]}
600
+ },
601
+ :exception => JSON::LD::ProcessingError::ListOfLists
602
+ },
603
+ "@list containing @list (with coercion)" => {
604
+ :input => {
605
+ "@context" => {"foo" => {"@id" => "http://example.com/foo", "@container" => "@list"}},
606
+ "foo" => [{"@list" => ["baz"]}]
607
+ },
608
+ :exception => JSON::LD::ProcessingError::ListOfLists
609
+ },
610
+ "coerced @list containing an array" => {
611
+ :input => {
612
+ "@context" => {"foo" => {"@id" => "http://example.com/foo", "@container" => "@list"}},
613
+ "foo" => [["baz"]]
614
+ },
615
+ :exception => JSON::LD::ProcessingError::ListOfLists
616
+ },
617
+ }.each do |title, params|
618
+ it title do
619
+ #JSON::LD::API.expand(params[:input], nil, nil, :debug => @debug).should produce([], @debug)
620
+ lambda {JSON::LD::API.expand(params[:input], nil, nil)}.should raise_error(params[:exception])
621
+ end
622
+ end
623
+ end
624
+ end
625
+ end