json-ld 3.2.4 → 3.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.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/VERSION +1 -1
  4. data/lib/json/ld/api.rb +807 -771
  5. data/lib/json/ld/compact.rb +304 -304
  6. data/lib/json/ld/conneg.rb +179 -161
  7. data/lib/json/ld/context.rb +2079 -1913
  8. data/lib/json/ld/expand.rb +745 -666
  9. data/lib/json/ld/extensions.rb +14 -13
  10. data/lib/json/ld/flatten.rb +257 -247
  11. data/lib/json/ld/format.rb +202 -194
  12. data/lib/json/ld/frame.rb +525 -502
  13. data/lib/json/ld/from_rdf.rb +223 -204
  14. data/lib/json/ld/html/nokogiri.rb +123 -121
  15. data/lib/json/ld/html/rexml.rb +151 -147
  16. data/lib/json/ld/reader.rb +107 -100
  17. data/lib/json/ld/resource.rb +224 -205
  18. data/lib/json/ld/streaming_reader.rb +574 -507
  19. data/lib/json/ld/streaming_writer.rb +93 -92
  20. data/lib/json/ld/to_rdf.rb +171 -169
  21. data/lib/json/ld/utils.rb +270 -264
  22. data/lib/json/ld/version.rb +24 -14
  23. data/lib/json/ld/writer.rb +334 -311
  24. data/lib/json/ld.rb +103 -96
  25. metadata +56 -225
  26. data/spec/api_spec.rb +0 -132
  27. data/spec/compact_spec.rb +0 -3482
  28. data/spec/conneg_spec.rb +0 -373
  29. data/spec/context_spec.rb +0 -2056
  30. data/spec/expand_spec.rb +0 -4496
  31. data/spec/flatten_spec.rb +0 -1203
  32. data/spec/format_spec.rb +0 -115
  33. data/spec/frame_spec.rb +0 -2541
  34. data/spec/from_rdf_spec.rb +0 -1072
  35. data/spec/matchers.rb +0 -20
  36. data/spec/rdfstar_spec.rb +0 -25
  37. data/spec/reader_spec.rb +0 -883
  38. data/spec/resource_spec.rb +0 -76
  39. data/spec/spec_helper.rb +0 -281
  40. data/spec/streaming_reader_spec.rb +0 -237
  41. data/spec/streaming_writer_spec.rb +0 -145
  42. data/spec/suite_compact_spec.rb +0 -22
  43. data/spec/suite_expand_spec.rb +0 -36
  44. data/spec/suite_flatten_spec.rb +0 -34
  45. data/spec/suite_frame_spec.rb +0 -29
  46. data/spec/suite_from_rdf_spec.rb +0 -22
  47. data/spec/suite_helper.rb +0 -411
  48. data/spec/suite_html_spec.rb +0 -22
  49. data/spec/suite_http_spec.rb +0 -35
  50. data/spec/suite_remote_doc_spec.rb +0 -22
  51. data/spec/suite_to_rdf_spec.rb +0 -30
  52. data/spec/support/extensions.rb +0 -44
  53. data/spec/test-files/test-1-compacted.jsonld +0 -10
  54. data/spec/test-files/test-1-context.jsonld +0 -7
  55. data/spec/test-files/test-1-expanded.jsonld +0 -5
  56. data/spec/test-files/test-1-input.jsonld +0 -10
  57. data/spec/test-files/test-1-rdf.ttl +0 -8
  58. data/spec/test-files/test-2-compacted.jsonld +0 -20
  59. data/spec/test-files/test-2-context.jsonld +0 -7
  60. data/spec/test-files/test-2-expanded.jsonld +0 -16
  61. data/spec/test-files/test-2-input.jsonld +0 -20
  62. data/spec/test-files/test-2-rdf.ttl +0 -14
  63. data/spec/test-files/test-3-compacted.jsonld +0 -11
  64. data/spec/test-files/test-3-context.jsonld +0 -8
  65. data/spec/test-files/test-3-expanded.jsonld +0 -10
  66. data/spec/test-files/test-3-input.jsonld +0 -11
  67. data/spec/test-files/test-3-rdf.ttl +0 -8
  68. data/spec/test-files/test-4-compacted.jsonld +0 -10
  69. data/spec/test-files/test-4-context.jsonld +0 -7
  70. data/spec/test-files/test-4-expanded.jsonld +0 -6
  71. data/spec/test-files/test-4-input.jsonld +0 -10
  72. data/spec/test-files/test-4-rdf.ttl +0 -5
  73. data/spec/test-files/test-5-compacted.jsonld +0 -13
  74. data/spec/test-files/test-5-context.jsonld +0 -7
  75. data/spec/test-files/test-5-expanded.jsonld +0 -9
  76. data/spec/test-files/test-5-input.jsonld +0 -13
  77. data/spec/test-files/test-5-rdf.ttl +0 -7
  78. data/spec/test-files/test-6-compacted.jsonld +0 -10
  79. data/spec/test-files/test-6-context.jsonld +0 -7
  80. data/spec/test-files/test-6-expanded.jsonld +0 -10
  81. data/spec/test-files/test-6-input.jsonld +0 -10
  82. data/spec/test-files/test-6-rdf.ttl +0 -6
  83. data/spec/test-files/test-7-compacted.jsonld +0 -23
  84. data/spec/test-files/test-7-context.jsonld +0 -4
  85. data/spec/test-files/test-7-expanded.jsonld +0 -20
  86. data/spec/test-files/test-7-input.jsonld +0 -23
  87. data/spec/test-files/test-7-rdf.ttl +0 -14
  88. data/spec/test-files/test-8-compacted.jsonld +0 -34
  89. data/spec/test-files/test-8-context.jsonld +0 -11
  90. data/spec/test-files/test-8-expanded.jsonld +0 -24
  91. data/spec/test-files/test-8-frame.jsonld +0 -18
  92. data/spec/test-files/test-8-framed.jsonld +0 -25
  93. data/spec/test-files/test-8-input.jsonld +0 -30
  94. data/spec/test-files/test-8-rdf.ttl +0 -15
  95. data/spec/test-files/test-9-compacted.jsonld +0 -20
  96. data/spec/test-files/test-9-context.jsonld +0 -13
  97. data/spec/test-files/test-9-expanded.jsonld +0 -14
  98. data/spec/test-files/test-9-input.jsonld +0 -12
  99. data/spec/to_rdf_spec.rb +0 -1684
  100. data/spec/writer_spec.rb +0 -427
