json-ld 3.0.0 → 3.0.1

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.
@@ -81,17 +81,17 @@ describe JSON::LD::API do
81
81
  options = {logger: logger, adapter: adapter}
82
82
  options[:expandContext] = File.open(context) if context
83
83
  jld = described_class.expand(File.open(filename), options)
84
- expect(jld).to produce(JSON.load(File.open(expanded)), logger)
84
+ expect(jld).to produce_jsonld(JSON.load(File.open(expanded)), logger)
85
85
  end if File.exist?(expanded)
86
86
 
87
87
  it "compacts" do
88
88
  jld = described_class.compact(File.open(filename), File.open(context), adapter: adapter, logger: logger)
89
- expect(jld).to produce(JSON.load(File.open(compacted)), logger)
89
+ expect(jld).to produce_jsonld(JSON.load(File.open(compacted)), logger)
90
90
  end if File.exist?(compacted) && File.exist?(context)
91
91
 
92
92
  it "frame" do
93
93
  jld = described_class.frame(File.open(filename), File.open(frame), adapter: adapter, logger: logger)
94
- expect(jld).to produce(JSON.load(File.open(framed)), logger)
94
+ expect(jld).to produce_jsonld(JSON.load(File.open(framed)), logger)
95
95
  end if File.exist?(framed) && File.exist?(frame)
96
96
 
97
97
  it "toRdf" do
@@ -501,7 +501,7 @@ describe JSON::LD::API do
501
501
  })
