json-ld 2.1.7 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/context_spec.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # coding: utf-8
2
- $:.unshift "."
3
- require 'spec_helper'
2
+ require_relative 'spec_helper'
4
3
  require 'rdf/xsd'
5
4
  require 'rdf/spec/reader'
6
5
 
@@ -196,7 +195,7 @@ describe JSON::LD::Context do
196
195
  expect(subject.parse({
197
196
  "foo" => {"@id" => "http://example.com/", "@container" => "@list"}
198
197
  }).containers).to produce({
199
- "foo" => '@list'
198
+ "foo" => %w(@list)
200
199
  }, logger)
201
200
  end
202
201
 
@@ -204,7 +203,7 @@ describe JSON::LD::Context do
204
203
  expect(subject.parse({
205
204
  "foo" => {"@id" => "http://example.com/", "@container" => "@type"}
206
205
  }).containers).to produce({
207
- "foo" => "@type"
206
+ "foo" => %w(@type)
208
207
  }, logger)
209
208
  end
210
209
 
@@ -212,7 +211,7 @@ describe JSON::LD::Context do
212
211
  expect(subject.parse({
213
212
  "foo" => {"@id" => "http://example.com/", "@container" => "@id"}
214
213
  }).containers).to produce({
215
- "foo" => "@id"
214
+ "foo" => %w(@id)
216
215
  }, logger)
217
216
  end
218
217
 
@@ -953,6 +952,7 @@ describe JSON::LD::Context do
953
952
  "setdouble" => {"@id" => "http://example.com/double", "@type" => "xsd:double", "@container" => "@set"},
954
953
  "setdate" => {"@id" => "http://example.com/date", "@type" => "xsd:date", "@container" => "@set"},
955
954
  "setid" => {"@id" => "http://example.com/id", "@type" => "@id", "@container" => "@set"},
955
+ 'setgraph' => {'@id' => 'http://example.com/graph', '@container' => ['@graph', '@set']},
956
956
  "langmap" => {"@id" => "http://example.com/langmap", "@container" => "@language"},
957
957
  })
958
958
  logger.clear
@@ -960,9 +960,12 @@ describe JSON::LD::Context do
960
960
  end
961
961
 
962
962
  {
963
+ "plain" => [{"@value" => "foo"}],
963
964
  "langmap" => [{"@value" => "en", "@language" => "en"}],
964
- #"plain" => [{"@value" => "foo"}],
965
- #"setplain" => [{"@value" => "foo", "@language" => "pl"}]
965
+ "setbool" => [{"@value" => "true", "@type" => "http://www.w3.org/2001/XMLSchema#boolean"}],
966
+ "setinteger" => [{"@value" => "1", "@type" => "http://www.w3.org/2001/XMLSchema#integer"}],
967
+ "setid" => [{"@id" => "http://example.org/id"}],
968
+ "setgraph" => [{"@graph" => [{"@id" => "http://example.org/id"}]}],
966
969
  }.each do |prop, values|
967
970
  context "uses #{prop}" do
968
971
  values.each do |value|
@@ -1365,38 +1368,95 @@ describe JSON::LD::Context do
1365
1368
  describe "#container" do
1366
1369
  subject {
1367
1370
  ctx = context.parse({
1368
- "ex" => "http://example.org/",
1369
- "list" => {"@id" => "ex:list", "@container" => "@list"},
1370
- "set" => {"@id" => "ex:set", "@container" => "@set"},
1371
- "language" => {"@id" => "ex:language", "@container" => "@language"},
1372
- "ndx" => {"@id" => "ex:ndx", "@container" => "@index"},
1373
- "id" => {"@id" => "ex:id", "@container" => "@id"},
1374
- "type" => {"@id" => "ex:type", "@container" => "@type"}
1371
+ "ex" => "http://example.org/",
1372
+ "graph" => {"@id" => "ex:graph", "@container" => "@graph"},
1373
+ "graphSet" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@set"]},
1374
+ "graphId" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@id"]},
1375
+ "graphIdSet" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@id", "@set"]},
1376
+ "graphNdx" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@index"]},
1377
+ "graphNdxSet" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@index", "@set"]},
1378
+ "id" => {"@id" => "ex:idSet", "@container" => "@id"},
1379
+ "idSet" => {"@id" => "ex:id", "@container" => ["@id", "@set"]},
1380
+ "language" => {"@id" => "ex:language", "@container" => "@language"},
1381
+ "langSet" => {"@id" => "ex:languageSet", "@container" => ["@language", "@set"]},
1382
+ "list" => {"@id" => "ex:list", "@container" => "@list"},
1383
+ "ndx" => {"@id" => "ex:ndx", "@container" => "@index"},
1384
+ "ndxSet" => {"@id" => "ex:ndxSet", "@container" => ["@index", "@set"]},
1385
+ "set" => {"@id" => "ex:set", "@container" => "@set"},
1386
+ "type" => {"@id" => "ex:type", "@container" => "@type"},
1387
+ "typeSet" => {"@id" => "ex:typeSet", "@container" => ["@type", "@set"]},
1375
1388
  })
1376
1389
  logger.clear
1377
1390
  ctx
1378
1391
  }