data/spec/context_spec.rb DELETED
@@ -1,2056 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
- require 'rdf/xsd'
4
- require 'rdf/spec/reader'
5
-
6
- # Add for testing
7
- class JSON::LD::Context
8
- # Retrieve type mappings
9
- def coercions
10
- term_definitions.inject({}) do |memo, (t,td)|
11
- memo[t] = td.type_mapping
12
- memo
13
- end
14
- end
15
-
16
- def containers
17
- term_definitions.inject({}) do |memo, (t,td)|
18
- memo[t] = td.container_mapping
19
- memo
20
- end
21
- end
22
- end
23
-
24
- describe JSON::LD::Context do
25
- let(:logger) {RDF::Spec.logger}
26
- let(:context) {JSON::LD::Context.new(logger: logger, validate: true, processingMode: "json-ld-1.1", compactToRelative: true)}
27
- let(:remote_doc) do
28
- JSON::LD::API::RemoteDocument.new(%q({
29
- "@context": {
30
- "xsd": "http://www.w3.org/2001/XMLSchema#",
31
- "name": "http://xmlns.com/foaf/0.1/name",
32
- "homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id"},
33
- "avatar": {"@id": "http://xmlns.com/foaf/0.1/avatar", "@type": "@id"}
34
- }
35
- }),
36
- documentUrl: "http://example.com/context",
37
- contentType: "application/ld+json")
38
- end
39
- subject {context}
40
-
41
- describe ".parse" do
42
- let(:ctx) {[
43
- {"foo" => "http://example.com/foo"},
44
- {"bar" => "foo"}
45
- ]}
46
-
47
- it "merges definitions from each context" do
48
- ec = described_class.parse(ctx)
49
- expect(ec.send(:mappings)).to produce({
50
- "foo" => "http://example.com/foo",
51
- "bar" => "http://example.com/foo"
52
- }, logger)
53
- end
54
- end
55
-
56
- describe "#parse" do
57
- context "remote" do
58
-
59
- it "fails given a missing remote @context" do
60
- JSON::LD::Context.instance_variable_set(:@cache, nil)
61
- expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_raise(IOError)
62
- expect {subject.parse("http://example.com/context")}.to raise_error(JSON::LD::JsonLdError::LoadingRemoteContextFailed, %r{http://example.com/context})
63
- end
64
-
65
- it "creates mappings" do
66
- expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
67
- ec = subject.parse("http://example.com/context")
68
- expect(ec.send(:mappings)).to produce({
69
- "xsd" => "http://www.w3.org/2001/XMLSchema#",
70
- "name" => "http://xmlns.com/foaf/0.1/name",
71
- "homepage" => "http://xmlns.com/foaf/0.1/homepage",
72
- "avatar" => "http://xmlns.com/foaf/0.1/avatar"
73
- }, logger)
74
- end
75
-
76
- it "retrieves and parses a remote context document in HTML using the context profile" do
77
- remote_doc =
78
- JSON::LD::API::RemoteDocument.new(%q(
79
- <html><head>
80
- <script>Not This</script>
81
- <script type="application/ld+json">
82
- {
83
- "@context": {
84
- "homepage": {"@id": "http://example.com/this-would-be-wrong", "@type": "@id"},
85
- "avatar": {"@id": "http://example.com/this-would-be-wrong", "@type": "@id"}
86
- }
87
- }
88
- </script>
89
- <script type="application/ld+json;profile=http://www.w3.org/ns/json-ld#context">
90
- {
91
- "@context": {
92
- "xsd": "http://www.w3.org/2001/XMLSchema#",
93
- "name": "http://xmlns.com/foaf/0.1/name",
94
- "homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id"},
95
- "avatar": {"@id": "http://xmlns.com/foaf/0.1/avatar", "@type": "@id"}
96
- }
97
- }
98
- </script>
99
- <script type="application/ld+json;profile=http://www.w3.org/ns/json-ld#context">
100
- {
101
- "@context": {
102
- "homepage": {"@id": "http://example.com/this-would-also-be-wrong", "@type": "@id"},
103
- "avatar": {"@id": "http://example.com/this-would-also-be-wrong", "@type": "@id"}
104
- }
105
- }
106
- </script>
107
- </head></html>
108
- ),
109
- documentUrl: "http://example.com/context",
110
- contentType: "text/html")
111
-
112
- JSON::LD::Context.instance_variable_set(:@cache, nil)
113
- expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
114
- ec = subject.parse("http://example.com/context")
115
- expect(ec.send(:mappings)).to produce({
116
- "xsd" => "http://www.w3.org/2001/XMLSchema#",
117
- "name" => "http://xmlns.com/foaf/0.1/name",
118
- "homepage" => "http://xmlns.com/foaf/0.1/homepage",
119
- "avatar" => "http://xmlns.com/foaf/0.1/avatar"
120
- }, logger)
121
- end
122
-
123
- it "retrieves and parses a remote context document in HTML" do
124
- remote_doc =
125
- JSON::LD::API::RemoteDocument.new(%q(
126
- <html><head>
127
- <script>Not This</script>
128
- <script type="application/ld+json">
129
- {
130
- "@context": {
131
- "xsd": "http://www.w3.org/2001/XMLSchema#",
132
- "name": "http://xmlns.com/foaf/0.1/name",
133
- "homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id"},
134
- "avatar": {"@id": "http://xmlns.com/foaf/0.1/avatar", "@type": "@id"}
135
- }
136
- }
137
- </script>
138
- <script type="application/ld+json">
139
- {
140
- "@context": {
141
- "homepage": {"@id": "http://example.com/this-would-also-be-wrong", "@type": "@id"},
142
- "avatar": {"@id": "http://example.com/this-would-also-be-wrong", "@type": "@id"}
143
- }
144
- }
145
- </script>
146
- </head></html>
147
- ),
148
- documentUrl: "http://example.com/context",
149
- contentType: "text/html")
150
- JSON::LD::Context.instance_variable_set(:@cache, nil)
151
- expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
152
- ec = subject.parse("http://example.com/context")
153
- expect(ec.send(:mappings)).to produce({
154
- "xsd" => "http://www.w3.org/2001/XMLSchema#",
155
- "name" => "http://xmlns.com/foaf/0.1/name",
156
- "homepage" => "http://xmlns.com/foaf/0.1/homepage",
157
- "avatar" => "http://xmlns.com/foaf/0.1/avatar"
158
- }, logger)
159
- end
160
-
161
- it "notes non-existing @context" do
162
- expect {subject.parse(StringIO.new("{}"))}.to raise_error(JSON::LD::JsonLdError::InvalidRemoteContext)
163
- end
164
-
165
- it "parses a referenced context at a relative URI" do
166
- JSON::LD::Context.instance_variable_set(:@cache, nil)
167
- rd1 = JSON::LD::API::RemoteDocument.new(%({"@context": "context"}), base_uri: "http://example.com/c1")
168
- expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/c1", anything).and_yield(rd1)
169
- expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
170
- ec = subject.parse("http://example.com/c1")
171
- expect(ec.send(:mappings)).to produce({
172
- "xsd" => "http://www.w3.org/2001/XMLSchema#",
173
- "name" => "http://xmlns.com/foaf/0.1/name",
174
- "homepage" => "http://xmlns.com/foaf/0.1/homepage",
175
- "avatar" => "http://xmlns.com/foaf/0.1/avatar"
176
- }, logger)
177
- end
178
-
179
- context "remote with local mappings" do
180
- let(:ctx) {["http://example.com/context", {"integer" => "xsd:integer"}]}
181
- before {JSON::LD::Context.instance_variable_set(:@cache, nil)}
182
- it "retrieves and parses a remote context document" do
183
- expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
184
- ec = subject.parse(ctx)
185
- expect(ec.send(:mappings)).to produce({
186
- "xsd" => "http://www.w3.org/2001/XMLSchema#",
187
- "name" => "http://xmlns.com/foaf/0.1/name",
188
- "homepage" => "http://xmlns.com/foaf/0.1/homepage",
189
- "avatar" => "http://xmlns.com/foaf/0.1/avatar",
190
- "integer" => "http://www.w3.org/2001/XMLSchema#integer"
191
- }, logger)
192
- end
193
- end
194
-
195
- context "pre-loaded remote" do
196
- let(:ctx) {"http://example.com/preloaded"}
197
- before(:all) {
198
- JSON::LD::Context.add_preloaded("http://example.com/preloaded",
199
- JSON::LD::Context.parse({'foo' => "http://example.com/"})
200
- )
201
- JSON::LD::Context.alias_preloaded("https://example.com/preloaded", "http://example.com/preloaded")
202
- }
203
- after(:all) {JSON::LD::Context.instance_variable_set(:@cache, nil)}
204
-
205
- it "does not load referenced context" do
206
- expect(JSON::LD::API).not_to receive(:documentLoader).with(ctx, anything)
207
- subject.parse(ctx)
208
- end
209
-
210
- it "does not load aliased context" do
211
- expect(JSON::LD::API).not_to receive(:documentLoader).with(ctx.sub('http', 'https'), anything)
212
- subject.parse(ctx.sub('http', 'https'))
213
- end
214
-
215
- it "uses loaded context" do
216
- ec = subject.parse(ctx)
217
- expect(ec.send(:mappings)).to produce({
218
- "foo" => "http://example.com/"
219
- }, logger)
220
- end
221
-
222
- it "uses aliased context" do
223
- ec = subject.parse(ctx.sub('http', 'https'))
224
- expect(ec.send(:mappings)).to produce({
225
- "foo" => "http://example.com/"
226
- }, logger)
227
- end
228
- end
229
- end
230
-
231
- context "Array" do
232
- let(:ctx) {[
233
- {"foo" => "http://example.com/foo"},
234
- {"bar" => "foo"}
235
- ]}
236
-
237
- it "merges definitions from each context" do
238
- ec = subject.parse(ctx)
239
- expect(ec.send(:mappings)).to produce({
240
- "foo" => "http://example.com/foo",
241
- "bar" => "http://example.com/foo"
242
- }, logger)
243
- end
244
-
245
- it "merges definitions from remote contexts" do
246
- JSON::LD::Context.instance_variable_set(:@cache, nil)
247
- expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
248
- rd2 = JSON::LD::API::RemoteDocument.new(%q({
249
- "@context": {
250
- "title": {"@id": "http://purl.org/dc/terms/title"}
251
- }
252
- }), base_uri: "http://example.com/c2")
253
- expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/c2", anything).and_yield(rd2)
254
- ec = subject.parse(%w(http://example.com/context http://example.com/c2))
255
- expect(ec.send(:mappings)).to produce({
256
- "xsd" => "http://www.w3.org/2001/XMLSchema#",
257
- "name" => "http://xmlns.com/foaf/0.1/name",
258
- "homepage" => "http://xmlns.com/foaf/0.1/homepage",
259
- "avatar" => "http://xmlns.com/foaf/0.1/avatar",
260
- "title" => "http://purl.org/dc/terms/title"
261
- }, logger)
262
- end
263
- end
264
-
265
- context "Hash" do
266
- it "extracts @language" do
267
- expect(subject.parse({
268
- "@language" => "en"
269
- }).default_language).to produce("en", logger)
270
- end
271
-
272
- it "extracts @vocab" do
273
- expect(subject.parse({
274
- "@vocab" => "http://schema.org/"
275
- }).vocab).to produce("http://schema.org/", logger)
276
- end
277
-
278
- it "maps term with IRI value" do
279
- expect(subject.parse({
280
- "foo" => "http://example.com/"
281
- }).send(:mappings)).to produce({
282
- "foo" => "http://example.com/"
283
- }, logger)
284
- end
285
-
286
- it "maps term with blank node value (with deprecation)" do
287
- expect do
288
- expect(subject.parse({
289
- "foo" => "_:bn"
290
- }).send(:mappings)).to produce({
291
- "foo" => RDF::Node("bn")
292
- }, logger)
293
- end.to write("[DEPRECATION]").to(:error)
294
- end
295
-
296
- it "maps term with @id" do
297
- expect(subject.parse({
298
- "foo" => {"@id" => "http://example.com/"}
299
- }).send(:mappings)).to produce({
300
- "foo" => "http://example.com/"
301
- }, logger)
302
- end
303
-
304
- it "maps term with blank node @id (with deprecation)" do
305
- expect do
306
- expect(subject.parse({
307
- "foo" => {"@id" => "_:bn"}
308
- }).send(:mappings)).to produce({
309
- "foo" => RDF::Node("bn")
310
- }, logger)
311
- end.to write("[DEPRECATION]").to(:error)
312
- end
313
-
314
- it "warns and ignores keyword-like term" do
315
- expect do
316
- expect(subject.parse({
317
- "@foo" => {"@id" => "http://example.org/foo"}
318
- }).send(:mappings)).to produce({}, logger)
319
- end.to write("Terms beginning with '@' are reserved").to(:error)
320
- end
321
-
322
- it "maps '@' as a term" do
323
- expect do
324
- expect(subject.parse({
325
- "@" => {"@id" => "http://example.org/@"}
326
- }).send(:mappings)).to produce({
327
- "@" => "http://example.org/@"
328
- }, logger)
329
- end.not_to write.to(:error)
330
- end
331
-
332
- it "maps '@foo.bar' as a term" do
333
- expect do
334
- expect(subject.parse({
335
- "@foo.bar" => {"@id" => "http://example.org/foo.bar"}
336
- }).send(:mappings)).to produce({
337
- "@foo.bar" => "http://example.org/foo.bar"
338
- }, logger)
339
- end.not_to write.to(:error)
340
- end
341
-
342
- it "associates @list container mapping with term" do
343
- expect(subject.parse({
344
- "foo" => {"@id" => "http://example.com/", "@container" => "@list"}
345
- }).containers).to produce({
346
- "foo" => Set["@list"]
347
- }, logger)
348
- end
349
-
350
- it "associates @type container mapping with term" do
351
- expect(subject.parse({
352
- "foo" => {"@id" => "http://example.com/", "@container" => "@type"}
353
- }).containers).to produce({
354
- "foo" => Set["@type"]
355
- }, logger)
356
- end
357
-
358
- it "associates @id container mapping with term" do
359
- expect(subject.parse({
360
- "foo" => {"@id" => "http://example.com/", "@container" => "@id"}
361
- }).containers).to produce({
362
- "foo" => Set["@id"]
363
- }, logger)
364
- end
365
-
366
- it "associates @id type mapping with term" do
367
- expect(subject.parse({
368
- "foo" => {"@id" => "http://example.com/", "@type" => "@id"}
369
- }).coercions).to produce({
370
- "foo" => "@id"
371
- }, logger)
372
- end
373
-
374
- it "associates @json type mapping with term" do
375
- expect(subject.parse({
376
- "foo" => {"@id" => "http://example.com/", "@type" => "@json"}
377
- }).coercions).to produce({
378
- "foo" => "@json"
379
- }, logger)
380
- end
381
-
382
- it "associates type mapping with term" do
383
- expect(subject.parse({
384
- "foo" => {"@id" => "http://example.com/", "@type" => RDF::XSD.string.to_s}
385
- }).coercions).to produce({
386
- "foo" => RDF::XSD.string
387
- }, logger)
388
- end
389
-
390
- it "associates language mapping with term" do
391
- expect(subject.parse({
392
- "foo" => {"@id" => "http://example.com/", "@language" => "en"}
393
- }).send(:languages)).to produce({
394
- "foo" => "en"
395
- }, logger)
396
- end
397
-
398
- it "expands chains of term definition/use with string values" do
399
- expect(subject.parse({
400
- "foo" => "bar",
401
- "bar" => "baz",
402
- "baz" => "http://example.com/"
403
- }).send(:mappings)).to produce({
404
- "foo" => "http://example.com/",
405
- "bar" => "http://example.com/",
406
- "baz" => "http://example.com/"
407
- }, logger)
408
- end
409
-
410
- it "expands terms using @vocab" do
411
- expect(subject.parse({
412
- "foo" => "bar",
413
- "@vocab" => "http://example.com/"
414
- }).send(:mappings)).to produce({
415
- "foo" => "http://example.com/bar"
416
- }, logger)
417
- end
418
-
419
- context "with null" do
420
- it "removes @language if set to null" do
421
- expect(subject.parse([
422
- {
423
- "@language" => "en"
424
- },
425
- {
426
- "@language" => nil
427
- }
428
- ]).default_language).to produce(nil, logger)
429
- end
430
-
431
- it "removes @vocab if set to null" do
432
- expect(subject.parse([
433
- {
434
- "@vocab" => "http://schema.org/"
435
- },
436
- {
437
- "@vocab" => nil
438
- }
439
- ]).vocab).to produce(nil, logger)
440
- end
441
-
442
- it "removes term if set to null with @vocab" do
443
- expect(subject.parse([
444
- {
445
- "@vocab" => "http://schema.org/",
446
- "term" => nil
447
- }
448
- ]).send(:mappings)).to produce({"term" => nil}, logger)
449
- end
450
-
451
- it "loads initial context" do
452
- init_ec = JSON::LD::Context.new
453
- nil_ec = subject.parse(nil)
454
- expect(nil_ec.default_language).to eq init_ec.default_language
455
- expect(nil_ec.send(:languages)).to eq init_ec.send(:languages)
456
- expect(nil_ec.send(:mappings)).to eq init_ec.send(:mappings)
457
- expect(nil_ec.coercions).to eq init_ec.coercions
458
- expect(nil_ec.containers).to eq init_ec.containers
459
- end
460
-
461
- it "removes a term definition" do
462
- expect(subject.parse({"name" => nil}).send(:mapping, "name")).to be_nil
463
- end
464
- end
465
-
466
-
467
- context "@propagate" do
468
- it "generates an InvalidPropagateValue error if not a boolean" do
469
- expect {subject.parse({'@version' => 1.1, '@propagate' => "String"})}.to raise_error(JSON::LD::JsonLdError::InvalidPropagateValue)
470
- end
471
- end
472
-
473
- context "@import" do
474
- before(:each) {JSON::LD::Context.instance_variable_set(:@cache, nil)}
475
- it "generates an InvalidImportValue error if not a string" do
476
- expect {subject.parse({'@version' => 1.1, '@import' => true})}.to raise_error(JSON::LD::JsonLdError::InvalidImportValue)
477
- end
478
-
479
- it "retrieves remote context" do
480
- expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
481
- ec = subject.parse(JSON.parse %({
482
- "@version": 1.1,
483
- "@import": "http://example.com/context"
484
- }))
485
- expect(ec.term_definitions).to include("avatar")
486
- end
487
- end
488
- end
489
-
490
- describe "Syntax Errors" do
491
- {
492
- "malformed JSON" => StringIO.new(%q({"@context": {"foo" "http://malformed/"})),
493
- "no @id, @type, or @container" => {"foo" => {}},
494
- "value as array" => {"foo" => []},
495
- "@id as object" => {"foo" => {"@id" => {}}},
496
- "@id as array of object" => {"foo" => {"@id" => [{}]}},
497
- "@id as array of null" => {"foo" => {"@id" => [nil]}},
498
- "@type as object" => {"foo" => {"@type" => {}}},
499
- "@type as array" => {"foo" => {"@type" => []}},
500
- "@type as @list" => {"foo" => {"@type" => "@list"}},
501
- "@type as @none" => {"@version" => 1.1, "foo" => {"@type" => "@none"}},
502
- "@type as @set" => {"foo" => {"@type" => "@set"}},
503
- "@container as object" => {"foo" => {"@container" => {}}},
504
- "@container as empty array" => {"foo" => {"@container" => []}},
505
- "@container as string" => {"foo" => {"@container" => "true"}},
506
- "@context which is invalid" => {"foo" => {"@context" => {"bar" => []}}},
507
- "@language as @id" => {"@language" => {"@id" => "http://example.com/"}},
508
- "@direction as foo" => {"@direction" => "foo"},
509
- "@vocab as @id" => {"@vocab" => {"@id" => "http://example.com/"}},
510
- "@prefix string" => {"foo" => {"@id" => 'http://example.org/', "@prefix" => "str"}},
511
- "@prefix array" => {"foo" => {"@id" => 'http://example.org/', "@prefix" => []}},
512
- "@prefix object" => {"foo" => {"@id" => 'http://example.org/', "@prefix" => {}}},
513
- "IRI term expands to different IRI" => {
514
- "ex" => "http://example.com/",
515
- "ex2" => "http://example.com/2/",
516
- "ex:foo" => "ex2:foo"
517
- },
518
- "IRI term expands to different IRI (reverse)" => {
519
- "ex" => "http://example.com/",
520
- "ex2" => "http://example.com/2/",
521
- "ex:foo" => {"@reverse" => "ex2:foo"}
522
- }
523
- }.each do |title, context|
524
- it title do
525
- expect {
526
- ec = subject.parse(context)
527
- expect(ec.serialize).to produce({}, logger)
528
- }.to raise_error(JSON::LD::JsonLdError)
529
- end
530
- end
531
-
532
- context "1.0" do
533
- let(:context) {JSON::LD::Context.new(logger: logger, validate: true, processingMode: 'json-ld-1.0')}
534
- {
535
- "@context" => {"foo" => {"@id" => 'http://example.org/', "@context" => {}}},
536
- "@container @id" => {"foo" => {"@container" => "@id"}},
537
- "@container @type" => {"foo" => {"@container" => "@type"}},
538
- "@nest" => {"foo" => {"@id" => 'http://example.org/', "@nest" => "@nest"}},
539
- "@type as @none" => {"foo" => {"@type" => "@none"}},
540
- "@type as @json" => {"foo" => {"@type" => "@json"}},
541
- "@prefix" => {"foo" => {"@id" => 'http://example.org/', "@prefix" => true}},
542
- }.each do |title, context|
543
- it title do
544
- expect {
545
- ec = subject.parse(context)
546
- expect(ec.serialize).to produce({}, logger)
547
- }.to raise_error(JSON::LD::JsonLdError)
548
- end
549
- end
550
-
551
- it "generates InvalidContextEntry if using @propagate" do
552
- expect {context.parse({'@propagate' => true})}.to raise_error(JSON::LD::JsonLdError::InvalidContextEntry)
553
- end
554
-
555
- it "generates InvalidContextEntry if using @import" do
556
- expect {context.parse({'@import' => "location"})}.to raise_error(JSON::LD::JsonLdError::InvalidContextEntry)
557
- end
558
-
559
- (JSON::LD::KEYWORDS - %w(@base @language @version @protected @propagate @vocab)).each do |kw|
560
- it "does not redefine #{kw} with an @container" do
561
- expect {
562
- ec = subject.parse({kw => {"@container" => "@set"}})
563
- expect(ec.serialize).to produce({}, logger)
564
- }.to raise_error(JSON::LD::JsonLdError)
565
- end
566
- end
567
- end
568
-
569
- (JSON::LD::KEYWORDS - %w(@base @direction @language @protected @propagate @import @version @vocab)).each do |kw|
570
- it "does not redefine #{kw} as a string" do
571
- expect {
572
- ec = subject.parse({kw => "http://example.com/"})
573
- expect(ec.serialize).to produce({}, logger)
574
- }.to raise_error(JSON::LD::JsonLdError)
575
- end
576
-
577
- it "does not redefine #{kw} with an @id" do
578
- expect {
579
- ec = subject.parse({kw => {"@id" => "http://example.com/"}})
580
- expect(ec.serialize).to produce({}, logger)
581
- }.to raise_error(JSON::LD::JsonLdError)
582
- end
583
-
584
- it "does not redefine #{kw} with an @container" do
585
- expect {
586
- ec = subject.parse({"@version" => 1.1, kw => {"@container" => "@set"}})
587
- expect(ec.serialize).to produce({}, logger)
588
- }.to raise_error(JSON::LD::JsonLdError)
589
- end unless kw == '@type'
590
-
591
- it "redefines #{kw} with an @container" do
592
- ec = subject.parse({kw => {"@container" => "@set"}})
593
- expect(ec.as_array('@type')).to be_truthy
594
- end if kw == '@type'
595
- end
596
- end
597
- end
598
-
599
- describe "#processingMode" do
600
- it "sets to json-ld-1.1 if @version: 1.1" do
601
- [
602
- %({"@version": 1.1}),
603
- %([{"@version": 1.1}]),
604
- ].each do |str|
605
- ctx = JSON::LD::Context.parse(::JSON.parse(str))
606
- expect(ctx.processingMode).to eql "json-ld-1.1"
607
- end
608
- end
609
-
610
- it "raises InvalidVersionValue if @version out of scope" do
611
- [
612
- "1.1",
613
- "1.0",
614
- 1.0,
615
- "foo"
616
- ].each do |vers|
617
- expect {JSON::LD::Context.parse({"@version" => vers})}.to raise_error(JSON::LD::JsonLdError::InvalidVersionValue)
618
- end
619
- end
620
-
621
- it "raises ProcessingModeConflict if provided processing mode conflicts with context" do
622
- expect {JSON::LD::Context.parse({"@version" => 1.1}, processingMode: "json-ld-1.0")}.to raise_error(JSON::LD::JsonLdError::ProcessingModeConflict)
623
- end
624
-
625
- it "does not raise ProcessingModeConflict nested context is different from starting context" do
626
- expect {JSON::LD::Context.parse([{}, {"@version" => 1.1}])}.not_to raise_error
627
- end
628
- end
629
-
630
- describe "#merge" do
631
- it "creates a new context with components of each" do
632
- c2 = JSON::LD::Context.parse({'foo' => "http://example.com/"})
633
- cm = context.merge(c2)
634
- expect(cm).not_to equal context
635
- expect(cm).not_to equal c2
636
- expect(cm.term_definitions).to eq c2.term_definitions
637
- end
638
- end
639
-
640
- describe "#serialize" do
641
- before {JSON::LD::Context.instance_variable_set(:@cache, nil)}
642
- it "context hash" do
643
- ctx = {"foo" => "http://example.com/"}
644
-
645
- ec = subject.parse(ctx)
646
- expect(ec.serialize).to produce({
647
- "@context" => ctx
648
- }, logger)
649
- end
650
-
651
- it "@language" do
652
- subject.default_language = "en"
653
- expect(subject.serialize).to produce({
654
- "@context" => {
655
- "@language" => "en"
656
- }
657
- }, logger)
658
- end
659
-
660
- it "@vocab" do
661
- subject.vocab = "http://example.com/"
662
- expect(subject.serialize).to produce({
663
- "@context" => {
664
- "@vocab" => "http://example.com/"
665
- }
666
- }, logger)
667
- end
668
-
669
- it "term mappings" do
670
- c = subject.
671
- parse({'foo' => "http://example.com/"})
672
- expect(c.serialize).to produce({
673
- "@context" => {
674
- "foo" => "http://example.com/"
675
- }
676
- }, logger)
677
- end
678
-
679
- it "@context" do
680
- expect(subject.parse({
681
- "foo" => {"@id" => "http://example.com/", "@context" => {"bar" => "http://example.com/baz"}}
682
- }).
683
- serialize).to produce({
684
- "@context" => {
685
- "foo" => {
686
- "@id" => "http://example.com/",
687
- "@context" => {"bar" => "http://example.com/baz"}
688
- }
689
- }
690
- }, logger)
691
- end
692
-
693
- it "@type with dependent prefixes in a single context" do
694
- expect(subject.parse({
695
- 'xsd' => "http://www.w3.org/2001/XMLSchema#",
696
- 'homepage' => {'@id' => RDF::Vocab::FOAF.homepage.to_s, '@type' => '@id'}
697
- }).
698
- serialize).to produce({
699
- "@context" => {
700
- "xsd" => RDF::XSD.to_uri.to_s,
701
- "homepage" => {"@id" => RDF::Vocab::FOAF.homepage.to_s, "@type" => "@id"}
702
- }
703
- }, logger)
704
- end
705
-
706
- it "@list with @id definition in a single context" do
707
- expect(subject.parse({
708
- 'knows' => {'@id' => RDF::Vocab::FOAF.knows.to_s, '@container' => '@list'}
709
- }).
710
- serialize).to produce({
711
- "@context" => {
712
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
713
- }
714
- }, logger)
715
- end
716
-
717
- it "@set with @id definition in a single context" do
718
- expect(subject.parse({
719
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@set"}
720
- }).
721
- serialize).to produce({
722
- "@context" => {
723
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@set"}
724
- }
725
- }, logger)
726
- end
727
-
728
- it "@language with @id definition in a single context" do
729
- expect(subject.parse({
730
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "en"}
731
- }).
732
- serialize).to produce({
733
- "@context" => {
734
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "en"}
735
- }
736
- }, logger)
737
- end
738
-
739
- it "@language with @id definition in a single context and equivalent default" do
740
- expect(subject.parse({
741
- "@language" => 'en',
742
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => 'en'}
743
- }).
744
- serialize).to produce({
745
- "@context" => {
746
- "@language" => 'en',
747
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => 'en'}
748
- }
749
- }, logger)
750
- end
751
-
752
- it "@language with @id definition in a single context and different default" do
753
- expect(subject.parse({
754
- "@language" => 'en',
755
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "de"}
756
- }).
757
- serialize).to produce({
758
- "@context" => {
759
- "@language" => 'en',
760
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "de"}
761
- }
762
- }, logger)
763
- end
764
-
765
- it "null @language with @id definition in a single context and default" do
766
- expect(subject.parse({
767
- "@language" => 'en',
768
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => nil}
769
- }).
770
- serialize).to produce({
771
- "@context" => {
772
- "@language" => 'en',
773
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => nil}
774
- }
775
- }, logger)
776
- end
777
-
778
- it "prefix with @type and @list" do
779
- expect(subject.parse({
780
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
781
- }).
782
- serialize).to produce({
783
- "@context" => {
784
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
785
- }
786
- }, logger)
787
- end
788
-
789
- it "prefix with @type and @set" do
790
- expect(subject.parse({
791
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
792
- }).
793
- serialize).to produce({
794
- "@context" => {
795
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
796
- }
797
- }, logger)
798
- end
799
-
800
- it "prefix with @type @json" do
801
- expect(subject.parse({
802
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@json"}
803
- }).
804
- serialize).to produce({
805
- "@context" => {
806
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@json"}
807
- }
808
- }, logger)
809
- end
810
-
811
- it "Compact IRI with @type" do
812
- expect(subject.parse({
813
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
814
- "foaf:knows" => {
815
- "@container" => "@list"
816
- }
817
- }).
818
- serialize).to produce({
819
- "@context" => {
820
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
821
- "foaf:knows" => {
822
- "@container" => "@list"
823
- }
824
- }
825
- }, logger)
826
- end
827
-
828
- it "does not use aliased @id in key position" do
829
- expect(subject.parse({
830
- "id" => "@id",
831
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
832
- }).
833
- serialize).to produce({
834
- "@context" => {
835
- "id" => "@id",
836
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
837
- }
838
- }, logger)
839
- end
840
-
841
- it "does not use aliased @id in value position" do
842
- expect(subject.parse({
843
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
844
- "id" => "@id",
845
- "foaf:homepage" => {
846
- "@type" => "@id"
847
- }
848
- }).
849
- serialize).to produce({
850
- "@context" => {
851
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
852
- "id" => "@id",
853
- "foaf:homepage" => {
854
- "@type" => "@id"
855
- }
856
- }
857
- }, logger)
858
- end
859
-
860
- it "does not use aliased @type" do
861
- expect(subject.parse({
862
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
863
- "type" => "@type",
864
- "foaf:homepage" => {"@type" => "@id"}
865
- }).
866
- serialize).to produce({
867
- "@context" => {
868
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
869
- "type" => "@type",
870
- "foaf:homepage" => {"@type" => "@id"}
871
- }
872
- }, logger)
873
- end
874
-
875
- it "does not use aliased @container" do
876
- expect(subject.parse({
877
- "container" => "@container",
878
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
879
- }).
880
- serialize).to produce({
881
- "@context" => {
882
- "container" => "@container",
883
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
884
- }
885
- }, logger)
886
- end
887
-
888
- it "compacts IRIs to Compact IRIs" do
889
- expect(subject.parse({
890
- "ex" => 'http://example.org/',
891
- "term" => {"@id" => "ex:term", "@type" => "ex:datatype"}
892
- }).
893
- serialize).to produce({
894
- "@context" => {
895
- "ex" => 'http://example.org/',
896
- "term" => {"@id" => "ex:term", "@type" => "ex:datatype"}
897
- }
898
- }, logger)
899
- end
900
-
901
- it "compacts IRIs using @vocab" do
902
- expect(subject.parse({
903
- "@vocab" => 'http://example.org/',
904
- "term" => {"@id" => "http://example.org/term", "@type" => "datatype"}
905
- }).
906
- serialize).to produce({
907
- "@context" => {
908
- "@vocab" => 'http://example.org/',
909
- "term" => {"@type" => "datatype"}
910
- }
911
- }, logger)
912
- end
913
-
914
- context "invalid term definitions" do
915
- {
916
- "empty term": {
917
- input: {"" => "http://blank-term/"}
918
- },
919
- "extra key": {
920
- input: {"foo" => {"@id" => "http://example.com/foo", "@baz" => "foobar"}}
921
- }
922
- }.each do |title, params|
923
- it title do
924
- expect {subject.parse(params[:input])}.to raise_error(JSON::LD::JsonLdError::InvalidTermDefinition)
925
- end
926
- end
927
- end
928
-
929
- end
930
-
931
- describe "#to_rb" do
932
- before(:all) {JSON::LD::Context.instance_variable_set(:@cache, nil)}
933
- subject {
934
- allow(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
935
- context.parse("http://example.com/context")
936
- }
937
-
938
- it "encodes as utf-8" do
939
- expect(subject.to_rb).to match(/encoding: utf-8/)
940
- end
941
-
942
- it "marked as auto-generated" do
943
- expect(subject.to_rb).to match(/This file generated automatically from/)
944
- end
945
-
946
- it "includes URL in preloaded" do
947
- expect(subject.to_rb).to include(%(add_preloaded("http://example.com/context")))
948
- end
949
-
950
- it "includes processingMode" do
951
- expect(subject.to_rb).to include(%(processingMode: "json-ld-1.1"))
952
- end
953
-
954
- it "term mappings" do
955
- expect(subject.to_rb).to include(%("avatar" => TermDefinition.new("avatar", id: "http://xmlns.com/foaf/0.1/avatar", type_mapping: "@id")))
956
- expect(subject.to_rb).to include(%("homepage" => TermDefinition.new("homepage", id: "http://xmlns.com/foaf/0.1/homepage", type_mapping: "@id")))
957
- expect(subject.to_rb).to include(%("name" => TermDefinition.new("name", id: "http://xmlns.com/foaf/0.1/name", simple: true)))
958
- expect(subject.to_rb).to include(%("xsd" => TermDefinition.new("xsd", id: "http://www.w3.org/2001/XMLSchema#", simple: true, prefix: true)))
959
- end
960
- end
961
-
962
- describe "#base=" do
963
- subject {
964
- context.parse({
965
- '@base' => 'http://base/',
966
- '@vocab' => 'http://vocab/',
967
- 'ex' => 'http://example.org/',
968
- '_' => 'http://underscore/'
969
- })
970
- }
971
-
972
- it "sets new base uri given an absolute uri" do
973
- subject.base = "http://example.org/"
974
- expect(subject.base).to eql RDF::URI("http://example.org/")
975
- end
976
-
977
- it "sets relative URI" do
978
- subject.base = "foo/bar"
979
- expect(subject.base).to eql RDF::URI("http://base/foo/bar")
980
- end
981
- end
982
-
983
- describe "#vocab=" do
984
- subject {
985
- context.parse({
986
- '@base' => 'http://base/resource',
987
- })
988
- }
989
-
990
- it "sets vocab from absolute iri" do
991
- subject.vocab = "http://example.org/"
992
- expect(subject.vocab).to eql RDF::URI("http://example.org/")
993
- end
994
-
995
- it "sets vocab from empty string" do
996
- subject.vocab = ""
997
- expect(subject.vocab).to eql RDF::URI("http://base/resource")
998
- end
999
-
1000
- it "sets vocab to blank node (with deprecation)" do
1001
- expect do
1002
- subject.vocab = "_:bn"
1003
- end.to write("[DEPRECATION]").to(:error)
1004
- expect(subject.vocab).to eql "_:bn"
1005
- end
1006
-
1007
- it "sets vocab from relative IRI" do
1008
- subject.vocab = "relative#"
1009
- expect(subject.vocab).to eql RDF::URI("http://base/relative#")
1010
- end
1011
-
1012
- it "sets vocab from relative IRI given an existing vocab" do
1013
- subject.vocab = "http://example.org/."
1014
- subject.vocab = "relative#"
1015
- expect(subject.vocab).to eql RDF::URI("http://example.org/.relative#")
1016
- end
1017
-
1018
- it "sets vocab from relative IRI given an existing vocab which is also relative" do
1019
- subject.vocab = "/rel1"
1020
- subject.vocab = "rel2#"
1021
- expect(subject.vocab).to eql RDF::URI("http://base/rel1rel2#")
1022
- end
1023
- end
1024
-
1025
- describe "#expand_iri" do
1026
- subject {
1027
- context.parse({
1028
- '@base' => 'http://base/base',
1029
- '@vocab' => 'http://vocab/',
1030
- 'ex' => 'http://example.org/',
1031
- '_' => 'http://underscore/'
1032
- })
1033
- }
1034
-
1035
- it "bnode" do
1036
- expect(subject.expand_iri("_:a")).to be_a(RDF::Node)
1037
- end
1038
-
1039
- context "keywords" do
1040
- %w(id type).each do |kw|
1041
- it "expands #{kw} to @#{kw}" do
1042
- subject.set_mapping(kw, "@#{kw}")
1043
- expect(subject.expand_iri(kw, vocab: true)).to produce("@#{kw}", logger)
1044
- end
1045
- end
1046
- end
1047
-
1048
- context "relative IRI" do
1049
- context "with no options" do
1050
- {
1051
- "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
1052
- "term" => ["ex", RDF::URI("ex")],
1053
- "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
1054
- "#frag" => ["#frag", RDF::URI("#frag")],
1055
- "#frag:2" => ["#frag:2", RDF::URI("#frag:2")],
1056
- "keyword" => ["@type", "@type"],
1057
- "unmapped" => ["foo", RDF::URI("foo")],
1058
- "relative" => ["foo/bar", RDF::URI("foo/bar")],
1059
- "dotseg" => ["../foo/bar", RDF::URI("../foo/bar")],
1060
- "empty term" => ["", RDF::URI("")],
1061
- "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
1062
- "absolute IRI looking like a Compact IRI" =>
1063
- ["foo:bar", RDF::URI("foo:bar")],
1064
- "bnode" => ["_:t0", RDF::Node("t0")],
1065
- "_" => ["_", RDF::URI("_")],
1066
- "@" => ["@", RDF::URI("@")],
1067
- }.each do |title, (input, result)|
1068
- it title do
1069
- expect(subject.expand_iri(input)).to produce(result, logger)
1070
- end
1071
- end
1072
- end
1073
-
1074
- context "with base IRI" do
1075
- {
1076
- "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
1077
- "term" => ["ex", RDF::URI("http://base/ex")],
1078
- "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
1079
- "#frag" => ["#frag", RDF::URI("http://base/base#frag")],
1080
- "#frag:2" => ["#frag:2", RDF::URI("http://base/base#frag:2")],
1081
- "keyword" => ["@type", "@type"],
1082
- "unmapped" => ["foo", RDF::URI("http://base/foo")],
1083
- "relative" => ["foo/bar", RDF::URI("http://base/foo/bar")],
1084
- "dotseg" => ["../foo/bar", RDF::URI("http://base/foo/bar")],
1085
- "empty term" => ["", RDF::URI("http://base/base")],
1086
- "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
1087
- "absolute IRI looking like a compact IRI" =>
1088
- ["foo:bar", RDF::URI("foo:bar")],
1089
- "bnode" => ["_:t0", RDF::Node("t0")],
1090
- "_" => ["_", RDF::URI("http://base/_")],
1091
- "@" => ["@", RDF::URI("http://base/@")],
1092
- }.each do |title, (input, result)|
1093
- it title do
1094
- expect(subject.expand_iri(input, documentRelative: true)).to produce(result, logger)
1095
- end
1096
- end
1097
- end
1098
-
1099
- context "@vocab" do
1100
- {
1101
- "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
1102
- "term" => ["ex", RDF::URI("http://example.org/")],
1103
- "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
1104
- "#frag" => ["#frag", RDF::URI("http://vocab/#frag")],
1105
- "#frag:2" => ["#frag:2", RDF::URI("http://vocab/#frag:2")],
1106
- "keyword" => ["@type", "@type"],
1107
- "unmapped" => ["foo", RDF::URI("http://vocab/foo")],
1108
- "relative" => ["foo/bar", RDF::URI("http://vocab/foo/bar")],
1109
- "dotseg" => ["../foo/bar", RDF::URI("http://vocab/../foo/bar")],
1110
- "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
1111
- "absolute IRI looking like a compact IRI" =>
1112
- ["foo:bar", RDF::URI("foo:bar")],
1113
- "bnode" => ["_:t0", RDF::Node("t0")],
1114
- "_" => ["_", RDF::URI("http://underscore/")],
1115
- "@" => ["@", RDF::URI("http://vocab/@")],
1116
- }.each do |title, (input, result)|
1117
- it title do
1118
- expect(subject.expand_iri(input, vocab: true)).to produce(result, logger)
1119
- end
1120
- end
1121
-
1122
- context "set to ''" do
1123
- subject {
1124
- context.parse({
1125
- '@base' => 'http://base/base',
1126
- '@vocab' => '',
1127
- 'ex' => 'http://example.org/',
1128
- '_' => 'http://underscore/'
1129
- })
1130
- }
1131
-
1132
- {
1133
- "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
1134
- "term" => ["ex", RDF::URI("http://example.org/")],
1135
- "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
1136
- "#frag" => ["#frag", RDF::URI("http://base/base#frag")],
1137
- "#frag:2" => ["#frag:2", RDF::URI("http://base/base#frag:2")],
1138
- "keyword" => ["@type", "@type"],
1139
- "unmapped" => ["foo", RDF::URI("http://base/basefoo")],
1140
- "relative" => ["foo/bar", RDF::URI("http://base/basefoo/bar")],
1141
- "dotseg" => ["../foo/bar", RDF::URI("http://base/base../foo/bar")],
1142
- "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
1143
- "absolute IRI looking like a compact IRI" =>
1144
- ["foo:bar", RDF::URI("foo:bar")],
1145
- "bnode" => ["_:t0", RDF::Node("t0")],
1146
- "_" => ["_", RDF::URI("http://underscore/")],
1147
- }.each do |title, (input, result)|
1148
- it title do
1149
- expect(subject.expand_iri(input, vocab: true)).to produce(result, logger)
1150
- end
1151
- end
1152
- end
1153
-
1154
- it "expand-0110" do
1155
- ctx = JSON::LD::Context.parse({
1156
- "@base" => "http://example.com/some/deep/directory/and/file/",
1157
- "@vocab" => "/relative"
1158
- })
1159
- expect(ctx.expand_iri("#fragment-works", vocab: true)).to produce("http://example.com/relative#fragment-works", logger)
1160
- end
1161
- end
1162
- end
1163
- end
1164
-
1165
- describe "#compact_iri" do
1166
- subject {
1167
- c = context.parse({
1168
- '@base' => 'http://base/',
1169
- "xsd" => "http://www.w3.org/2001/XMLSchema#",
1170
- 'ex' => 'http://example.org/',
1171
- '_' => 'http://underscore/',
1172
- 'rex' => {'@reverse' => "ex"},
1173
- 'lex' => {'@id' => 'ex', '@language' => 'en'},
1174
- 'tex' => {'@id' => 'ex', '@type' => 'xsd:string'},
1175
- 'exp' => {'@id' => 'ex:pert'},
1176
- 'experts' => {'@id' => 'ex:perts'},
1177
- })
1178
- logger.clear
1179
- c
1180
- }
1181
-
1182
- {
1183
- "nil" => [nil, nil],
1184
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1185
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1186
- "unmapped" => ["foo", "foo"],
1187
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1188
- "relative" => ["foo/bar", "http://base/foo/bar"],
1189
- "odd Compact IRI"=>["ex:perts", "http://example.org/perts"]
1190
- }.each do |title, (result, input)|
1191
- it title do
1192
- if result.is_a?(Class)
1193
- expect {subject.compact_iri(input)}.to raise_error(result)
1194
- else
1195
- expect(subject.compact_iri(input)).to produce(result, logger)
1196
- end
1197
- end
1198
- end
1199
-
1200
- context "with :vocab option" do
1201
- {
1202
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1203
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1204
- "keyword" => ["@type", "@type"],
1205
- "unmapped" => ["foo", "foo"],
1206
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1207
- "relative" => ["http://base/foo/bar", "http://base/foo/bar"],
1208
- "odd Compact IRI"=> ["experts", "http://example.org/perts"]
1209
- }.each do |title, (result, input)|
1210
- it title do
1211
- if result.is_a?(Class)
1212
- expect {subject.compact_iri(input, vocab: true)}.to raise_error(result)
1213
- else
1214
- expect(subject.compact_iri(input, vocab: true)).to produce(result, logger)
1215
- end
1216
- end
1217
- end
1218
- end
1219
-
1220
- context "with @vocab" do
1221
- before(:each) { subject.vocab = "http://example.org/"}
1222
-
1223
- {
1224
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1225
- "prefix:suffix" => ["suffix", "http://example.org/suffix"],
1226
- "keyword" => ["@type", "@type"],
1227
- "unmapped" => ["foo", "foo"],
1228
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1229
- "relative" => ["http://base/foo/bar", "http://base/foo/bar"],
1230
- "odd Compact IRI"=> ["experts", "http://example.org/perts"]
1231
- }.each do |title, (result, input)|
1232
- it title do
1233
- if result.is_a?(Class)
1234
- expect {subject.compact_iri(input, vocab: true)}.to raise_error(result)
1235
- else
1236
- expect(subject.compact_iri(input, vocab: true)).to produce(result, logger)
1237
- end
1238
- end
1239
- end
1240
-
1241
- it "does not use @vocab if it would collide with a term" do
1242
- subject.set_mapping("name", "http://xmlns.com/foaf/0.1/name")
1243
- subject.set_mapping("ex", nil)
1244
- expect(subject.compact_iri("http://example.org/name", vocab: true)).
1245
- not_to produce("name", logger)
1246
- end
1247
-
1248
- context "with @vocab: relative" do
1249
- before(:each) {
1250
- subject.vocab = nil
1251
- subject.base = 'http://base/base'
1252
- }
1253
-
1254
- {
1255
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1256
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1257
- "keyword" => ["@type", "@type"],
1258
- "unmapped" => ["foo", "foo"],
1259
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1260
- "relative" => ["http://base/foo/bar", "http://base/foo/bar"],
1261
- "odd Compact IRI"=> ["experts", "http://example.org/perts"]
1262
- }.each do |title, (result, input)|
1263
- it title do
1264
- if result.is_a?(Class)
1265
- expect {subject.compact_iri(input, vocab: true)}.to raise_error(result)
1266
- else
1267
- expect(subject.compact_iri(input, vocab: true)).to produce(result, logger)
1268
- end
1269
- end
1270
- end
1271
- end
1272
- end
1273
-
1274
- context "with value" do
1275
- let(:ctx) do
1276
- c = subject.parse({
1277
- "xsd" => RDF::XSD.to_s,
1278
- "plain" => "http://example.com/plain",
1279
- "lang" => {"@id" => "http://example.com/lang", "@language" => "en"},
1280
- "dir" => {"@id" => "http://example.com/dir", "@direction" => "ltr"},
1281
- "langdir" => {"@id" => "http://example.com/langdir", "@language" => "en", "@direction" => "ltr"},
1282
- "bool" => {"@id" => "http://example.com/bool", "@type" => "xsd:boolean"},
1283
- "integer" => {"@id" => "http://example.com/integer", "@type" => "xsd:integer"},
1284
- "double" => {"@id" => "http://example.com/double", "@type" => "xsd:double"},
1285
- "date" => {"@id" => "http://example.com/date", "@type" => "xsd:date"},
1286
- "id" => {"@id" => "http://example.com/id", "@type" => "@id"},
1287
- 'graph' => {'@id' => 'http://example.com/graph', '@container' => '@graph'},
1288
- 'json' => {'@id' => 'http://example.com/json', '@type' => '@json'},
1289
-
1290
- "list_plain" => {"@id" => "http://example.com/plain", "@container" => "@list"},
1291
- "list_lang" => {"@id" => "http://example.com/lang", "@language" => "en", "@container" => "@list"},
1292
- "list_bool" => {"@id" => "http://example.com/bool", "@type" => "xsd:boolean", "@container" => "@list"},
1293
- "list_integer" => {"@id" => "http://example.com/integer", "@type" => "xsd:integer", "@container" => "@list"},
1294
- "list_double" => {"@id" => "http://example.com/double", "@type" => "xsd:double", "@container" => "@list"},
1295
- "list_date" => {"@id" => "http://example.com/date", "@type" => "xsd:date", "@container" => "@list"},
1296
- "list_id" => {"@id" => "http://example.com/id", "@type" => "@id", "@container" => "@list"},
1297
- "list_graph" => {"@id" => "http://example.com/graph", "@type" => "@id", "@container" => "@list"},
1298
-
1299
- "set_plain" => {"@id" => "http://example.com/plain", "@container" => "@set"},
1300
- "set_lang" => {"@id" => "http://example.com/lang", "@language" => "en", "@container" => "@set"},
1301
- "set_bool" => {"@id" => "http://example.com/bool", "@type" => "xsd:boolean", "@container" => "@set"},
1302
- "set_integer" => {"@id" => "http://example.com/integer", "@type" => "xsd:integer", "@container" => "@set"},
1303
- "set_double" => {"@id" => "http://example.com/double", "@type" => "xsd:double", "@container" => "@set"},
1304
- "set_date" => {"@id" => "http://example.com/date", "@type" => "xsd:date", "@container" => "@set"},
1305
- "set_id" => {"@id" => "http://example.com/id", "@type" => "@id", "@container" => "@set"},
1306
- 'set_graph' => {'@id' => 'http://example.com/graph', '@container' => ['@graph', '@set']},
1307
-
1308
- "map_lang" => {"@id" => "http://example.com/lang", "@container" => "@language"},
1309
-
1310
- "set_map_lang" => {"@id" => "http://example.com/lang", "@container" => ["@language", "@set"]},
1311
- })
1312
- logger.clear
1313
- c
1314
- end
1315
-
1316
- # Prefered sets and maps over non sets or maps
1317
- {
1318
- "set_plain" => [{"@value" => "foo"}],
1319
- "map_lang" => [{"@value" => "en", "@language" => "en"}],
1320
- "set_bool" => [{"@value" => "true", "@type" => "http://www.w3.org/2001/XMLSchema#boolean"}],
1321
- "set_integer" => [{"@value" => "1", "@type" => "http://www.w3.org/2001/XMLSchema#integer"}],
1322
- "set_id" => [{"@id" => "http://example.org/id"}],
1323
- "graph" => [{"@graph" => [{"@id" => "http://example.org/id"}]}],
1324
- 'json' => [{"@value" => {"some" => "json"}, "@type" => "@json"}],
1325
- 'dir' => [{"@value" => "dir", "@direction" => "ltr"}],
1326
- 'langdir' => [{"@value" => "lang dir", "@language" => "en", "@direction" => "ltr"}],
1327
- }.each do |prop, values|
1328
- context "uses #{prop}" do
1329
- values.each do |value|
1330
- it "for #{value.inspect}" do
1331
- expect(ctx.compact_iri("http://example.com/#{prop.sub(/^\w+_/, '')}", value: value, vocab: true)).
1332
- to produce(prop, logger)
1333
- end
1334
- end
1335
- end
1336
- end
1337
-
1338
- # @language and @type with @list
1339
- context "for @list" do
1340
- {
1341
- "list_plain" => [
1342
- [{"@value" => "foo"}],
1343
- [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => "baz"}],
1344
- [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => 1}],
1345
- [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => 1.1}],
1346
- [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => true}],
1347
- [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => 1}],
1348
- [{"@value" => "de", "@language" => "de"}, {"@value" => "jp", "@language" => "jp"}],
1349
- [{"@value" => true}], [{"@value" => false}],
1350
- [{"@value" => 1}], [{"@value" => 1.1}],
1351
- ],
1352
- "list_lang" => [[{"@value" => "en", "@language" => "en"}]],
1353
- "list_bool" => [[{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}]],
1354
- "list_integer" => [[{"@value" => "1", "@type" => RDF::XSD.integer.to_s}]],
1355
- "list_double" => [[{"@value" => "1", "@type" => RDF::XSD.double.to_s}]],
1356
- "list_date" => [[{"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}]],
1357
- }.each do |prop, values|
1358
- context "uses #{prop}" do
1359
- values.each do |value|
1360
- it "for #{{"@list" => value}.inspect}" do
1361
- expect(ctx.compact_iri("http://example.com/#{prop.sub(/^\w+_/, '')}", value: {"@list" => value}, vocab: true)).
1362
- to produce(prop, logger)
1363
- end
1364
- end
1365
- end
1366
- end
1367
- end
1368
- end
1369
-
1370
- context "Compact IRI compaction" do
1371
- {
1372
- "nil" => [nil, nil],
1373
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1374
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1375
- "unmapped" => ["foo", "foo"],
1376
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1377
- "relative" => ["foo/bar", "http://base/foo/bar"],
1378
- "odd Compact IRI"=> ["ex:perts", "http://example.org/perts"]
1379
- }.each do |title, (result, input)|
1380
- it title do
1381
- if result.is_a?(Class)
1382
- expect {subject.compact_iri(input)}.to raise_error(result)
1383
- else
1384
- expect(subject.compact_iri(input)).to produce(result, logger)
1385
- end
1386
- end
1387
- end
1388
-
1389
- context "and @vocab" do
1390
- before(:each) { subject.vocab = "http://example.org/"}
1391
-
1392
- {
1393
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1394
- "prefix:suffix" => ["suffix", "http://example.org/suffix"],
1395
- "keyword" => ["@type", "@type"],
1396
- "unmapped" => ["foo", "foo"],
1397
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1398
- "relative" => ["http://base/foo/bar", "http://base/foo/bar"],
1399
- "odd Compact IRI"=> ["experts", "http://example.org/perts"]
1400
- }.each do |title, (result, input)|
1401
- it title do
1402
- if result.is_a?(Class)
1403
- expect {subject.compact_iri(input, vocab: true)}.to raise_error(result)
1404
- else
1405
- expect(subject.compact_iri(input, vocab: true)).to produce(result, logger)
1406
- end
1407
- end
1408
- end
1409
- end
1410
- end
1411
-
1412
- context "compact-0018" do
1413
- let(:ctx) do
1414
- subject.parse(JSON.parse %({
1415
- "id1": "http://example.com/id1",
1416
- "type1": "http://example.com/t1",
1417
- "type2": "http://example.com/t2",
1418
- "@language": "de",
1419
- "term": {
1420
- "@id": "http://example.com/term"
1421
- },
1422
- "term1": {
1423
- "@id": "http://example.com/term",
1424
- "@container": "@list"
1425
- },
1426
- "term2": {
1427
- "@id": "http://example.com/term",
1428
- "@container": "@list",
1429
- "@language": "en"
1430
- },
1431
- "term3": {
1432
- "@id": "http://example.com/term",
1433
- "@container": "@list",
1434
- "@language": null
1435
- },
1436
- "term4": {
1437
- "@id": "http://example.com/term",
1438
- "@container": "@list",
1439
- "@type": "type1"
1440
- },
1441
- "term5": {
1442
- "@id": "http://example.com/term",
1443
- "@container": "@list",
1444
- "@type": "type2"
1445
- }
1446
- }))
1447
- end
1448
-
1449
- {
1450
- "term" => [
1451
- '{ "@value": "v0.1", "@language": "de" }',
1452
- '{ "@value": "v0.2", "@language": "en" }',
1453
- '{ "@value": "v0.3"}',
1454
- '{ "@value": 4}',
1455
- '{ "@value": true}',
1456
- '{ "@value": false}'
1457
- ],
1458
- "term1" => %q({
1459
- "@list": [
1460
- { "@value": "v1.1", "@language": "de" },
1461
- { "@value": "v1.2", "@language": "en" },
1462
- { "@value": "v1.3"},
1463
- { "@value": 14},
1464
- { "@value": true},
1465
- { "@value": false}
1466
- ]
1467
- }),
1468
- "term2" => %q({
1469
- "@list": [
1470
- { "@value": "v2.1", "@language": "en" },
1471
- { "@value": "v2.2", "@language": "en" },
1472
- { "@value": "v2.3", "@language": "en" },
1473
- { "@value": "v2.4", "@language": "en" },
1474
- { "@value": "v2.5", "@language": "en" },
1475
- { "@value": "v2.6", "@language": "en" }
1476
- ]
1477
- }),
1478
- "term3" => %q({
1479
- "@list": [
1480
- { "@value": "v3.1"},
1481
- { "@value": "v3.2"},
1482
- { "@value": "v3.3"},
1483
- { "@value": "v3.4"},
1484
- { "@value": "v3.5"},
1485
- { "@value": "v3.6"}
1486
- ]
1487
- }),
1488
- "term4" => %q({
1489
- "@list": [
1490
- { "@value": "v4.1", "@type": "http://example.com/t1" },
1491
- { "@value": "v4.2", "@type": "http://example.com/t1" },
1492
- { "@value": "v4.3", "@type": "http://example.com/t1" },
1493
- { "@value": "v4.4", "@type": "http://example.com/t1" },
1494
- { "@value": "v4.5", "@type": "http://example.com/t1" },
1495
- { "@value": "v4.6", "@type": "http://example.com/t1" }
1496
- ]
1497
- }),
1498
- "term5" => %q({
1499
- "@list": [
1500
- { "@value": "v5.1", "@type": "http://example.com/t2" },
1501
- { "@value": "v5.2", "@type": "http://example.com/t2" },
1502
- { "@value": "v5.3", "@type": "http://example.com/t2" },
1503
- { "@value": "v5.4", "@type": "http://example.com/t2" },
1504
- { "@value": "v5.5", "@type": "http://example.com/t2" },
1505
- { "@value": "v5.6", "@type": "http://example.com/t2" }
1506
- ]
1507
- }),
1508
- }.each do |term, value|
1509
- [value].flatten.each do |v|
1510
- it "Uses #{term} for #{v}" do
1511
- expect(ctx.compact_iri("http://example.com/term", value: JSON.parse(v), vocab: true)).
1512
- to produce(term, logger)
1513
- end
1514
- end
1515
- end
1516
- end
1517
-
1518
- context "compact-0020" do
1519
- let(:ctx) do
1520
- subject.parse({
1521
- "ex" => "http://example.org/ns#",
1522
- "ex:property" => {"@container" => "@list"}
1523
- })
1524
- end
1525
- it "Compact @id that is a property IRI when @container is @list" do
1526
- expect(ctx.compact_iri("http://example.org/ns#property", vocab: false)).
1527
- to produce("ex:property", logger)
1528
- end
1529
- end
1530
-
1531
- context "compact-0041" do
1532
- let(:ctx) do
1533
- subject.parse({"name" => {"@id" => "http://example.com/property", "@container" => "@list"}})
1534
- end
1535
- it "Does not use @list with @index" do
1536
- expect(ctx.compact_iri("http://example.com/property", value: {
1537
- "@list" => ["one item"],
1538
- "@index" => "an annotation"
1539
- })).to produce("http://example.com/property", logger)
1540
- end
1541
- end
1542
- end
1543
-
1544
- describe "#expand_value" do
1545
- subject {
1546
- ctx = context.parse({
1547
- "dc" => RDF::Vocab::DC.to_uri.to_s,
1548
- "ex" => "http://example.org/",
1549
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
1550
- "xsd" => "http://www.w3.org/2001/XMLSchema#",
1551
- "foaf:age" => {"@type" => "xsd:integer"},
1552
- "foaf:knows" => {"@type" => "@id"},
1553
- "dc:created" => {"@type" => "xsd:date"},
1554
- "ex:integer" => {"@type" => "xsd:integer"},
1555
- "ex:double" => {"@type" => "xsd:double"},
1556
- "ex:boolean" => {"@type" => "xsd:boolean"},
1557
- "ex:none" => {"@type" => "@none"},
1558
- "ex:json" => {"@type" => "@json"}
1559
- })
1560
- logger.clear
1561
- ctx
1562
- }
1563
-
1564
- %w(boolean integer string dateTime date time).each do |dt|
1565
- it "expands datatype xsd:#{dt}" do
1566
- expect(subject.expand_value("foo", RDF::XSD[dt])).to produce({"@id" => "http://www.w3.org/2001/XMLSchema##{dt}"}, logger)
1567
- end
1568
- end
1569
-
1570
- {
1571
- "absolute IRI" => ["foaf:knows", "http://example.com/", {"@id" => "http://example.com/"}],
1572
- "term" => ["foaf:knows", "ex", {"@id" => "ex"}],
1573
- "prefix:suffix" => ["foaf:knows", "ex:suffix", {"@id" => "http://example.org/suffix"}],
1574
- "no IRI" => ["foo", "http://example.com/", {"@value" => "http://example.com/"}],
1575
- "no term" => ["foo", "ex", {"@value" => "ex"}],
1576
- "no prefix" => ["foo", "ex:suffix", {"@value" => "ex:suffix"}],
1577
- "integer" => ["foaf:age", "54", {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1578
- "date " => ["dc:created", "2011-12-27Z", {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1579
- "native boolean" => ["foo", true, {"@value" => true}],
1580
- "native integer" => ["foo", 1, {"@value" => 1}],
1581
- "native double" => ["foo", 1.1e1, {"@value" => 1.1E1}],
1582
- "native date" => ["foo", Date.parse("2011-12-27"), {"@value" => "2011-12-27", "@type" => RDF::XSD.date.to_s}],
1583
- "native dateTime" =>["foo", DateTime.parse("2011-12-27T10:11:12Z"), {"@value" => "2011-12-27T10:11:12Z", "@type" => RDF::XSD.dateTime.to_s}],
1584
- "ex:none string" => ["ex:none", "foo", {"@value" => "foo"}],
1585
- "ex:none boolean" =>["ex:none", true, {"@value" => true}],
1586
- "ex:none integer" =>["ex:none", 1, {"@value" => 1}],
1587
- "ex:none double" => ["ex:none", 1.1e1, {"@value" => 1.1E1}],
1588
- "ex:json string" => ["ex:json", "foo", {"@value" => "foo", "@type" => "@json"}],
1589
- "ex:json boolean" =>["ex:json", true, {"@value" => true, "@type" => "@json"}],
1590
- "ex:json integer" =>["ex:json", 1, {"@value" => 1, "@type" => "@json"}],
1591
- "ex:json double" => ["ex:json", 1.1e1, {"@value" => 1.1e1, "@type" => "@json"}],
1592
- "ex:json object" => ["ex:json", {"foo" => "bar"}, {"@value" => {"foo" => "bar"}, "@type" => "@json"}],
1593
- "ex:json array" => ["ex:json", [{"foo" => "bar"}], {"@value" => [{"foo" => "bar"}], "@type" => "@json"}],
1594
- }.each do |title, (key, compacted, expanded)|
1595
- it title do
1596
- expect(subject.expand_value(key, compacted)).to produce(expanded, logger)
1597
- end
1598
- end
1599
-
1600
- context "@language" do
1601
- before(:each) {subject.default_language = "en"}
1602
- {
1603
- "no IRI" => ["foo", "http://example.com/", {"@value" => "http://example.com/", "@language" => "en"}],
1604
- "no term" => ["foo", "ex", {"@value" => "ex", "@language" => "en"}],
1605
- "no prefix" => ["foo", "ex:suffix", {"@value" => "ex:suffix", "@language" => "en"}],
1606
- "native boolean" => ["foo", true, {"@value" => true}],
1607
- "native integer" => ["foo", 1, {"@value" => 1}],
1608
- "native double" => ["foo", 1.1, {"@value" => 1.1}],
1609
- }.each do |title, (key, compacted, expanded)|
1610
- it title do
1611
- expect(subject.expand_value(key, compacted)).to produce(expanded, logger)
1612
- end
1613
- end
1614
- end
1615
-
1616
- context "coercion" do
1617
- before(:each) {subject.default_language = "en"}
1618
- {
1619
- "boolean-boolean" => ["ex:boolean", true, {"@value" => true, "@type" => RDF::XSD.boolean.to_s}],
1620
- "boolean-integer" => ["ex:integer", true, {"@value" => true, "@type" => RDF::XSD.integer.to_s}],
1621
- "boolean-double" => ["ex:double", true, {"@value" => true, "@type" => RDF::XSD.double.to_s}],
1622
- "boolean-json" => ["ex:json", true, {"@value" => true, "@type" => '@json'}],
1623
- "double-boolean" => ["ex:boolean", 1.1, {"@value" => 1.1, "@type" => RDF::XSD.boolean.to_s}],
1624
- "double-double" => ["ex:double", 1.1, {"@value" => 1.1, "@type" => RDF::XSD.double.to_s}],
1625
- "double-integer" => ["foaf:age", 1.1, {"@value" => 1.1, "@type" => RDF::XSD.integer.to_s}],
1626
- "double-json" => ["ex:json", 1.1, {"@value" => 1.1, "@type" => '@json'}],
1627
- "json-json" => ["ex:json", {"foo" => "bar"}, {"@value" => {"foo" => "bar"}, "@type" => '@json'}],
1628
- "integer-boolean" => ["ex:boolean", 1, {"@value" => 1, "@type" => RDF::XSD.boolean.to_s}],
1629
- "integer-double" => ["ex:double", 1, {"@value" => 1, "@type" => RDF::XSD.double.to_s}],
1630
- "integer-integer" => ["foaf:age", 1, {"@value" => 1, "@type" => RDF::XSD.integer.to_s}],
1631
- "integer-json" => ["ex:json", 1, {"@value" => 1, "@type" => '@json'}],
1632
- "string-boolean" => ["ex:boolean", "foo", {"@value" => "foo", "@type" => RDF::XSD.boolean.to_s}],
1633
- "string-double" => ["ex:double", "foo", {"@value" => "foo", "@type" => RDF::XSD.double.to_s}],
1634
- "string-integer" => ["foaf:age", "foo", {"@value" => "foo", "@type" => RDF::XSD.integer.to_s}],
1635
- "string-json" => ["ex:json", "foo", {"@value" => "foo", "@type" => '@json'}],
1636
- }.each do |title, (key, compacted, expanded)|
1637
- it title do
1638
- expect(subject.expand_value(key, compacted)).to produce(expanded, logger)
1639
- end
1640
- end
1641
- end
1642
- end
1643
-
1644
- describe "#compact_value" do
1645
- let(:ctx) do
1646
- c = context.parse({
1647
- "dc" => RDF::Vocab::DC.to_uri.to_s,
1648
- "ex" => "http://example.org/",
1649
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
1650
- "xsd" => RDF::XSD.to_s,
1651
- "langmap" => {"@id" => "http://example.com/langmap", "@container" => "@language"},
1652
- "list" => {"@id" => "http://example.org/list", "@container" => "@list"},
1653
- "nolang" => {"@id" => "http://example.org/nolang", "@language" => nil},
1654
- "dc:created" => {"@type" => RDF::XSD.date.to_s},
1655
- "foaf:age" => {"@type" => RDF::XSD.integer.to_s},
1656
- "foaf:knows" => {"@type" => "@id"},
1657
- "ex:none" => {"@type" => "@none"},
1658
- })
1659
- logger.clear
1660
- c
1661
- end
1662
- subject {ctx}
1663
-
1664
- {
1665
- "absolute IRI" => ["foaf:knows", "http://example.com/", {"@id" => "http://example.com/"}],
1666
- "prefix:suffix" => ["foaf:knows", "ex:suffix", {"@id" => "http://example.org/suffix"}],
1667
- "integer" => ["foaf:age", "54", {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1668
- "date " => ["dc:created", "2011-12-27Z", {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1669
- "no IRI" => ["foo", {"@id" =>"http://example.com/"},{"@id" => "http://example.com/"}],
1670
- "no IRI (Compact IRI)" => ["foo", {"@id" => RDF::Vocab::FOAF.Person.to_s}, {"@id" => RDF::Vocab::FOAF.Person.to_s}],
1671
- "no boolean" => ["foo", {"@value" => "true", "@type" => "xsd:boolean"},{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}],
1672
- "no integer" => ["foo", {"@value" => "54", "@type" => "xsd:integer"},{"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1673
- "no date " => ["foo", {"@value" => "2011-12-27Z", "@type" => "xsd:date"}, {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1674
- "no string " => ["foo", "string", {"@value" => "string"}],
1675
- "no lang " => ["nolang", "string", {"@value" => "string"}],
1676
- "native boolean" => ["foo", true, {"@value" => true}],
1677
- "native integer" => ["foo", 1, {"@value" => 1}],
1678
- "native integer(list)"=>["list", 1, {"@value" => 1}],
1679
- "native double" => ["foo", 1.1e1, {"@value" => 1.1E1}],
1680
- "ex:none IRI" => ["ex:none", {"@id" => "http://example.com/"}, {"@id" => "http://example.com/"}],
1681
- "ex:none string" => ["ex:none", {"@value" => "string"}, {"@value" => "string"}],
1682
- "ex:none integer" =>["ex:none", {"@value" => "54", "@type" => "xsd:integer"}, {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1683
- }.each do |title, (key, compacted, expanded)|
1684
- it title do
1685
- expect(subject.compact_value(key, expanded)).to produce(compacted, logger)
1686
- end
1687
- end
1688
-
1689
- context "@language" do
1690
- {
1691
- "@id" => ["foo", {"@id" => "foo"}, {"@id" => "foo"}],
1692
- "integer" => ["foo", {"@value" => "54", "@type" => "xsd:integer"}, {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1693
- "date" => ["foo", {"@value" => "2011-12-27Z","@type" => "xsd:date"},{"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1694
- "no lang" => ["foo", {"@value" => "foo" }, {"@value" => "foo"}],
1695
- "same lang" => ["foo", "foo", {"@value" => "foo", "@language" => "en"}],
1696
- "other lang" => ["foo", {"@value" => "foo", "@language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
1697
- "langmap" => ["langmap", "en", {"@value" => "en", "@language" => "en"}],
1698
- "no lang with @type coercion" => ["dc:created", {"@value" => "foo"}, {"@value" => "foo"}],
1699
- "no lang with @id coercion" => ["foaf:knows", {"@value" => "foo"}, {"@value" => "foo"}],
1700
- "no lang with @language=null" => ["nolang", "string", {"@value" => "string"}],
1701
- "same lang with @type coercion" => ["dc:created", {"@value" => "foo"}, {"@value" => "foo"}],
1702
- "same lang with @id coercion" => ["foaf:knows", {"@value" => "foo"}, {"@value" => "foo"}],
1703
- "other lang with @type coercion" => ["dc:created", {"@value" => "foo", "@language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
1704
- "other lang with @id coercion" => ["foaf:knows", {"@value" => "foo", "@language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
1705
- "native boolean" => ["foo", true, {"@value" => true}],
1706
- "native integer" => ["foo", 1, {"@value" => 1}],
1707
- "native integer(list)" => ["list", 1, {"@value" => 1}],
1708
- "native double" => ["foo", 1.1e1, {"@value" => 1.1E1}],
1709
- }.each do |title, (key, compacted, expanded)|
1710
- it title do
1711
- subject.default_language = "en"
1712
- expect(subject.compact_value(key, expanded)).to produce(compacted, logger)
1713
- end
1714
- end
1715
- end
1716
-
1717
- context "keywords" do
1718
- before(:each) do
1719
- subject.set_mapping("id", "@id")
1720
- subject.set_mapping("type", "@type")
1721
- subject.set_mapping("list", "@list")
1722
- subject.set_mapping("set", "@set")
1723
- subject.set_mapping("language", "@language")
1724
- subject.set_mapping("literal", "@value")
1725
- end
1726
-
1727
- {
1728
- "@id" => [{"id" => "http://example.com/"}, {"@id" => "http://example.com/"}],
1729
- "@type" => [{"literal" => "foo", "type" => "http://example.com/"},
1730
- {"@value" => "foo", "@type" => "http://example.com/"}],
1731
- "@value" => [{"literal" => "foo", "language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
1732
- }.each do |title, (compacted, expanded)|
1733
- it title do
1734
- expect(subject.compact_value("foo", expanded)).to produce(compacted, logger)
1735
- end
1736
- end
1737
- end
1738
- end
1739
-
1740
- describe "#from_vocabulary" do
1741
- it "must be described"
1742
- end
1743
-
1744
- describe "#container" do
1745
- subject {
1746
- ctx = context.parse({
1747
- "ex" => "http://example.org/",
1748
- "graph" => {"@id" => "ex:graph", "@container" => "@graph"},
1749
- "graphSet" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@set"]},
1750
- "graphId" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@id"]},
1751
- "graphIdSet" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@id", "@set"]},
1752
- "graphNdx" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@index"]},
1753
- "graphNdxSet" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@index", "@set"]},
1754
- "id" => {"@id" => "ex:idSet", "@container" => "@id"},
1755
- "idSet" => {"@id" => "ex:id", "@container" => ["@id", "@set"]},
1756
- "language" => {"@id" => "ex:language", "@container" => "@language"},
1757
- "langSet" => {"@id" => "ex:languageSet", "@container" => ["@language", "@set"]},
1758
- "list" => {"@id" => "ex:list", "@container" => "@list"},
1759
- "ndx" => {"@id" => "ex:ndx", "@container" => "@index"},
1760
- "ndxSet" => {"@id" => "ex:ndxSet", "@container" => ["@index", "@set"]},
1761
- "set" => {"@id" => "ex:set", "@container" => "@set"},
1762
- "type" => {"@id" => "ex:type", "@container" => "@type"},
1763
- "typeSet" => {"@id" => "ex:typeSet", "@container" => ["@type", "@set"]},
1764
- })
1765
- logger.clear
1766
- ctx
1767
- }
1768
-
1769
- it "uses TermDefinition" do
1770
- {
1771
- "ex" => Set.new,
1772
- "graph" => Set["@graph"],
1773
- "graphSet" => Set["@graph"],
1774
- "graphId" => Set["@graph", "@id"],
1775
- "graphIdSet" => Set["@graph", "@id"],
1776
- "graphNdx" => Set["@graph", "@index"],
1777
- "graphNdxSet" => Set["@graph", "@index"],
1778
- "id" => Set['@id'],
1779
- "idSet" => Set['@id'],
1780
- "language" => Set['@language'],
1781
- "langSet" => Set['@language'],
1782
- "list" => Set['@list'],
1783
- "ndx" => Set['@index'],
1784
- "ndxSet" => Set['@index'],
1785
- "set" => Set.new,
1786
- "type" => Set['@type'],
1787
- "typeSet" => Set['@type'],
1788
- }.each do |defn, container|
1789
- expect(subject.container(subject.term_definitions[defn])).to eq container
1790
- end
1791
- end
1792
-
1793
- it "#as_array" do
1794
- {
1795
- "ex" => false,
1796
- "graph" => false,
1797
- "graphSet" => true,
1798
- "graphId" => false,
1799
- "graphIdSet" => true,
1800
- "graphNdx" => false,
1801
- "graphNdxSet" => true,
1802
- "id" => false,
1803
- "idSet" => true,
1804
- "language" => false,
1805
- "langSet" => true,
1806
- "list" => true,
1807
- "ndx" => false,
1808
- "ndxSet" => true,
1809
- "set" => true,
1810
- "type" => false,
1811
- "typeSet" => true,
1812
- }.each do |defn, as_array|
1813
- expect(subject.as_array?(subject.term_definitions[defn])).to eq as_array
1814
- end
1815
- end
1816
-
1817
- it "uses array" do
1818
- {
1819
- "ex" => Set.new,
1820
- "graph" => Set["@graph"],
1821
- "graphSet" => Set["@graph"],
1822
- "graphId" => Set["@graph", "@id"],
1823
- "graphIdSet" => Set["@graph", "@id"],
1824
- "graphNdx" => Set["@graph", "@index"],
1825
- "graphNdxSet" => Set["@graph", "@index"],
1826
- "id" => Set['@id'],
1827
- "idSet" => Set['@id'],
1828
- "language" => Set['@language'],
1829
- "langSet" => Set['@language'],
1830
- "list" => Set['@list'],
1831
- "ndx" => Set['@index'],
1832
- "ndxSet" => Set['@index'],
1833
- "set" => Set.new,
1834
- "type" => Set['@type'],
1835
- "typeSet" => Set['@type'],
1836
- }.each do |defn, container|
1837
- expect(subject.container(defn)).to eq container
1838
- end
1839
- end
1840
- end
1841
-
1842
- describe "#language" do
1843
- subject {
1844
- ctx = context.parse({
1845
- "ex" => "http://example.org/",
1846
- "nil" => {"@id" => "ex:nil", "@language" => nil},
1847
- "en" => {"@id" => "ex:en", "@language" => "en"},
1848
- })
1849
- logger.clear
1850
- ctx
1851
- }
1852
- it "uses TermDefinition" do
1853
- expect(subject.language(subject.term_definitions['ex'])).to be_falsey
1854
- expect(subject.language(subject.term_definitions['nil'])).to be_falsey
1855
- expect(subject.language(subject.term_definitions['en'])).to eq 'en'
1856
- end
1857
-
1858
- it "uses string" do
1859
- expect(subject.language('ex')).to be_falsey
1860
- expect(subject.language('nil')).to be_falsey
1861
- expect(subject.language('en')).to eq 'en'
1862
- end
1863
- end
1864
-
1865
- describe "#reverse?" do
1866
- subject {
1867
- ctx = context.parse({
1868
- "ex" => "http://example.org/",
1869
- "reverse" => {"@reverse" => "ex:reverse"},
1870
- })
1871
- logger.clear
1872
- ctx
1873
- }
1874
- it "uses TermDefinition" do
1875
- expect(subject.reverse?(subject.term_definitions['ex'])).to be_falsey
1876
- expect(subject.reverse?(subject.term_definitions['reverse'])).to be_truthy
1877
- end
1878
-
1879
- it "uses string" do
1880
- expect(subject.reverse?('ex')).to be_falsey
1881
- expect(subject.reverse?('reverse')).to be_truthy
1882
- end
1883
- end
1884
-
1885
- describe "#nest" do
1886
- subject {
1887
- ctx = context.parse({
1888
- "ex" => "http://example.org/",
1889
- "nest" => {"@id" => "ex:nest", "@nest" => "@nest"},
1890
- "nest2" => {"@id" => "ex:nest2", "@nest" => "nest-alias"},
1891
- "nest-alias" => "@nest"
1892
- })
1893
- logger.clear
1894
- ctx
1895
- }
1896
-
1897
- it "uses term" do
1898
- {
1899
- "ex" => nil,
1900
- "nest" => "@nest",
1901
- "nest2" => "nest-alias",
1902
- "nest-alias" => nil,
1903
- }.each do |defn, nest|
1904
- expect(subject.nest(defn)).to eq nest
1905
- end
1906
- end
1907
-
1908
- context "detects error" do
1909
- it "does not allow a keyword other than @nest for the value of @nest" do
1910
- expect {
1911
- context.parse({"no-keyword-nest" => {"@id" => "http://example/f", "@nest" => "@id"}})
1912
- }.to raise_error JSON::LD::JsonLdError::InvalidNestValue
1913
- end
1914
-
1915
- it "does not allow @nest with @reverse" do
1916
- expect {
1917
- context.parse({"no-reverse-nest" => {"@reverse" => "http://example/f", "@nest" => "@nest"}})
1918
- }.to raise_error JSON::LD::JsonLdError::InvalidReverseProperty
1919
- end
1920
- end
1921
- end
1922
-
1923
- describe "#reverse_term" do
1924
- subject {
1925
- ctx = context.parse({
1926
- "ex" => "http://example.org/",
1927
- "reverse" => {"@reverse" => "ex"},
1928
- })
1929
- logger.clear
1930
- ctx
1931
- }
1932
- it "uses TermDefinition" do
1933
- expect(subject.reverse_term(subject.term_definitions['ex'])).to eql subject.term_definitions['reverse']
1934
- expect(subject.reverse_term(subject.term_definitions['reverse'])).to eql subject.term_definitions['ex']
1935
- end
1936
-
1937
- it "uses string" do
1938
- expect(subject.reverse_term('ex')).to eql subject.term_definitions['reverse']
1939
- expect(subject.reverse_term('reverse')).to eql subject.term_definitions['ex']
1940
- end
1941
- end
1942
-
1943
- describe "protected contexts" do
1944
- it "seals a term with @protected true" do
1945
- ctx = context.parse({
1946
- "protected" => {"@id" => "http://example.com/protected", "@protected" => true},
1947
- "unprotected" => {"@id" => "http://example.com/unprotected"},
1948
- })
1949
- expect(ctx.term_definitions["protected"]).to be_protected
1950
- expect(ctx.term_definitions["unprotected"]).not_to be_protected
1951
- end
1952
-
1953
- it "seals all term with @protected true in context" do
1954
- ctx = context.parse({
1955
- "@protected" => true,
1956
- "protected" => {"@id" => "http://example.com/protected"},
1957
- "protected2" => {"@id" => "http://example.com/protected2"},
1958
- })
1959
- expect(ctx.term_definitions["protected"]).to be_protected
1960
- expect(ctx.term_definitions["protected2"]).to be_protected
1961
- end
1962
-
1963
- it "does not seal term with @protected: false when context is protected" do
1964
- ctx = context.parse({
1965
- "@protected" => true,
1966
- "protected" => {"@id" => "http://example.com/protected"},
1967
- "unprotected" => {"@id" => "http://example.com/unprotected", "@protected" => false},
1968
- })
1969
- expect(ctx.term_definitions["protected"]).to be_protected
1970
- expect(ctx.term_definitions["unprotected"]).not_to be_protected
1971
- end
1972
-
1973
- it "does not error when redefining an identical term" do
1974
- c = {
1975
- "protected" => {"@id" => "http://example.com/protected", "@protected" => true}
1976
- }
1977
- ctx = context.parse(c)
1978
-
1979
- expect {ctx.parse(c)}.not_to raise_error
1980
- end
1981
-
1982
- it "errors when redefining a protected term" do
1983
- ctx = context.parse({
1984
- "protected" => {"@id" => "http://example.com/protected", "@protected" => true}
1985
- })
1986
-
1987
- expect {ctx.parse({"protected" => "http://example.com/different"})}.to raise_error(JSON::LD::JsonLdError::ProtectedTermRedefinition)
1988
- end
1989
-
1990
- it "errors when clearing a context having protected terms" do
1991
- ctx = context.parse({
1992
- "protected" => {"@id" => "http://example.com/protected", "@protected" => true}
1993
- })
1994
-
1995
- expect {ctx.parse(nil)}.to raise_error(JSON::LD::JsonLdError::InvalidContextNullification)
1996
- end
1997
- end
1998
-
1999
- describe JSON::LD::Context::TermDefinition do
2000
- context "with nothing" do
2001
- subject {described_class.new("term")}
2002
- its(:term) {is_expected.to eq "term"}
2003
- its(:id) {is_expected.to be_nil}
2004
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term"))}
2005
- end
2006
-
2007
- context "with id" do
2008
- subject {described_class.new("term", id: "http://example.org/term")}
2009
- its(:term) {is_expected.to eq "term"}
2010
- its(:id) {is_expected.to eq "http://example.org/term"}
2011
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", id: "http://example.org/term"))}
2012
- end
2013
-
2014
- context "with type_mapping" do
2015
- subject {described_class.new("term", type_mapping: "http://example.org/type")}
2016
- its(:type_mapping) {is_expected.to eq "http://example.org/type"}
2017
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", type_mapping: "http://example.org/type"))}
2018
- end
2019
-
2020
- context "with container_mapping @set" do
2021
- subject {described_class.new("term", container_mapping: "@set")}
2022
- its(:container_mapping) {is_expected.to be_empty}
2023
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: "@set"))}
2024
- end
2025
-
2026
- context "with container_mapping @id @set" do
2027
- subject {described_class.new("term", container_mapping: %w(@id @set))}
2028
- its(:container_mapping) {is_expected.to eq Set['@id']}
2029
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: ["@id", "@set"]))}
2030
- end
2031
-
2032
- context "with container_mapping @list" do
2033
- subject {described_class.new("term", container_mapping: "@list")}
2034
- its(:container_mapping) {is_expected.to eq Set['@list']}
2035
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: "@list"))}
2036
- end
2037
-
2038
- context "with language_mapping" do
2039
- subject {described_class.new("term", language_mapping: "en")}
2040
- its(:language_mapping) {is_expected.to eq "en"}
2041
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", language_mapping: "en"))}
2042
- end
2043
-
2044
- context "with reverse_property" do
2045
- subject {described_class.new("term", reverse_property: true)}
2046
- its(:reverse_property) {is_expected.to be_truthy}
2047
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", reverse_property: true))}
2048
- end
2049
-
2050
- context "with simple" do
2051
- subject {described_class.new("term", simple: true)}
2052
- its(:simple) {is_expected.to be_truthy}
2053
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", simple: true))}
2054
- end
2055
- end
2056
- end