502
502
  allow(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
503
503
  jld = JSON::LD::API.compact(input, "http://example.com/context", logger: logger, validate: true)
504
- expect(jld).to produce(expected, logger)
504
+ expect(jld).to produce_jsonld(expected, logger)
505
505
  end
506
506
  end
507
507
 
@@ -2237,7 +2237,12 @@ describe JSON::LD::API do
2237
2237
  expect {JSON::LD::API.compact(input, context, params.merge(logger: logger))}.to raise_error(params[:exception])
2238
2238
  else
2239
2239
  jld = JSON::LD::API.compact(input, context, params.merge(logger: logger))
2240
- expect(jld).to produce(output, logger)
2240
+ expect(jld).to produce_jsonld(output, logger)
2241
+
2242
+ # Compare expanded jld/output too to make sure list values remain ordered
2243
+ exp_jld = JSON::LD::API.expand(jld, processingMode: 'json-ld-1.1')
2244
+ exp_output = JSON::LD::API.expand(output, processingMode: 'json-ld-1.1')
2245
+ expect(exp_jld).to produce_jsonld(exp_output, logger)
2241
2246
  end
2242
2247
  end
2243
2248
  end
@@ -96,6 +96,32 @@ describe JSON::LD::API do
96
96
  it(title) {run_expand params}
97
97
  end
98
98
 
99
+ context "default language" do
100
+ {
101
+ "base": {
102
+ input: %({
103
+ "http://example/foo": "bar"
104
+ }),
105
+ output: %([{
106
+ "http://example/foo": [{"@value": "bar", "@language": "en"}]
107
+ }]),
108
+ language: "en"
109
+ },
110
+ "override": {
111
+ input: %({
112
+ "@context": {"@language": null},
113
+ "http://example/foo": "bar"
114
+ }),
115
+ output: %([{
116
+ "http://example/foo": [{"@value": "bar"}]
117
+ }]),
118
+ language: "en"
119
+ }
120
+ }.each_pair do |title, params|
121
+ it(title) {run_expand params}
122
+ end
123
+ end
124
+
99
125
  context "with relative IRIs" do
100
126
  {
101
127
  "base": {
@@ -2349,15 +2375,15 @@ describe JSON::LD::API do
2349
2375
  end
2350
2376
 
2351
2377
  def run_expand(params)
2352
- input, output, processingMode = params[:input], params[:output], params[:processingMode]
2378
+ input, output = params[:input], params[:output]
2353
2379
  input = ::JSON.parse(input) if input.is_a?(String)
2354
2380
  output = ::JSON.parse(output) if output.is_a?(String)
2355
2381
  pending params.fetch(:pending, "test implementation") unless input
2356
2382
  if params[:exception]
2357
- expect {JSON::LD::API.expand(input, {processingMode: processingMode}.merge(params))}.to raise_error(params[:exception])
2383
+ expect {JSON::LD::API.expand(input, params)}.to raise_error(params[:exception])
2358
2384
  else
2359
- jld = JSON::LD::API.expand(input, base: params[:base], logger: logger, processingMode: processingMode)
2360
- expect(jld).to produce(output, logger)
2385
+ jld = JSON::LD::API.expand(input, {logger: logger}.merge(params))
2386
+ expect(jld).to produce_jsonld(output, logger)
2361
2387
  end
2362
2388
  end
2363
2389
  end
@@ -294,7 +294,7 @@ describe JSON::LD::API do
294
294
  expect {JSON::LD::API.flatten(input, context, params.merge(logger: logger))}.to raise_error(params[:exception])
295
295
  else
296
296
  jld = JSON::LD::API.flatten(input, context, params.merge(logger: logger))
297
- expect(jld).to produce(output, logger)
297
+ expect(jld).to produce_jsonld(output, logger)
298
298
  end
299
299
  end
300
300
  end
@@ -652,20 +652,18 @@ describe JSON::LD::API do
652
652
  "query": {"@id": "mq:query", "@type": "@id"},
653
653
  "result": {"@id": "mf:result", "@type": "xsd:boolean"}
654
654
  },
655
- "@graph": [{
656
- "@type": "mf:Manifest",
657
- "comment": "Positive processor tests",
658
- "entries": [{
659
- "@type": "mf:ManifestEntry",
660
- "action": {
661
- "@type": "mq:QueryTest",
662
- "data": "http://www.w3.org/TR/microdata-rdf/tests/0001.html",
663
- "query": "http://www.w3.org/TR/microdata-rdf/tests/0001.ttl"
664
- },
665
- "comment": "Item with no itemtype and literal itemprop",
666
- "mf:result": "true",
667
- "name": "Test 0001"
668
- }]
655
+ "@type": "mf:Manifest",
656
+ "comment": "Positive processor tests",
657
+ "entries": [{
658
+ "@type": "mf:ManifestEntry",
659
+ "action": {
660
+ "@type": "mq:QueryTest",
661
+ "data": "http://www.w3.org/TR/microdata-rdf/tests/0001.html",
662
+ "query": "http://www.w3.org/TR/microdata-rdf/tests/0001.ttl"
663
+ },
664
+ "comment": "Item with no itemtype and literal itemprop",
665
+ "mf:result": "true",
666
+ "name": "Test 0001"
669
667
  }]
670
668
  }),
671
669
  processingMode: 'json-ld-1.1'
@@ -815,7 +813,7 @@ describe JSON::LD::API do
815
813
  frame = ::JSON.parse(frame) if frame.is_a?(String)
816
814
  output = ::JSON.parse(output) if output.is_a?(String)
817
815
  jld = JSON::LD::API.frame(input, frame, logger: logger)
818
- expect(jld).to produce(output, logger)
816
+ expect(jld).to produce_jsonld(output, logger)
819
817
  rescue JSON::LD::JsonLdError => e
820
818
  fail("#{e.class}: #{e.message}\n" +
821
819
  "#{logger}\n" +
@@ -1129,11 +1127,9 @@ describe JSON::LD::API do
1129
1127
  }),
1130
1128
  output: %({
1131
1129
  "@context": {"@vocab": "urn:"},
1132
- "@graph": [{
1133
- "@id": "urn:id-1",
1134
- "@type": "Class",
1135
- "preserve": {}
1136
- }]
1130
+ "@id": "urn:id-1",
1131
+ "@type": "Class",
1132
+ "preserve": {}
1137
1133
  }),
1138
1134
  processingMode: 'json-ld-1.1'
1139
1135
  },
@@ -1157,17 +1153,15 @@ describe JSON::LD::API do
1157
1153
  }),