1392
+
1379
1393
  it "uses TermDefinition" do
1380
1394
  {
1381
- "ex" => nil,
1382
- "list" => "@list",
1383
- "language" => "@language",
1384
- "ndx" => "@index",
1385
- "id" => "@id",
1386
- "type" => "@type",
1395
+ "ex" => [],
1396
+ "graph" => %w(@graph),
1397
+ "graphSet" => %w(@graph),
1398
+ "graphId" => %w(@graph @id),
1399
+ "graphIdSet" => %w(@graph @id),
1400
+ "graphNdx" => %w(@graph @index),
1401
+ "graphNdxSet" => %w(@graph @index),
1402
+ "id" => %w(@id),
1403
+ "idSet" => %w(@id),
1404
+ "language" => %w(@language),
1405
+ "langSet" => %w(@language),
1406
+ "list" => %w(@list),
1407
+ "ndx" => %w(@index),
1408
+ "ndxSet" => %w(@index),
1409
+ "set" => [],
1410
+ "type" => %w(@type),
1411
+ "typeSet" => %w(@type),
1387
1412
  }.each do |defn, container|
1388
1413
  expect(subject.container(subject.term_definitions[defn])).to eq container
1389
1414
  end
1390
1415
  end
1391
1416
 
1392
- it "uses string" do
1417
+ it "#as_array" do
1393
1418
  {
1394
- "ex" => nil,
1395
- "list" => "@list",
1396
- "language" => "@language",
1397
- "ndx" => "@index",
1398
- "id" => "@id",
1399
- "type" => "@type",
1419
+ "ex" => false,
1420
+ "graph" => false,
1421
+ "graphSet" => true,
1422
+ "graphId" => false,
1423
+ "graphIdSet" => true,
1424
+ "graphNdx" => false,
1425
+ "graphNdxSet" => true,
1426
+ "id" => false,
1427
+ "idSet" => true,
1428
+ "language" => false,
1429
+ "langSet" => true,
1430
+ "list" => true,
1431
+ "ndx" => false,
1432
+ "ndxSet" => true,
1433
+ "set" => true,
1434
+ "type" => false,
1435
+ "typeSet" => true,
1436
+ }.each do |defn, as_array|
1437
+ expect(subject.as_array?(subject.term_definitions[defn])).to eq as_array
1438
+ end
1439
+ end
1440
+
1441
+ it "uses array" do
1442
+ {
1443
+ "ex" => [],
1444
+ "graph" => %w(@graph),
1445
+ "graphSet" => %w(@graph),
1446
+ "graphId" => %w(@graph @id),
1447
+ "graphIdSet" => %w(@graph @id),
1448
+ "graphNdx" => %w(@graph @index),
1449
+ "graphNdxSet" => %w(@graph @index),
1450
+ "id" => %w(@id),
1451
+ "idSet" => %w(@id),
1452
+ "language" => %w(@language),
1453
+ "langSet" => %w(@language),
1454
+ "list" => %w(@list),
1455
+ "ndx" => %w(@index),
1456
+ "ndxSet" => %w(@index),
1457
+ "set" => [],
1458
+ "type" => %w(@type),
1459
+ "typeSet" => %w(@type),
1400
1460
  }.each do |defn, container|
1401
1461
  expect(subject.container(defn)).to eq container
1402
1462
  end
@@ -1525,12 +1585,24 @@ describe JSON::LD::Context do
1525
1585
  its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", type_mapping: "http://example.org/type"))}
1526
1586
  end
1527
1587
 
1528
- context "with container_mapping" do
1588
+ context "with container_mapping @set" do
1529
1589
  subject {described_class.new("term", container_mapping: "@set")}
1530
- its(:container_mapping) {is_expected.to be_nil}
1590
+ its(:container_mapping) {is_expected.to be_empty}
1531
1591
  its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: "@set"))}
1532
1592
  end
1533
1593
 