1158
1154
  output: %({
1159
1155
  "@context": {"@vocab": "urn:"},
1160
- "@graph": [{
1161
- "@id": "urn:id-1",
1162
- "@type": "Class",
1163
- "preserve": {
1164
- "@id": "urn:gr-1",
1165
- "@graph": {
1166
- "@id": "urn:id-2",
1167
- "term": "data"
1168
- }
1156
+ "@id": "urn:id-1",
1157
+ "@type": "Class",
1158
+ "preserve": {
1159
+ "@id": "urn:gr-1",
1160
+ "@graph": {
1161
+ "@id": "urn:id-2",
1162
+ "term": "data"
1169
1163
  }
1170
- }]
1164
+ }
1171
1165
  }),
1172
1166
  processingMode: 'json-ld-1.1'
1173
1167
  },
@@ -1200,21 +1194,19 @@ describe JSON::LD::API do
1200
1194
  }),
1201
1195
  output: %({
1202
1196
  "@context": {"@vocab": "urn:"},
1203
- "@graph": [{
1204
- "@id": "urn:id-1",
1205
- "@type": "Class",
1206
- "merge": {
1207
- "@id": "urn:id-2",
1208
- "term": "foo"
1209
- },
1210
- "preserve": {
1211
- "@id": "urn:graph-1",
1212
- "@graph": {
1213
- "@id": "urn:id-3",
1214
- "term": "bar"
1215
- }
1197
+ "@id": "urn:id-1",
1198
+ "@type": "Class",
1199
+ "merge": {
1200
+ "@id": "urn:id-2",
1201
+ "term": "foo"
1202
+ },
1203
+ "preserve": {
1204
+ "@id": "urn:graph-1",
1205
+ "@graph": {
1206
+ "@id": "urn:id-3",
1207
+ "term": "bar"
1216
1208
  }
1217
- }]
1209
+ }
1218
1210
  }),
1219
1211
  processingMode: 'json-ld-1.1'
1220
1212
  },
@@ -1250,22 +1242,20 @@ describe JSON::LD::API do
1250
1242
  }),
1251
1243
  output: %({
1252
1244
  "@context": {"@vocab": "urn:"},
1253
- "@graph": [{
1254
- "@id": "urn:id-1",
1255
- "@type": "Class",
1256
- "merge": {
1257
- "@id": "urn:id-2",
1258
- "term": "foo"
1259
- },
1260
- "preserve": {
1261
- "deep": {
1262
- "@graph": {
1263
- "@id": "urn:id-3",
1264
- "term": "bar"
1265
- }
1245
+ "@id": "urn:id-1",
1246
+ "@type": "Class",
1247
+ "merge": {
1248
+ "@id": "urn:id-2",
1249
+ "term": "foo"
1250
+ },
1251
+ "preserve": {
1252
+ "deep": {
1253
+ "@graph": {
1254
+ "@id": "urn:id-3",
1255
+ "term": "bar"
1266
1256
  }
1267
1257
  }
1268
- }]
1258
+ }
1269
1259
  }),
1270
1260
  processingMode: 'json-ld-1.1'
1271
1261
  },
@@ -1301,28 +1291,24 @@ describe JSON::LD::API do
1301
1291
  }),
1302
1292
  output: %({
1303
1293
  "@context": {"@vocab": "http://example.org/"},
1304
- "@graph": [
1305
- {
1306
- "@id": "http://example.org/library",
1307
- "@type": "Library",
1308
- "name": "Library",
1294
+ "@id": "http://example.org/library",
1295
+ "@type": "Library",
1296
+ "name": "Library",
1297
+ "contains": {
1298
+ "@id": "http://example.org/graphs/books",
1299
+ "@graph": {
1300
+ "@id": "http://example.org/library/the-republic",
1301
+ "@type": "Book",
1302
+ "creator": "Plato",
1303
+ "title": "The Republic",
1309
1304
  "contains": {
1310
- "@id": "http://example.org/graphs/books",
1311
- "@graph": {
1312
- "@id": "http://example.org/library/the-republic",
1313
- "@type": "Book",
1314
- "creator": "Plato",
1315
- "title": "The Republic",
1316
- "contains": {
1317
- "@id": "http://example.org/library/the-republic#introduction",
1318
- "@type": "Chapter",
1319
- "description": "An introductory chapter on The Republic.",
1320
- "title": "The Introduction"
1321
- }
1322
- }
1305
+ "@id": "http://example.org/library/the-republic#introduction",
1306
+ "@type": "Chapter",
1307
+ "description": "An introductory chapter on The Republic.",
1308
+ "title": "The Introduction"
1323
1309
  }
1324
1310
  }
1325
- ]
1311
+ }
1326
1312
  }),
1327
1313
  processingMode: 'json-ld-1.1'
1328
1314
  }
@@ -1523,14 +1509,10 @@ describe JSON::LD::API do
1523
1509
  },
1524
1510
  "id": "@id"
1525
1511
  },
1526
- "@graph": [
1527
- {
1528
- "claim": {
1529
- "id": "ex:1",
1530
- "test": "foo"
1531
- }
1532
- }
1533
- ]
1512
+ "claim": {
1513
+ "id": "ex:1",
1514
+ "test": "foo"
1515
+ }
1534
1516
  })
1535
1517
  do_frame(input: input, frame: frame, output: expected, processingMode: 'json-ld-1.1')
1536
1518
  end
@@ -1708,7 +1690,12 @@ describe JSON::LD::API do
1708
1690
  frame = ::JSON.parse(frame) if frame.is_a?(String)
1709
1691
  output = ::JSON.parse(output) if output.is_a?(String)
1710
1692
  jld = JSON::LD::API.frame(input, frame, logger: logger, processingMode: processingMode)
1711
- expect(jld).to produce(output, logger)
1693
+ expect(jld).to produce_jsonld(output, logger)
1694
+
1695
+ # Compare expanded jld/output too to make sure list values remain ordered
1696
+ exp_jld = JSON::LD::API.expand(jld, processingMode: 'json-ld-1.1')
1697
+ exp_output = JSON::LD::API.expand(output, processingMode: 'json-ld-1.1')
1698
+ expect(exp_jld).to produce_jsonld(exp_output, logger)
1712
1699
  rescue JSON::LD::JsonLdError => e