1594
+ context "with container_mapping @id @set" do
1595
+ subject {described_class.new("term", container_mapping: %w(@id @set))}
1596
+ its(:container_mapping) {is_expected.to eq %w(@id)}
1597
+ its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: ["@id", "@set"]))}
1598
+ end
1599
+
1600
+ context "with container_mapping @list" do
1601
+ subject {described_class.new("term", container_mapping: "@list")}
1602
+ its(:container_mapping) {is_expected.to eq %w(@list)}
1603
+ its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: "@list"))}
1604
+ end
1605
+
1534
1606
  context "with language_mapping" do
1535
1607
  subject {described_class.new("term", language_mapping: "en")}
1536
1608
  its(:language_mapping) {is_expected.to eq "en"}
data/spec/expand_spec.rb CHANGED
@@ -1,97 +1,96 @@
1
1
  # coding: utf-8
2
- $:.unshift "."
3
- require 'spec_helper'
2
+ require_relative 'spec_helper'
4
3
 
5
4
  describe JSON::LD::API do
6
5
  let(:logger) {RDF::Spec.logger}
7
6
 
8
7
  describe ".expand" do
9
8
  {
10
- "empty doc" => {
9
+ "empty doc": {
11
10
  input: {},
12
11
  output: []
13
12
  },
14
- "@list coercion" => {
15
- input: {
16
- "@context" => {
17
- "foo" => {"@id" => "http://example.com/foo", "@container" => "@list"}
13
+ "@list coercion": {
14
+ input: %({
15
+ "@context": {
16
+ "foo": {"@id": "http://example.com/foo", "@container": "@list"}
18
17
  },
19
- "foo" => [{"@value" => "bar"}]
20
- },
21
- output: [{
22
- "http://example.com/foo" => [{"@list" => [{"@value" => "bar"}]}]
23
- }]
18
+ "foo": [{"@value": "bar"}]
19
+ }),
20
+ output: %([{
21
+ "http://example.com/foo": [{"@list": [{"@value": "bar"}]}]
22
+ }])
24
23
  },
25
- "native values in list" => {
26
- input: {
27
- "http://example.com/foo" => {"@list" => [1, 2]}
28
- },
29
- output: [{
30
- "http://example.com/foo" => [{"@list" => [{"@value" => 1}, {"@value" => 2}]}]
31
- }]
24
+ "native values in list": {
25
+ input: %({
26
+ "http://example.com/foo": {"@list": [1, 2]}
27
+ }),
28
+ output: %([{
29
+ "http://example.com/foo": [{"@list": [{"@value": 1}, {"@value": 2}]}]
30
+ }])
32
31
  },
33
- "@graph" => {
34
- input: {
35
- "@context" => {"ex" => "http://example.com/"},
36
- "@graph" => [
37
- {"ex:foo" => {"@value" => "foo"}},
38
- {"ex:bar" => {"@value" => "bar"}}
32
+ "@graph": {
33
+ input: %({
34
+ "@context": {"ex": "http://example.com/"},
35
+ "@graph": [
36
+ {"ex:foo": {"@value": "foo"}},
37
+ {"ex:bar": {"@value": "bar"}}
39
38
  ]
40
- },
41
- output: [
42
- {"http://example.com/foo" => [{"@value" => "foo"}]},
43
- {"http://example.com/bar" => [{"@value" => "bar"}]}
44
- ]
39
+ }),
40
+ output: %([
41
+ {"http://example.com/foo": [{"@value": "foo"}]},
42
+ {"http://example.com/bar": [{"@value": "bar"}]}
43
+ ])
45
44
  },
46
- "@graph value (expands to array form)" => {
47
- input: {
48
- "@context" => {"ex" => "http://example.com/"},
49
- "ex:p" => {
50
- "@id" => "ex:Sub1",
51
- "@graph" => {
52
- "ex:q" => "foo"
45
+ "@graph value (expands to array form)": {
46
+ input: %({
47
+ "@context": {"ex": "http://example.com/"},
48
+ "ex:p": {
49
+ "@id": "ex:Sub1",
50
+ "@graph": {
51
+ "ex:q": "foo"
53
52
  }
54
53
  }
55
- },
56
- output: [{
57
- "http://example.com/p" => [{
58
- "@id" => "http://example.com/Sub1",
59
- "@graph" => [{
60
- "http://example.com/q" => [{"@value" => "foo"}],
54
+ }),
55
+ output: %([{
56
+ "http://example.com/p": [{
57
+ "@id": "http://example.com/Sub1",
58
+ "@graph": [{
59
+ "http://example.com/q": [{"@value": "foo"}]
61
60
  }]
62
61
  }]
63
- }]
62
+ }])
64
63
  },
65
- "@type with CURIE" => {
66
- input: {
67
- "@context" => {"ex" => "http://example.com/"},
68
- "@type" => "ex:type"
69
- },
70
- output: [
71
- {"@type" => ["http://example.com/type"]}
72
- ]
64
+ "@type with CURIE": {
65
+ input: %({
66
+ "@context": {"ex": "http://example.com/"},
67
+ "@type": "ex:type"
68
+ }),
69
+ output: %([
70
+ {"@type": ["http://example.com/type"]}
71
+ ])
73
72
  },
74
- "@type with CURIE and muliple values" => {
75
- input: {
76
- "@context" => {"ex" => "http://example.com/"},
77
- "@type" => ["ex:type1", "ex:type2"]
78
- },
79
- output: [
80
- {"@type" => ["http://example.com/type1", "http://example.com/type2"]}
81
- ]
73
+ "@type with CURIE and muliple values": {
74
+ input: %({
75
+ "@context": {"ex": "http://example.com/"},
76
+ "@type": ["ex:type1", "ex:type2"]
77
+ }),
78
+ output: %([
79
+ {"@type": ["http://example.com/type1", "http://example.com/type2"]}
80
+ ])
82
81
  },
83
- "@value with false" => {
84
- input: {"http://example.com/ex" => {"@value" => false}},
85
- output: [{"http://example.com/ex" => [{"@value" => false}]}]
82
+ "@value with false": {
83
+ input: %({"http://example.com/ex": {"@value": false}}),
84
+ output: %([{"http://example.com/ex": [{"@value": false}]}])
86
85
  },
87
- "compact IRI" => {
88
- input: {
89
- "@context" => {"ex" => "http://example.com/"},
90
- "ex:p" => {"@id" => "ex:Sub1"}
91
- },
92
- output: [{
93
- "http://example.com/p" => [{"@id" => "http://example.com/Sub1"}]
94
- }]
86
+ "compact IRI": {
87
+ input: %({
88
+ "@context": {"ex": "http://example.com/"},
89
+ "ex:p": {"@id": "ex:Sub1"}
90
+ }),
91
+ output: %([{
92
+ "http://example.com/p": [{"@id": "http://example.com/Sub1"}]
93
+ }])
95
94
  },
96
95
  }.each_pair do |title, params|
97
96
  it(title) {run_expand params}
@@ -99,43 +98,43 @@ describe JSON::LD::API do
99
98
 
100
99
  context "with relative IRIs" do
101
100
  {
102
- "base" => {
103
- input: {
104
- "@id" => "",
105
- "@type" => "http://www.w3.org/2000/01/rdf-schema#Resource"
106
- },
107
- output: [{
108
- "@id" => "http://example.org/",
109
- "@type" => ["http://www.w3.org/2000/01/rdf-schema#Resource"]
110
- }]
101
+ "base": {
102
+ input: %({
103
+ "@id": "",
104
+ "@type": "http://www.w3.org/2000/01/rdf-schema#Resource"
105
+ }),
106
+ output: %([{
107
+ "@id": "http://example.org/",
108
+ "@type": ["http://www.w3.org/2000/01/rdf-schema#Resource"]
109
+ }])
111
110
  },
112
- "relative" => {
113
- input: {
114
- "@id" => "a/b",
115
- "@type" => "http://www.w3.org/2000/01/rdf-schema#Resource"
116
- },
117
- output: [{
118
- "@id" => "http://example.org/a/b",
119
- "@type" => ["http://www.w3.org/2000/01/rdf-schema#Resource"]
120
- }]
111
+ "relative": {
112
+ input: %({
113
+ "@id": "a/b",
114
+ "@type": "http://www.w3.org/2000/01/rdf-schema#Resource"
115
+ }),
116
+ output: %([{
117
+ "@id": "http://example.org/a/b",
118
+ "@type": ["http://www.w3.org/2000/01/rdf-schema#Resource"]
119
+ }])
121
120
  },
122
- "hash" => {
123
- input: {
124
- "@id" => "#a",
125
- "@type" => "http://www.w3.org/2000/01/rdf-schema#Resource"
126
- },
127
- output: [{
128
- "@id" => "http://example.org/#a",
129
- "@type" => ["http://www.w3.org/2000/01/rdf-schema#Resource"]
130
- }]
121
+ "hash": {
122
+ input: %({
123
+ "@id": "#a",
124
+ "@type": "http://www.w3.org/2000/01/rdf-schema#Resource"
125
+ }),
126
+ output: %([{
127
+ "@id": "http://example.org/#a",
128
+ "@type": ["http://www.w3.org/2000/01/rdf-schema#Resource"]
129
+ }])
131
130
  },
132
- "unmapped @id" => {
133
- input: {
134
- "http://example.com/foo" => {"@id" => "bar"}
135
- },
136
- output: [{
137
- "http://example.com/foo" => [{"@id" => "http://example.org/bar"}]
138
- }]
131
+ "unmapped @id": {
132
+ input: %({
133
+ "http://example.com/foo": {"@id": "bar"}
134
+ }),
135
+ output: %([{
136
+ "http://example.com/foo": [{"@id": "http://example.org/bar"}]
137
+ }])
139
138
  },
140
139
  }.each do |title, params|
141
140
  it(title) {run_expand params.merge(base: "http://example.org/")}
@@ -144,54 +143,54 @@ describe JSON::LD::API do
144
143
 
145
144
  context "keyword aliasing" do
146
145
  {
147
- "@id" => {
148
- input: {
149
- "@context" => {"id" => "@id"},
150
- "id" => "",
151
- "@type" => "http://www.w3.org/2000/01/rdf-schema#Resource"
152
- },
153
- output: [{
154
- "@id" => "",
155
- "@type" =>[ "http://www.w3.org/2000/01/rdf-schema#Resource"]
156
- }]
146
+ "@id": {
147
+ input: %({
148
+ "@context": {"id": "@id"},
149
+ "id": "",
150
+ "@type": "http://www.w3.org/2000/01/rdf-schema#Resource"
151
+ }),
152
+ output: %([{
153
+ "@id": "",
154
+ "@type":[ "http://www.w3.org/2000/01/rdf-schema#Resource"]
155
+ }])
157
156
  },
158
- "@type" => {
159
- input: {
160
- "@context" => {"type" => "@type"},
161
- "type" => "http://www.w3.org/2000/01/rdf-schema#Resource",
162
- "http://example.com/foo" => {"@value" => "bar", "type" => "http://example.com/baz"}
163
- },
164
- output: [{
165
- "@type" => ["http://www.w3.org/2000/01/rdf-schema#Resource"],
166
- "http://example.com/foo" => [{"@value" => "bar", "@type" => "http://example.com/baz"}]
167
- }]
157
+ "@type": {
158
+ input: %({
159
+ "@context": {"type": "@type"},
160
+ "type": "http://www.w3.org/2000/01/rdf-schema#Resource",
161
+ "http://example.com/foo": {"@value": "bar", "type": "http://example.com/baz"}
162
+ }),
163
+ output: %([{
164
+ "@type": ["http://www.w3.org/2000/01/rdf-schema#Resource"],
165
+ "http://example.com/foo": [{"@value": "bar", "@type": "http://example.com/baz"}]
166
+ }])
168
167
  },
169
- "@language" => {
170
- input: {
171
- "@context" => {"language" => "@language"},
172
- "http://example.com/foo" => {"@value" => "bar", "language" => "baz"}
173
- },
174
- output: [{
175
- "http://example.com/foo" => [{"@value" => "bar", "@language" => "baz"}]
176
- }]
168
+ "@language": {
169
+ input: %({
170
+ "@context": {"language": "@language"},
171
+ "http://example.com/foo": {"@value": "bar", "language": "baz"}
172
+ }),
173
+ output: %([{
174
+ "http://example.com/foo": [{"@value": "bar", "@language": "baz"}]
175
+ }])
177
176
  },
178
- "@value" => {
179
- input: {
180
- "@context" => {"literal" => "@value"},
181
- "http://example.com/foo" => {"literal" => "bar"}
182
- },
183
- output: [{
184
- "http://example.com/foo" => [{"@value" => "bar"}]
185
- }]
177
+ "@value": {
178
+ input: %({
179
+ "@context": {"literal": "@value"},
180
+ "http://example.com/foo": {"literal": "bar"}
181
+ }),
182
+ output: %([{
183
+ "http://example.com/foo": [{"@value": "bar"}]
184
+ }])
186
185
  },
187
- "@list" => {
188
- input: {
189
- "@context" => {"list" => "@list"},
190
- "http://example.com/foo" => {"list" => ["bar"]}
191
- },
192
- output: [{
193
- "http://example.com/foo" => [{"@list" => [{"@value" => "bar"}]}]
194
- }]
186
+ "@list": {
187
+ input: %({
188
+ "@context": {"list": "@list"},
189
+ "http://example.com/foo": {"list": ["bar"]}
190
+ }),
191
+ output: %([{
192
+ "http://example.com/foo": [{"@list": [{"@value": "bar"}]}]
193
+ }])
195
194
  },
196
195
  }.each do |title, params|
197
196
  it(title) {run_expand params}
@@ -200,54 +199,158 @@ describe JSON::LD::API do
200
199
 
201
200
  context "native types" do
202
201
  {
203
- "true" => {
204
- input: {
205
- "@context" => {"e" => "http://example.org/vocab#"},
206
- "e:bool" => true
207
- },
208
- output: [{
209
- "http://example.org/vocab#bool" => [{"@value" => true}]
210
- }]
202
+ "true": {
203
+ input: %({
204
+ "@context": {"e": "http://example.org/vocab#"},
205
+ "e:bool": true
206
+ }),
207
+ output: %([{
208
+ "http://example.org/vocab#bool": [{"@value": true}]
209
+ }])
211
210
  },
212
- "false" => {
213
- input: {
214
- "@context" => {"e" => "http://example.org/vocab#"},
215
- "e:bool" => false
216
- },
217
- output: [{
218
- "http://example.org/vocab#bool" => [{"@value" => false}]
219
- }]
211
+ "false": {
212
+ input: %({
213
+ "@context": {"e": "http://example.org/vocab#"},
214
+ "e:bool": false
215
+ }),
216
+ output: %([{
217
+ "http://example.org/vocab#bool": [{"@value": false}]
218
+ }])
220
219
  },
221
- "double" => {
222
- input: {
223
- "@context" => {"e" => "http://example.org/vocab#"},
224
- "e:double" => 1.23
225
- },
226
- output: [{
227
- "http://example.org/vocab#double" => [{"@value" => 1.23}]
228
- }]
220
+ "double": {
221
+ input: %({
222
+ "@context": {"e": "http://example.org/vocab#"},
223
+ "e:double": 1.23
224
+ }),
225
+ output: %([{
226
+ "http://example.org/vocab#double": [{"@value": 1.23}]
227
+ }])
229
228
  },
230
- "double-zero" => {
231
- input: {
232
- "@context" => {"e" => "http://example.org/vocab#"},
233
- "e:double-zero" => 0.0e0
234
- },
235
- output: [{
236
- "http://example.org/vocab#double-zero" => [{"@value" => 0.0e0}]
237
- }]
229
+ "double-zero": {
230
+ input: %({
231
+ "@context": {"e": "http://example.org/vocab#"},
232
+ "e:double-zero": 0.0e0
233
+ }),
234
+ output: %([{
235
+ "http://example.org/vocab#double-zero": [{"@value": 0.0e0}]
236
+ }])
238
237
  },
239
- "integer" => {
240
- input: {
241
- "@context" => {"e" => "http://example.org/vocab#"},
242
- "e:integer" => 123
243
- },
244
- output: [{
245
- "http://example.org/vocab#integer" => [{"@value" => 123}]
246
- }]
238
+ "integer": {
239
+ input: %({
240
+ "@context": {"e": "http://example.org/vocab#"},
241
+ "e:integer": 123
242
+ }),
243
+ output: %([{
244
+ "http://example.org/vocab#integer": [{"@value": 123}]
245
+ }])
247
246
  },
248
247
  }.each do |title, params|
249
248
  it(title) {run_expand params}
250
249
  end
250
+
251
+ context "with @type: @id" do
252
+ {
253
+ "true": {
254
+ input: %({
255
+ "@context": {"e": {"@id": "http://example.org/vocab#bool", "@type": "@id"}},
256
+ "e": true
257
+ }),
258
+ output:%( [{
259
+ "http://example.org/vocab#bool": [{"@value": true}]
260
+ }])
261
+ },
262
+ "false": {
263
+ input: %({
264
+ "@context": {"e": {"@id": "http://example.org/vocab#bool", "@type": "@id"}},
265
+ "e": false
266
+ }),
267
+ output: %([{
268
+ "http://example.org/vocab#bool": [{"@value": false}]
269
+ }])
270
+ },
271
+ "double": {
272
+ input: %({
273
+ "@context": {"e": {"@id": "http://example.org/vocab#double", "@type": "@id"}},
274
+ "e": 1.23
275
+ }),
276
+ output: %([{
277
+ "http://example.org/vocab#double": [{"@value": 1.23}]
278
+ }])
279
+ },
280
+ "double-zero": {
281
+ input: %({
282
+ "@context": {"e": {"@id": "http://example.org/vocab#double", "@type": "@id"}},
283
+ "e": 0.0e0
284
+ }),
285
+ output: %([{
286
+ "http://example.org/vocab#double": [{"@value": 0.0e0}]
287
+ }])
288
+ },
289
+ "integer": {
290
+ input: %({
291
+ "@context": {"e": {"@id": "http://example.org/vocab#integer", "@type": "@id"}},
292
+ "e": 123
293
+ }),
294
+ output: %([{
295
+ "http://example.org/vocab#integer": [{"@value": 123}]
296
+ }])
297
+ },
298
+ }.each do |title, params|
299
+ it(title) {run_expand params}
300
+ end
301
+ end
302
+
303
+ context "with @type: @vocab" do
304
+ {
305
+ "true": {
306
+ input: %({
307
+ "@context": {"e": {"@id": "http://example.org/vocab#bool", "@type": "@vocab"}},
308
+ "e": true
309
+ }),
310
+ output:%( [{
311
+ "http://example.org/vocab#bool": [{"@value": true}]
312
+ }])
313
+ },
314
+ "false": {
315
+ input: %({
316
+ "@context": {"e": {"@id": "http://example.org/vocab#bool", "@type": "@vocab"}},
317
+ "e": false
318
+ }),
319
+ output: %([{
320
+ "http://example.org/vocab#bool": [{"@value": false}]
321
+ }])
322
+ },
323
+ "double": {
324
+ input: %({
325
+ "@context": {"e": {"@id": "http://example.org/vocab#double", "@type": "@vocab"}},
326
+ "e": 1.23
327
+ }),
328
+ output: %([{
329
+ "http://example.org/vocab#double": [{"@value": 1.23}]
330
+ }])
331
+ },
332
+ "double-zero": {
333
+ input: %({
334
+ "@context": {"e": {"@id": "http://example.org/vocab#double", "@type": "@vocab"}},
335
+ "e": 0.0e0
336
+ }),
337
+ output: %([{
338
+ "http://example.org/vocab#double": [{"@value": 0.0e0}]
339
+ }])
340
+ },
341
+ "integer": {
342
+ input: %({
343
+ "@context": {"e": {"@id": "http://example.org/vocab#integer", "@type": "@vocab"}},
344
+ "e": 123
345
+ }),
346
+ output: %([{
347
+ "http://example.org/vocab#integer": [{"@value": 123}]
348
+ }])
349
+ },
350
+ }.each do |title, params|
351
+ it(title) {run_expand params}
352
+ end
353
+ end
251
354
  end
252
355
 
253
356
  context "coerced typed values" do
@@ -900,6 +1003,205 @@ describe JSON::LD::API do
900
1003
  end
901
1004
  end
902
1005
 
1006
+ context "@container: @graph" do
1007
+ {
1008
+ "Creates a graph object given a value" => {
1009
+ input: %({
1010
+ "@context": {
1011
+ "@vocab": "http://example.org/",
1012
+ "input": {"@container": "@graph"}
1013
+ },
1014
+ "input": {
1015
+ "value": "x"
1016
+ }
1017
+ }),
1018
+ output: %([{
1019
+ "http://example.org/input": [{
1020
+ "@graph": [{
1021
+ "http://example.org/value": [{"@value": "x"}]
1022
+ }]
1023
+ }]
1024
+ }])
1025
+ },
1026
+ "Creates a graph object within an array given a value" => {
1027
+ input: %({
1028
+ "@context": {
1029
+ "@vocab": "http://example.org/",
1030
+ "input": {"@container": ["@graph", "@set"]}
1031
+ },
1032
+ "input": {
1033
+ "value": "x"
1034
+ }
1035
+ }),
1036
+ output: %([{
1037
+ "http://example.org/input": [{
1038
+ "@graph": [{
1039
+ "http://example.org/value": [{"@value": "x"}]
1040
+ }]
1041
+ }]
1042
+ }])
1043
+ },
1044
+ "Does not create an graph object if value is a graph" => {
1045
+ input: %({
1046
+ "@context": {
1047
+ "@vocab": "http://example.org/",
1048
+ "input": {"@container": "@graph"}
1049
+ },
1050
+ "input": {
1051
+ "@graph": {
1052
+ "value": "x"
1053
+ }
1054
+ }
1055
+ }),
1056
+ output: %([{
1057
+ "http://example.org/input": [{
1058
+ "@graph": [{
1059
+ "http://example.org/value": [{"@value": "x"}]
1060
+ }]
1061
+ }]
1062
+ }])
1063
+ },
1064
+ }.each do |title, params|
1065
+ it(title) {run_expand({processingMode: "json-ld-1.1"}.merge(params))}
1066
+ end
1067
+
1068
+ context "+ @index" do
1069
+ {
1070
+ "Creates a graph object given an indexed value" => {
1071
+ input: %({
1072
+ "@context": {
1073
+ "@vocab": "http://example.org/",
1074
+ "input": {"@container": ["@graph", "@index"]}
1075
+ },
1076
+ "input": {
1077
+ "g1": {"value": "x"}
1078
+ }
1079
+ }),
1080
+ output: %([{
1081
+ "http://example.org/input": [{
1082
+ "@index": "g1",
1083
+ "@graph": [{
1084
+ "http://example.org/value": [{"@value": "x"}]
1085
+ }]
1086
+ }]
1087
+ }])
1088
+ },
1089
+ "Creates a graph object given an indexed value with @set" => {
1090
+ input: %({
1091
+ "@context": {
1092
+ "@vocab": "http://example.org/",
1093
+ "input": {"@container": ["@graph", "@index", "@set"]}
1094
+ },
1095
+ "input": {
1096
+ "g1": {"value": "x"}
1097
+ }
1098
+ }),
1099
+ output: %([{
1100
+ "http://example.org/input": [{
1101
+ "@index": "g1",
1102
+ "@graph": [{
1103
+ "http://example.org/value": [{"@value": "x"}]
1104
+ }]
1105
+ }]
1106
+ }])
1107
+ },
1108
+ "Does not create a new graph object if indexed value is already a graph object" => {
1109
+ input: %({
1110
+ "@context": {
1111
+ "@vocab": "http://example.org/",
1112
+ "input": {"@container": ["@graph", "@index"]}
1113
+ },
1114
+ "input": {
1115
+ "g1": {
1116
+ "@graph": {
1117
+ "value": "x"
1118
+ }
1119
+ }
1120
+ }
1121
+ }),
1122
+ output: %([{
1123
+ "http://example.org/input": [{
1124
+ "@index": "g1",
1125
+ "@graph": [{
1126
+ "http://example.org/value": [{"@value": "x"}]
1127
+ }]
1128
+ }]
1129
+ }])
1130
+ },
1131
+ }.each do |title, params|
1132
+ it(title) {run_expand({processingMode: "json-ld-1.1"}.merge(params))}
1133
+ end
1134
+ end
1135
+
1136
+ context "+ @id" do
1137
+ {
1138
+ "Creates a graph object given an indexed value" => {
1139
+ input: %({
1140
+ "@context": {
1141
+ "@vocab": "http://example.org/",
1142
+ "input": {"@container": ["@graph", "@id"]}
1143
+ },
1144
+ "input": {
1145
+ "http://example.com/g1": {"value": "x"}
1146
+ }
1147
+ }),
1148
+ output: %([{
1149
+ "http://example.org/input": [{
1150
+ "@id": "http://example.com/g1",
1151
+ "@graph": [{
1152
+ "http://example.org/value": [{"@value": "x"}]
1153
+ }]
1154
+ }]
1155
+ }])
1156
+ },
1157
+ "Creates a graph object given an indexed value with @set" => {
1158
+ input: %({
1159
+ "@context": {
1160
+ "@vocab": "http://example.org/",
1161
+ "input": {"@container": ["@graph", "@id", "@set"]}
1162
+ },
1163
+ "input": {
1164
+ "http://example.com/g1": {"value": "x"}
1165
+ }
1166
+ }),
1167
+ output: %([{
1168
+ "http://example.org/input": [{
1169
+ "@id": "http://example.com/g1",
1170
+ "@graph": [{
1171
+ "http://example.org/value": [{"@value": "x"}]
1172
+ }]
1173
+ }]
1174
+ }])
1175
+ },
1176
+ "Does not create a new graph object if indexed value is already a graph object" => {
1177
+ input: %({
1178
+ "@context": {
1179
+ "@vocab": "http://example.org/",
1180
+ "input": {"@container": ["@graph", "@id"]}
1181
+ },
1182
+ "input": {
1183
+ "http://example.com/g1": {
1184
+ "@graph": {
1185
+ "value": "x"
1186
+ }
1187
+ }
1188
+ }
1189
+ }),
1190
+ output: %([{
1191
+ "http://example.org/input": [{
1192
+ "@id": "http://example.com/g1",
1193
+ "@graph": [{
1194
+ "http://example.org/value": [{"@value": "x"}]
1195
+ }]
1196
+ }]
1197
+ }])
1198
+ },
1199
+ }.each do |title, params|
1200
+ it(title) {run_expand({processingMode: "json-ld-1.1"}.merge(params))}
1201
+ end
1202
+ end
1203
+ end
1204
+
903
1205
  context "@nest" do
904
1206
  {
905
1207
  "Expands input using @nest" => {