1713
1700
  fail("#{e.class}: #{e.message}\n" +
1714
1701
  "#{logger}\n" +
@@ -9,7 +9,7 @@ describe JSON::LD::API do
9
9
  context "simple tests" do
10
10
  it "One subject IRI object" do
11
11
  input = %(<http://a/b> <http://a/c> <http://a/d> .)
12
- expect(serialize(input)).to produce([
12
+ expect(serialize(input)).to produce_jsonld([
13
13
  {
14
14
  '@id' => "http://a/b",
15
15
  "http://a/c" => [{"@id" => "http://a/d"}]
@@ -20,7 +20,7 @@ describe JSON::LD::API do
20
20
  it "should generate object list" do
21
21
  input = %(@prefix : <http://example.com/> . :b :c :d, :e .)
22
22
  expect(serialize(input)).
23
- to produce([{
23
+ to produce_jsonld([{
24
24
  '@id' => "http://example.com/b",
25
25
  "http://example.com/c" => [
26
26
  {"@id" => "http://example.com/d"},
@@ -33,7 +33,7 @@ describe JSON::LD::API do
33
33
  it "should generate property list" do
34
34
  input = %(@prefix : <http://example.com/> . :b :c :d; :e :f .)
35
35
  expect(serialize(input)).
36
- to produce([{
36
+ to produce_jsonld([{
37
37
  '@id' => "http://example.com/b",
38
38
  "http://example.com/c" => [{"@id" => "http://example.com/d"}],
39
39
  "http://example.com/e" => [{"@id" => "http://example.com/f"}]
@@ -49,7 +49,7 @@ describe JSON::LD::API do
49
49
  <test-cases/0002> a :TestCase .
50
50
  )
51
51
  expect(serialize(input)).
52
- to produce([
52
+ to produce_jsonld([
53
53
  {'@id' => "test-cases/0001", '@type' => ["http://www.w3.org/2006/03/test-description#TestCase"]},
54
54
  {'@id' => "test-cases/0002", '@type' => ["http://www.w3.org/2006/03/test-description#TestCase"]},
55
55
  ], logger)
@@ -60,7 +60,7 @@ describe JSON::LD::API do
60
60
  context "coercion" do
61
61
  it "typed literal" do
62
62
  input = %(@prefix ex: <http://example.com/> . ex:a ex:b "foo"^^ex:d .)
63
- expect(serialize(input)).to produce([
63
+ expect(serialize(input)).to produce_jsonld([
64
64
  {
65
65
  '@id' => "http://example.com/a",
66
66
  "http://example.com/b" => [{"@value" => "foo", "@type" => "http://example.com/d"}]
@@ -70,7 +70,7 @@ describe JSON::LD::API do
70
70
 
71
71
  it "integer" do
72
72
  input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1 .)
73
- expect(serialize(input, useNativeTypes: true)).to produce([{
73
+ expect(serialize(input, useNativeTypes: true)).to produce_jsonld([{
74
74
  '@id' => "http://example.com/a",
75
75
  "http://example.com/b" => [{"@value" => 1}]
76
76
  }], logger)
@@ -78,7 +78,7 @@ describe JSON::LD::API do
78
78
 
79
79
  it "integer (non-native)" do
80
80
  input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1 .)
81
- expect(serialize(input, useNativeTypes: false)).to produce([{
81
+ expect(serialize(input, useNativeTypes: false)).to produce_jsonld([{
82
82
  '@id' => "http://example.com/a",
83
83
  "http://example.com/b" => [{"@value" => "1","@type" => "http://www.w3.org/2001/XMLSchema#integer"}]
84
84
  }], logger)
@@ -86,7 +86,7 @@ describe JSON::LD::API do
86
86
 
87
87
  it "boolean" do
88
88
  input = %(@prefix ex: <http://example.com/> . ex:a ex:b true .)
89
- expect(serialize(input, useNativeTypes: true)).to produce([{
89
+ expect(serialize(input, useNativeTypes: true)).to produce_jsonld([{
90
90
  '@id' => "http://example.com/a",
91
91
  "http://example.com/b" => [{"@value" => true}]
92
92
  }], logger)
@@ -94,7 +94,7 @@ describe JSON::LD::API do
94
94
 
95
95
  it "boolean (non-native)" do
96
96
  input = %(@prefix ex: <http://example.com/> . ex:a ex:b true .)
97
- expect(serialize(input, useNativeTypes: false)).to produce([{
97
+ expect(serialize(input, useNativeTypes: false)).to produce_jsonld([{
98
98
  '@id' => "http://example.com/a",
99
99
  "http://example.com/b" => [{"@value" => "true","@type" => "http://www.w3.org/2001/XMLSchema#boolean"}]
100
100
  }], logger)
@@ -102,7 +102,7 @@ describe JSON::LD::API do
102
102
 
103
103
  it "decmal" do
104
104
  input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0 .)
105
- expect(serialize(input, useNativeTypes: true)).to produce([{
105
+ expect(serialize(input, useNativeTypes: true)).to produce_jsonld([{
106
106
  '@id' => "http://example.com/a",
107
107
  "http://example.com/b" => [{"@value" => "1.0", "@type" => "http://www.w3.org/2001/XMLSchema#decimal"}]
108
108
  }], logger)
@@ -110,7 +110,7 @@ describe JSON::LD::API do
110
110
 
111
111
  it "double" do
112
112
  input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0e0 .)
113
- expect(serialize(input, useNativeTypes: true)).to produce([{
113
+ expect(serialize(input, useNativeTypes: true)).to produce_jsonld([{
114
114
  '@id' => "http://example.com/a",
115
115
  "http://example.com/b" => [{"@value" => 1.0E0}]
116
116
  }], logger)
@@ -118,7 +118,7 @@ describe JSON::LD::API do
118
118
 
119
119
  it "double (non-native)" do
120
120
  input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0e0 .)
121
- expect(serialize(input, useNativeTypes: false)).to produce([{
121
+ expect(serialize(input, useNativeTypes: false)).to produce_jsonld([{
122
122
  '@id' => "http://example.com/a",
123
123
  "http://example.com/b" => [{"@value" => "1.0E0","@type" => "http://www.w3.org/2001/XMLSchema#double"}]
124
124
  }], logger)
@@ -140,7 +140,7 @@ describe JSON::LD::API do
140
140
  @prefix ex: <http://example.com/> .
141
141
  ex:a ex:b "#{v}"^^xsd:#{t} .
142
142
  )
143
- expect(serialize(input, useNativeTypes: false)).to produce([{
143
+ expect(serialize(input, useNativeTypes: false)).to produce_jsonld([{
144
144
  '@id' => "http://example.com/a",
145
145
  "http://example.com/b" => [{"@value" => "#{v}","@type" => "http://www.w3.org/2001/XMLSchema##{t}"}]
146
146
  }], logger)
@@ -150,7 +150,7 @@ describe JSON::LD::API do
150
150
 
151
151
  it "encodes language literal" do
152
152
  input = %(@prefix ex: <http://example.com/> . ex:a ex:b "foo"@en-us .)
153
- expect(serialize(input)).to produce([{
153
+ expect(serialize(input)).to produce_jsonld([{
154
154
  '@id' => "http://example.com/a",
155
155
  "http://example.com/b" => [{"@value" => "foo", "@language" => "en-us"}]
156
156
  }], logger)
@@ -160,7 +160,7 @@ describe JSON::LD::API do
160
160
  context "anons" do
161
161
  it "should generate bare anon" do
162
162
  input = %(@prefix : <http://example.com/> . _:a :a :b .)
163
- expect(serialize(input)).to produce([
163
+ expect(serialize(input)).to produce_jsonld([
164
164
  {
165
165
  "@id" => "_:a",
166
166
  "http://example.com/a" => [{"@id" => "http://example.com/b"}]
@@ -170,7 +170,7 @@ describe JSON::LD::API do
170
170
 
171
171
  it "should generate anon as object" do
172
172
  input = %(@prefix : <http://example.com/> . :a :b _:a . _:a :c :d .)
173
- expect(serialize(input)).to produce([
173
+ expect(serialize(input)).to produce_jsonld([
174
174
  {
175
175
  "@id" => "_:a",
176
176
  "http://example.com/c" => [{"@id" => "http://example.com/d"}]
@@ -185,13 +185,13 @@ describe JSON::LD::API do
185
185
 
186
186
  context "lists" do
187
187
  {
188
- "literal list" => [
189
- %q(
188
+ "literal list" => {
189
+ input: %q(
190
190
  @prefix : <http://example.com/> .
191
191
  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
192
192
  :a :b ("apple" "banana") .
193
193
  ),
194
- [{
194
+ output: [{
195
195
  '@id' => "http://example.com/a",
196
196
  "http://example.com/b" => [{
197
197
  "@list" => [
@@ -200,10 +200,10 @@ describe JSON::LD::API do
200
200
  ]
201
201
  }]
202
202
  }]
203
- ],
204
- "iri list" => [
205
- %q(@prefix : <http://example.com/> . :a :b (:c) .),
206
- [{
203
+ },
204
+ "iri list" => {
205
+ input: %q(@prefix : <http://example.com/> . :a :b (:c) .),
206
+ output: [{
207
207
  '@id' => "http://example.com/a",
208
208
  "http://example.com/b" => [{
209
209
  "@list" => [
@@ -211,24 +211,24 @@ describe JSON::LD::API do
211
211
  ]
212
212
  }]
213
213
  }]
214
- ],
215
- "empty list" => [
216
- %q(@prefix : <http://example.com/> . :a :b () .),
217
- [{
214
+ },
215
+ "empty list" => {
216
+ input: %q(@prefix : <http://example.com/> . :a :b () .),
217
+ output: [{
218
218
  '@id' => "http://example.com/a",
219
219
  "http://example.com/b" => [{"@list" => []}]
220
220
  }]
221
- ],
222
- "single element list" => [
223
- %q(@prefix : <http://example.com/> . :a :b ( "apple" ) .),
224
- [{
221
+ },
222
+ "single element list" => {
223
+ input: %q(@prefix : <http://example.com/> . :a :b ( "apple" ) .),
224
+ output: [{
225
225
  '@id' => "http://example.com/a",
226
226
  "http://example.com/b" => [{"@list" => [{"@value" => "apple"}]}]
227
227
  }]
228
- ],
229
- "single element list without @type" => [
230
- %q(@prefix : <http://example.com/> . :a :b ( _:a ) . _:a :b "foo" .),
231
- [
228
+ },
229
+ "single element list without @type" => {
230
+ input: %q(@prefix : <http://example.com/> . :a :b ( _:a ) . _:a :b "foo" .),
231
+ output: [
232
232
  {
233
233
  '@id' => "_:a",
234
234
  "http://example.com/b" => [{"@value" => "foo"}]
@@ -238,9 +238,9 @@ describe JSON::LD::API do
238
238
  "http://example.com/b" => [{"@list" => [{"@id" => "_:a"}]}]
239
239
  },
240
240
  ]
241
- ],
242
- "multiple graphs with shared BNode" => [
243
- %q(
241
+ },
242
+ "multiple graphs with shared BNode" => {
243
+ input: %q(
244
244
  <http://www.example.com/z> <http://www.example.com/q> _:z0 <http://www.example.com/G> .
245
245
  _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "cell-A" <http://www.example.com/G> .
246
246
  _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:z1 <http://www.example.com/G> .
@@ -248,7 +248,7 @@ describe JSON::LD::API do
248
248
  _: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> .
249
249
  <http://www.example.com/x> <http://www.example.com/p> _:z1 <http://www.example.com/G1> .
250
250
  ),
251
- [{
251
+ output: [{
252
252
  "@id" => "http://www.example.com/G",
253
253
  "@graph" => [{
254
254
  "@id" => "_:z0",
@@ -270,10 +270,10 @@ describe JSON::LD::API do
270
270
  "http://www.example.com/p" => [{"@id" => "_:z1"}]
271
271
  }]
272
272
  }],
273
- RDF::NQuads::Reader
274
- ],
275
- "multiple graphs with shared BNode (at head)" => [
276
- %q(
273
+ reader: RDF::NQuads::Reader
274
+ },
275
+ "multiple graphs with shared BNode (at head)" => {
276
+ input: %q(
277
277
  <http://www.example.com/z> <http://www.example.com/q> _:z0 <http://www.example.com/G> .
278
278
  _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "cell-A" <http://www.example.com/G> .
279
279
  _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:z1 <http://www.example.com/G> .
@@ -281,7 +281,7 @@ describe JSON::LD::API do
281
281
  _: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> .
282
282
  <http://www.example.com/z> <http://www.example.com/q> _:z0 <http://www.example.com/G1> .
283
283
  ),
284
- [{
284
+ output: [{
285
285
  "@id" => "http://www.example.com/G",
286
286
  "@graph" => [{
287
287
  "@id" => "_:z0",
@@ -299,33 +299,33 @@ describe JSON::LD::API do
299
299
  "http://www.example.com/q" => [{"@id" => "_:z0"}]
300
300
  }]
301
301
  }],
302
- RDF::NQuads::Reader
303
- ],
304
- "@list containing empty @list" => [
305
- %(
302
+ reader: RDF::NQuads::Reader
303
+ },
304
+ "@list containing empty @list" => {
305
+ input: %(
306
306
  <http://example.com/a> <http://example.com/property> (()) .
307
307
  ),
308
- JSON.parse(%([{
308
+ output: %([{
309
309
  "@id": "http://example.com/a",
310
310
  "http://example.com/property": [{"@list": [{"@list": []}]}]
311
- }])),
312
- RDF::Turtle::Reader
313
- ],
314
- "@list containing multiple lists" => [
315
- %(
311
+ }]),
312
+ reader: RDF::Turtle::Reader
313
+ },
314
+ "@list containing multiple lists" => {
315
+ input: %(
316
316
  <http://example.com/a> <http://example.com/property> (("a") ("b")) .
317
317
  ),
318
- JSON.parse(%([{
318
+ output: %([{
319
319
  "@id": "http://example.com/a",
320
320
  "http://example.com/property": [{"@list": [
321
321
  {"@list": [{"@value": "a"}]},
322
322
  {"@list": [{"@value": "b"}]}
323
323
  ]}]
324
- }])),
325
- RDF::Turtle::Reader
326
- ],
327
- "0008a" => [
328
- %(
324
+ }]),
325
+ reader: RDF::Turtle::Reader
326
+ },
327
+ "0008a" => {
328
+ input: %(
329
329
  <http://example.com> <http://example.com/property> _:outerlist .
330
330
  _:outerlist <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:lista .
331
331
  _:outerlist <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b0 .
@@ -355,7 +355,7 @@ describe JSON::LD::API do
355
355
  _:b3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "b3" .
356
356
  _:b3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
357
357
  ),
358
- JSON.parse(%([
358
+ output: JSON.parse(%([
359
359
  {
360
360
  "@id": "http://example.com",
361
361
  "http://example.com/property": [
@@ -369,12 +369,11 @@ describe JSON::LD::API do
369
369
  ]
370
370
  }
371
371
  ])),
372
- RDF::NQuads::Reader
373
- ]
374
- }.each do |name, (input, output, reader)|
375
- it name do
376
- r = serialize(input, reader: reader)
377
- expect(r).to produce(output, logger)
372
+ reader: RDF::NQuads::Reader
373
+ }
374
+ }.each do |name, params|
375
+ it "#{name}" do
376
+ do_fromRdf(params)
378
377
  end
379
378
  end
380
379
  end
@@ -465,33 +464,32 @@ describe JSON::LD::API do
465
464
  }
466
465
  ]
467
466
  },
468
- }.each_pair do |name, properties|
469
- it name do
470
- r = serialize(properties[:input], reader: RDF::NQuads::Reader)
471
- expect(r).to produce(properties[:output], logger)
467
+ }.each_pair do |name, params|
468
+ it "#{name}" do
469
+ do_fromRdf(params.merge(reader: RDF::NQuads::Reader))
472
470
  end
473
471
  end
474
472
  end
475
473
 
476
474
  context "problems" do
477
475
  {
478
- "xsd:boolean as value" => [
479
- %(
476
+ "xsd:boolean as value" => {
477
+ input: %(
480
478
  @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
481
479
  @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
482
480
 
483
481
  <http://data.wikia.com/terms#playable> rdfs:range xsd:boolean .
484
482
  ),
485
- [{
483
+ output: [{
486
484
  "@id" => "http://data.wikia.com/terms#playable",
487
485
  "http://www.w3.org/2000/01/rdf-schema#range" => [
488
486
  { "@id" => "http://www.w3.org/2001/XMLSchema#boolean" }
489
487
  ]
490
488
  }]
491
- ],
492
- }.each do |t, (input, output)|
489
+ },
490
+ }.each do |t, params|
493
491
  it "#{t}" do
494
- expect(serialize(input)).to produce(output, logger)
492
+ do_fromRdf(params)
495
493
  end
496
494
  end
497
495
  end
@@ -510,4 +508,17 @@ describe JSON::LD::API do
510
508
  statements = g.each_statement.to_a
511
509
  JSON::LD::API.fromRdf(statements, logger: logger, **options)
512
510
  end
511
+
512
+ def do_fromRdf(params)
513
+ begin
514
+ input, output, processingMode = params[:input], params[:output], params.fetch(:processingMode, 'json-ld-1.0')
515
+ output = ::JSON.parse(output) if output.is_a?(String)
516
+ jld = serialize(input, **params)
517
+ expect(jld).to produce_jsonld(output, logger)
518
+ rescue JSON::LD::JsonLdError => e
519
+ fail("#{e.class}: #{e.message}\n" +
520
+ "#{logger}\n" +
521
+ "Backtrace:\n#{e.backtrace.join("\n")}")
522
+ end
523
+ end
513
524
  end