json-ld 3.2.3 → 3.2.5

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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/json/ld/api.rb +807 -764
  4. data/lib/json/ld/compact.rb +304 -304
  5. data/lib/json/ld/conneg.rb +179 -161
  6. data/lib/json/ld/context.rb +2080 -1945
  7. data/lib/json/ld/expand.rb +745 -666
  8. data/lib/json/ld/extensions.rb +14 -13
  9. data/lib/json/ld/flatten.rb +257 -247
  10. data/lib/json/ld/format.rb +202 -194
  11. data/lib/json/ld/frame.rb +525 -502
  12. data/lib/json/ld/from_rdf.rb +224 -166
  13. data/lib/json/ld/html/nokogiri.rb +123 -121
  14. data/lib/json/ld/html/rexml.rb +151 -147
  15. data/lib/json/ld/reader.rb +107 -100
  16. data/lib/json/ld/resource.rb +224 -205
  17. data/lib/json/ld/streaming_reader.rb +574 -507
  18. data/lib/json/ld/streaming_writer.rb +93 -92
  19. data/lib/json/ld/to_rdf.rb +171 -167
  20. data/lib/json/ld/utils.rb +270 -264
  21. data/lib/json/ld/version.rb +24 -14
  22. data/lib/json/ld/writer.rb +334 -311
  23. data/lib/json/ld.rb +103 -96
  24. metadata +78 -209
  25. data/spec/api_spec.rb +0 -132
  26. data/spec/compact_spec.rb +0 -3482
  27. data/spec/conneg_spec.rb +0 -373
  28. data/spec/context_spec.rb +0 -2036
  29. data/spec/expand_spec.rb +0 -4496
  30. data/spec/flatten_spec.rb +0 -1203
  31. data/spec/format_spec.rb +0 -115
  32. data/spec/frame_spec.rb +0 -2498
  33. data/spec/from_rdf_spec.rb +0 -1005
  34. data/spec/matchers.rb +0 -20
  35. data/spec/rdfstar_spec.rb +0 -25
  36. data/spec/reader_spec.rb +0 -883
  37. data/spec/resource_spec.rb +0 -76
  38. data/spec/spec_helper.rb +0 -281
  39. data/spec/streaming_reader_spec.rb +0 -237
  40. data/spec/streaming_writer_spec.rb +0 -145
  41. data/spec/suite_compact_spec.rb +0 -22
  42. data/spec/suite_expand_spec.rb +0 -36
  43. data/spec/suite_flatten_spec.rb +0 -34
  44. data/spec/suite_frame_spec.rb +0 -29
  45. data/spec/suite_from_rdf_spec.rb +0 -22
  46. data/spec/suite_helper.rb +0 -411
  47. data/spec/suite_html_spec.rb +0 -22
  48. data/spec/suite_http_spec.rb +0 -35
  49. data/spec/suite_remote_doc_spec.rb +0 -22
  50. data/spec/suite_to_rdf_spec.rb +0 -30
  51. data/spec/support/extensions.rb +0 -44
  52. data/spec/test-files/test-1-compacted.jsonld +0 -10
  53. data/spec/test-files/test-1-context.jsonld +0 -7
  54. data/spec/test-files/test-1-expanded.jsonld +0 -5
  55. data/spec/test-files/test-1-input.jsonld +0 -10
  56. data/spec/test-files/test-1-rdf.ttl +0 -8
  57. data/spec/test-files/test-2-compacted.jsonld +0 -20
  58. data/spec/test-files/test-2-context.jsonld +0 -7
  59. data/spec/test-files/test-2-expanded.jsonld +0 -16
  60. data/spec/test-files/test-2-input.jsonld +0 -20
  61. data/spec/test-files/test-2-rdf.ttl +0 -14
  62. data/spec/test-files/test-3-compacted.jsonld +0 -11
  63. data/spec/test-files/test-3-context.jsonld +0 -8
  64. data/spec/test-files/test-3-expanded.jsonld +0 -10
  65. data/spec/test-files/test-3-input.jsonld +0 -11
  66. data/spec/test-files/test-3-rdf.ttl +0 -8
  67. data/spec/test-files/test-4-compacted.jsonld +0 -10
  68. data/spec/test-files/test-4-context.jsonld +0 -7
  69. data/spec/test-files/test-4-expanded.jsonld +0 -6
  70. data/spec/test-files/test-4-input.jsonld +0 -10
  71. data/spec/test-files/test-4-rdf.ttl +0 -5
  72. data/spec/test-files/test-5-compacted.jsonld +0 -13
  73. data/spec/test-files/test-5-context.jsonld +0 -7
  74. data/spec/test-files/test-5-expanded.jsonld +0 -9
  75. data/spec/test-files/test-5-input.jsonld +0 -13
  76. data/spec/test-files/test-5-rdf.ttl +0 -7
  77. data/spec/test-files/test-6-compacted.jsonld +0 -10
  78. data/spec/test-files/test-6-context.jsonld +0 -7
  79. data/spec/test-files/test-6-expanded.jsonld +0 -10
  80. data/spec/test-files/test-6-input.jsonld +0 -10
  81. data/spec/test-files/test-6-rdf.ttl +0 -6
  82. data/spec/test-files/test-7-compacted.jsonld +0 -23
  83. data/spec/test-files/test-7-context.jsonld +0 -4
  84. data/spec/test-files/test-7-expanded.jsonld +0 -20
  85. data/spec/test-files/test-7-input.jsonld +0 -23
  86. data/spec/test-files/test-7-rdf.ttl +0 -14
  87. data/spec/test-files/test-8-compacted.jsonld +0 -34
  88. data/spec/test-files/test-8-context.jsonld +0 -11
  89. data/spec/test-files/test-8-expanded.jsonld +0 -24
  90. data/spec/test-files/test-8-frame.jsonld +0 -18
  91. data/spec/test-files/test-8-framed.jsonld +0 -25
  92. data/spec/test-files/test-8-input.jsonld +0 -30
  93. data/spec/test-files/test-8-rdf.ttl +0 -15
  94. data/spec/test-files/test-9-compacted.jsonld +0 -20
  95. data/spec/test-files/test-9-context.jsonld +0 -13
  96. data/spec/test-files/test-9-expanded.jsonld +0 -14
  97. data/spec/test-files/test-9-input.jsonld +0 -12
  98. data/spec/to_rdf_spec.rb +0 -1551
  99. data/spec/writer_spec.rb +0 -427
data/spec/context_spec.rb DELETED
@@ -1,2036 +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
- expect(subject.to_rb).not_to be_empty
659
- end
660
-
661
- it "@vocab" do
662
- subject.vocab = "http://example.com/"
663
- expect(subject.serialize).to produce({
664
- "@context" => {
665
- "@vocab" => "http://example.com/"
666
- }
667
- }, logger)
668
- expect(subject.to_rb).not_to be_empty
669
- end
670
-
671
- it "term mappings" do
672
- c = subject.
673
- parse({'foo' => "http://example.com/"})
674
- expect(c.serialize).to produce({
675
- "@context" => {
676
- "foo" => "http://example.com/"
677
- }
678
- }, logger)
679
- expect(c.to_rb).not_to be_empty
680
- end
681
-
682
- it "@context" do
683
- expect(subject.parse({
684
- "foo" => {"@id" => "http://example.com/", "@context" => {"bar" => "http://example.com/baz"}}
685
- }).
686
- serialize).to produce({
687
- "@context" => {
688
- "foo" => {
689
- "@id" => "http://example.com/",
690
- "@context" => {"bar" => "http://example.com/baz"}
691
- }
692
- }
693
- }, logger)
694
- end
695
-
696
- it "@type with dependent prefixes in a single context" do
697
- expect(subject.parse({
698
- 'xsd' => "http://www.w3.org/2001/XMLSchema#",
699
- 'homepage' => {'@id' => RDF::Vocab::FOAF.homepage.to_s, '@type' => '@id'}
700
- }).
701
- serialize).to produce({
702
- "@context" => {
703
- "xsd" => RDF::XSD.to_uri.to_s,
704
- "homepage" => {"@id" => RDF::Vocab::FOAF.homepage.to_s, "@type" => "@id"}
705
- }
706
- }, logger)
707
- end
708
-
709
- it "@list with @id definition in a single context" do
710
- expect(subject.parse({
711
- 'knows' => {'@id' => RDF::Vocab::FOAF.knows.to_s, '@container' => '@list'}
712
- }).
713
- serialize).to produce({
714
- "@context" => {
715
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
716
- }
717
- }, logger)
718
- end
719
-
720
- it "@set with @id definition in a single context" do
721
- expect(subject.parse({
722
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@set"}
723
- }).
724
- serialize).to produce({
725
- "@context" => {
726
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@set"}
727
- }
728
- }, logger)
729
- end
730
-
731
- it "@language with @id definition in a single context" do
732
- expect(subject.parse({
733
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "en"}
734
- }).
735
- serialize).to produce({
736
- "@context" => {
737
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "en"}
738
- }
739
- }, logger)
740
- end
741
-
742
- it "@language with @id definition in a single context and equivalent default" do
743
- expect(subject.parse({
744
- "@language" => 'en',
745
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => 'en'}
746
- }).
747
- serialize).to produce({
748
- "@context" => {
749
- "@language" => 'en',
750
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => 'en'}
751
- }
752
- }, logger)
753
- end
754
-
755
- it "@language with @id definition in a single context and different default" do
756
- expect(subject.parse({
757
- "@language" => 'en',
758
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "de"}
759
- }).
760
- serialize).to produce({
761
- "@context" => {
762
- "@language" => 'en',
763
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "de"}
764
- }
765
- }, logger)
766
- end
767
-
768
- it "null @language with @id definition in a single context and default" do
769
- expect(subject.parse({
770
- "@language" => 'en',
771
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => nil}
772
- }).
773
- serialize).to produce({
774
- "@context" => {
775
- "@language" => 'en',
776
- "name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => nil}
777
- }
778
- }, logger)
779
- end
780
-
781
- it "prefix with @type and @list" do
782
- expect(subject.parse({
783
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
784
- }).
785
- serialize).to produce({
786
- "@context" => {
787
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
788
- }
789
- }, logger)
790
- end
791
-
792
- it "prefix with @type and @set" do
793
- expect(subject.parse({
794
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
795
- }).
796
- serialize).to produce({
797
- "@context" => {
798
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
799
- }
800
- }, logger)
801
- end
802
-
803
- it "prefix with @type @json" do
804
- expect(subject.parse({
805
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@json"}
806
- }).
807
- serialize).to produce({
808
- "@context" => {
809
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@json"}
810
- }
811
- }, logger)
812
- end
813
-
814
- it "Compact IRI with @type" do
815
- expect(subject.parse({
816
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
817
- "foaf:knows" => {
818
- "@container" => "@list"
819
- }
820
- }).
821
- serialize).to produce({
822
- "@context" => {
823
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
824
- "foaf:knows" => {
825
- "@container" => "@list"
826
- }
827
- }
828
- }, logger)
829
- end
830
-
831
- it "does not use aliased @id in key position" do
832
- expect(subject.parse({
833
- "id" => "@id",
834
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
835
- }).
836
- serialize).to produce({
837
- "@context" => {
838
- "id" => "@id",
839
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
840
- }
841
- }, logger)
842
- end
843
-
844
- it "does not use aliased @id in value position" do
845
- expect(subject.parse({
846
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
847
- "id" => "@id",
848
- "foaf:homepage" => {
849
- "@type" => "@id"
850
- }
851
- }).
852
- serialize).to produce({
853
- "@context" => {
854
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
855
- "id" => "@id",
856
- "foaf:homepage" => {
857
- "@type" => "@id"
858
- }
859
- }
860
- }, logger)
861
- end
862
-
863
- it "does not use aliased @type" do
864
- expect(subject.parse({
865
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
866
- "type" => "@type",
867
- "foaf:homepage" => {"@type" => "@id"}
868
- }).
869
- serialize).to produce({
870
- "@context" => {
871
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
872
- "type" => "@type",
873
- "foaf:homepage" => {"@type" => "@id"}
874
- }
875
- }, logger)
876
- end
877
-
878
- it "does not use aliased @container" do
879
- expect(subject.parse({
880
- "container" => "@container",
881
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
882
- }).
883
- serialize).to produce({
884
- "@context" => {
885
- "container" => "@container",
886
- "knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
887
- }
888
- }, logger)
889
- end
890
-
891
- it "compacts IRIs to Compact IRIs" do
892
- expect(subject.parse({
893
- "ex" => 'http://example.org/',
894
- "term" => {"@id" => "ex:term", "@type" => "ex:datatype"}
895
- }).
896
- serialize).to produce({
897
- "@context" => {
898
- "ex" => 'http://example.org/',
899
- "term" => {"@id" => "ex:term", "@type" => "ex:datatype"}
900
- }
901
- }, logger)
902
- end
903
-
904
- it "compacts IRIs using @vocab" do
905
- expect(subject.parse({
906
- "@vocab" => 'http://example.org/',
907
- "term" => {"@id" => "http://example.org/term", "@type" => "datatype"}
908
- }).
909
- serialize).to produce({
910
- "@context" => {
911
- "@vocab" => 'http://example.org/',
912
- "term" => {"@type" => "datatype"}
913
- }
914
- }, logger)
915
- end
916
-
917
- context "invalid term definitions" do
918
- {
919
- "empty term": {
920
- input: {"" => "http://blank-term/"}
921
- },
922
- "extra key": {
923
- input: {"foo" => {"@id" => "http://example.com/foo", "@baz" => "foobar"}}
924
- }
925
- }.each do |title, params|
926
- it title do
927
- expect {subject.parse(params[:input])}.to raise_error(JSON::LD::JsonLdError::InvalidTermDefinition)
928
- end
929
- end
930
- end
931
-
932
- end
933
-
934
- describe "#base=" do
935
- subject {
936
- context.parse({
937
- '@base' => 'http://base/',
938
- '@vocab' => 'http://vocab/',
939
- 'ex' => 'http://example.org/',
940
- '_' => 'http://underscore/'
941
- })
942
- }
943
-
944
- it "sets new base uri given an absolute uri" do
945
- subject.base = "http://example.org/"
946
- expect(subject.base).to eql RDF::URI("http://example.org/")
947
- end
948
-
949
- it "sets relative URI" do
950
- subject.base = "foo/bar"
951
- expect(subject.base).to eql RDF::URI("http://base/foo/bar")
952
- end
953
- end
954
-
955
- describe "#vocab=" do
956
- subject {
957
- context.parse({
958
- '@base' => 'http://base/resource',
959
- })
960
- }
961
-
962
- it "sets vocab from absolute iri" do
963
- subject.vocab = "http://example.org/"
964
- expect(subject.vocab).to eql RDF::URI("http://example.org/")
965
- end
966
-
967
- it "sets vocab from empty string" do
968
- subject.vocab = ""
969
- expect(subject.vocab).to eql RDF::URI("http://base/resource")
970
- end
971
-
972
- it "sets vocab to blank node (with deprecation)" do
973
- expect do
974
- subject.vocab = "_:bn"
975
- end.to write("[DEPRECATION]").to(:error)
976
- expect(subject.vocab).to eql "_:bn"
977
- end
978
-
979
- it "sets vocab from relative IRI" do
980
- subject.vocab = "relative#"
981
- expect(subject.vocab).to eql RDF::URI("http://base/relative#")
982
- end
983
-
984
- it "sets vocab from relative IRI given an existing vocab" do
985
- subject.vocab = "http://example.org/."
986
- subject.vocab = "relative#"
987
- expect(subject.vocab).to eql RDF::URI("http://example.org/.relative#")
988
- end
989
-
990
- it "sets vocab from relative IRI given an existing vocab which is also relative" do
991
- subject.vocab = "/rel1"
992
- subject.vocab = "rel2#"
993
- expect(subject.vocab).to eql RDF::URI("http://base/rel1rel2#")
994
- end
995
- end
996
-
997
- describe "#expand_iri" do
998
- subject {
999
- context.parse({
1000
- '@base' => 'http://base/base',
1001
- '@vocab' => 'http://vocab/',
1002
- 'ex' => 'http://example.org/',
1003
- '_' => 'http://underscore/'
1004
- })
1005
- }
1006
-
1007
- it "bnode" do
1008
- expect(subject.expand_iri("_:a")).to be_a(RDF::Node)
1009
- end
1010
-
1011
- context "keywords" do
1012
- %w(id type).each do |kw|
1013
- it "expands #{kw} to @#{kw}" do
1014
- subject.set_mapping(kw, "@#{kw}")
1015
- expect(subject.expand_iri(kw, vocab: true)).to produce("@#{kw}", logger)
1016
- end
1017
- end
1018
- end
1019
-
1020
- context "relative IRI" do
1021
- context "with no options" do
1022
- {
1023
- "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
1024
- "term" => ["ex", RDF::URI("ex")],
1025
- "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
1026
- "#frag" => ["#frag", RDF::URI("#frag")],
1027
- "#frag:2" => ["#frag:2", RDF::URI("#frag:2")],
1028
- "keyword" => ["@type", "@type"],
1029
- "unmapped" => ["foo", RDF::URI("foo")],
1030
- "relative" => ["foo/bar", RDF::URI("foo/bar")],
1031
- "dotseg" => ["../foo/bar", RDF::URI("../foo/bar")],
1032
- "empty term" => ["", RDF::URI("")],
1033
- "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
1034
- "absolute IRI looking like a Compact IRI" =>
1035
- ["foo:bar", RDF::URI("foo:bar")],
1036
- "bnode" => ["_:t0", RDF::Node("t0")],
1037
- "_" => ["_", RDF::URI("_")],
1038
- "@" => ["@", RDF::URI("@")],
1039
- }.each do |title, (input, result)|
1040
- it title do
1041
- expect(subject.expand_iri(input)).to produce(result, logger)
1042
- end
1043
- end
1044
- end
1045
-
1046
- context "with base IRI" do
1047
- {
1048
- "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
1049
- "term" => ["ex", RDF::URI("http://base/ex")],
1050
- "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
1051
- "#frag" => ["#frag", RDF::URI("http://base/base#frag")],
1052
- "#frag:2" => ["#frag:2", RDF::URI("http://base/base#frag:2")],
1053
- "keyword" => ["@type", "@type"],
1054
- "unmapped" => ["foo", RDF::URI("http://base/foo")],
1055
- "relative" => ["foo/bar", RDF::URI("http://base/foo/bar")],
1056
- "dotseg" => ["../foo/bar", RDF::URI("http://base/foo/bar")],
1057
- "empty term" => ["", RDF::URI("http://base/base")],
1058
- "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
1059
- "absolute IRI looking like a compact IRI" =>
1060
- ["foo:bar", RDF::URI("foo:bar")],
1061
- "bnode" => ["_:t0", RDF::Node("t0")],
1062
- "_" => ["_", RDF::URI("http://base/_")],
1063
- "@" => ["@", RDF::URI("http://base/@")],
1064
- }.each do |title, (input, result)|
1065
- it title do
1066
- expect(subject.expand_iri(input, documentRelative: true)).to produce(result, logger)
1067
- end
1068
- end
1069
- end
1070
-
1071
- context "@vocab" do
1072
- {
1073
- "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
1074
- "term" => ["ex", RDF::URI("http://example.org/")],
1075
- "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
1076
- "#frag" => ["#frag", RDF::URI("http://vocab/#frag")],
1077
- "#frag:2" => ["#frag:2", RDF::URI("http://vocab/#frag:2")],
1078
- "keyword" => ["@type", "@type"],
1079
- "unmapped" => ["foo", RDF::URI("http://vocab/foo")],
1080
- "relative" => ["foo/bar", RDF::URI("http://vocab/foo/bar")],
1081
- "dotseg" => ["../foo/bar", RDF::URI("http://vocab/../foo/bar")],
1082
- "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
1083
- "absolute IRI looking like a compact IRI" =>
1084
- ["foo:bar", RDF::URI("foo:bar")],
1085
- "bnode" => ["_:t0", RDF::Node("t0")],
1086
- "_" => ["_", RDF::URI("http://underscore/")],
1087
- "@" => ["@", RDF::URI("http://vocab/@")],
1088
- }.each do |title, (input, result)|
1089
- it title do
1090
- expect(subject.expand_iri(input, vocab: true)).to produce(result, logger)
1091
- end
1092
- end
1093
-
1094
- context "set to ''" do
1095
- subject {
1096
- context.parse({
1097
- '@base' => 'http://base/base',
1098
- '@vocab' => '',
1099
- 'ex' => 'http://example.org/',
1100
- '_' => 'http://underscore/'
1101
- })
1102
- }
1103
-
1104
- {
1105
- "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
1106
- "term" => ["ex", RDF::URI("http://example.org/")],
1107
- "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
1108
- "#frag" => ["#frag", RDF::URI("http://base/base#frag")],
1109
- "#frag:2" => ["#frag:2", RDF::URI("http://base/base#frag:2")],
1110
- "keyword" => ["@type", "@type"],
1111
- "unmapped" => ["foo", RDF::URI("http://base/basefoo")],
1112
- "relative" => ["foo/bar", RDF::URI("http://base/basefoo/bar")],
1113
- "dotseg" => ["../foo/bar", RDF::URI("http://base/base../foo/bar")],
1114
- "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
1115
- "absolute IRI looking like a compact IRI" =>
1116
- ["foo:bar", RDF::URI("foo:bar")],
1117
- "bnode" => ["_:t0", RDF::Node("t0")],
1118
- "_" => ["_", RDF::URI("http://underscore/")],
1119
- }.each do |title, (input, result)|
1120
- it title do
1121
- expect(subject.expand_iri(input, vocab: true)).to produce(result, logger)
1122
- end
1123
- end
1124
- end
1125
-
1126
- it "expand-0110" do
1127
- ctx = JSON::LD::Context.parse({
1128
- "@base" => "http://example.com/some/deep/directory/and/file/",
1129
- "@vocab" => "/relative"
1130
- })
1131
- expect(ctx.expand_iri("#fragment-works", vocab: true)).to produce("http://example.com/relative#fragment-works", logger)
1132
- end
1133
- end
1134
- end
1135
- end
1136
-
1137
- describe "#compact_iri" do
1138
- subject {
1139
- c = context.parse({
1140
- '@base' => 'http://base/',
1141
- "xsd" => "http://www.w3.org/2001/XMLSchema#",
1142
- 'ex' => 'http://example.org/',
1143
- '_' => 'http://underscore/',
1144
- 'rex' => {'@reverse' => "ex"},
1145
- 'lex' => {'@id' => 'ex', '@language' => 'en'},
1146
- 'tex' => {'@id' => 'ex', '@type' => 'xsd:string'},
1147
- 'exp' => {'@id' => 'ex:pert'},
1148
- 'experts' => {'@id' => 'ex:perts'},
1149
- })
1150
- logger.clear
1151
- c
1152
- }
1153
-
1154
- {
1155
- "nil" => [nil, nil],
1156
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1157
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1158
- "unmapped" => ["foo", "foo"],
1159
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1160
- "relative" => ["foo/bar", "http://base/foo/bar"],
1161
- "odd Compact IRI"=>["ex:perts", "http://example.org/perts"]
1162
- }.each do |title, (result, input)|
1163
- it title do
1164
- if result.is_a?(Class)
1165
- expect {subject.compact_iri(input)}.to raise_error(result)
1166
- else
1167
- expect(subject.compact_iri(input)).to produce(result, logger)
1168
- end
1169
- end
1170
- end
1171
-
1172
- context "with :vocab option" do
1173
- {
1174
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1175
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1176
- "keyword" => ["@type", "@type"],
1177
- "unmapped" => ["foo", "foo"],
1178
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1179
- "relative" => ["http://base/foo/bar", "http://base/foo/bar"],
1180
- "odd Compact IRI"=> ["experts", "http://example.org/perts"]
1181
- }.each do |title, (result, input)|
1182
- it title do
1183
- if result.is_a?(Class)
1184
- expect {subject.compact_iri(input, vocab: true)}.to raise_error(result)
1185
- else
1186
- expect(subject.compact_iri(input, vocab: true)).to produce(result, logger)
1187
- end
1188
- end
1189
- end
1190
- end
1191
-
1192
- context "with @vocab" do
1193
- before(:each) { subject.vocab = "http://example.org/"}
1194
-
1195
- {
1196
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1197
- "prefix:suffix" => ["suffix", "http://example.org/suffix"],
1198
- "keyword" => ["@type", "@type"],
1199
- "unmapped" => ["foo", "foo"],
1200
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1201
- "relative" => ["http://base/foo/bar", "http://base/foo/bar"],
1202
- "odd Compact IRI"=> ["experts", "http://example.org/perts"]
1203
- }.each do |title, (result, input)|
1204
- it title do
1205
- if result.is_a?(Class)
1206
- expect {subject.compact_iri(input, vocab: true)}.to raise_error(result)
1207
- else
1208
- expect(subject.compact_iri(input, vocab: true)).to produce(result, logger)
1209
- end
1210
- end
1211
- end
1212
-
1213
- it "does not use @vocab if it would collide with a term" do
1214
- subject.set_mapping("name", "http://xmlns.com/foaf/0.1/name")
1215
- subject.set_mapping("ex", nil)
1216
- expect(subject.compact_iri("http://example.org/name", vocab: true)).
1217
- not_to produce("name", logger)
1218
- end
1219
-
1220
- context "with @vocab: relative" do
1221
- before(:each) {
1222
- subject.vocab = nil
1223
- subject.base = 'http://base/base'
1224
- }
1225
-
1226
- {
1227
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1228
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1229
- "keyword" => ["@type", "@type"],
1230
- "unmapped" => ["foo", "foo"],
1231
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1232
- "relative" => ["http://base/foo/bar", "http://base/foo/bar"],
1233
- "odd Compact IRI"=> ["experts", "http://example.org/perts"]
1234
- }.each do |title, (result, input)|
1235
- it title do
1236
- if result.is_a?(Class)
1237
- expect {subject.compact_iri(input, vocab: true)}.to raise_error(result)
1238
- else
1239
- expect(subject.compact_iri(input, vocab: true)).to produce(result, logger)
1240
- end
1241
- end
1242
- end
1243
- end
1244
- end
1245
-
1246
- context "with value" do
1247
- let(:ctx) do
1248
- c = subject.parse({
1249
- "xsd" => RDF::XSD.to_s,
1250
- "plain" => "http://example.com/plain",
1251
- "lang" => {"@id" => "http://example.com/lang", "@language" => "en"},
1252
- "dir" => {"@id" => "http://example.com/dir", "@direction" => "ltr"},
1253
- "langdir" => {"@id" => "http://example.com/langdir", "@language" => "en", "@direction" => "ltr"},
1254
- "bool" => {"@id" => "http://example.com/bool", "@type" => "xsd:boolean"},
1255
- "integer" => {"@id" => "http://example.com/integer", "@type" => "xsd:integer"},
1256
- "double" => {"@id" => "http://example.com/double", "@type" => "xsd:double"},
1257
- "date" => {"@id" => "http://example.com/date", "@type" => "xsd:date"},
1258
- "id" => {"@id" => "http://example.com/id", "@type" => "@id"},
1259
- 'graph' => {'@id' => 'http://example.com/graph', '@container' => '@graph'},
1260
- 'json' => {'@id' => 'http://example.com/json', '@type' => '@json'},
1261
-
1262
- "list_plain" => {"@id" => "http://example.com/plain", "@container" => "@list"},
1263
- "list_lang" => {"@id" => "http://example.com/lang", "@language" => "en", "@container" => "@list"},
1264
- "list_bool" => {"@id" => "http://example.com/bool", "@type" => "xsd:boolean", "@container" => "@list"},
1265
- "list_integer" => {"@id" => "http://example.com/integer", "@type" => "xsd:integer", "@container" => "@list"},
1266
- "list_double" => {"@id" => "http://example.com/double", "@type" => "xsd:double", "@container" => "@list"},
1267
- "list_date" => {"@id" => "http://example.com/date", "@type" => "xsd:date", "@container" => "@list"},
1268
- "list_id" => {"@id" => "http://example.com/id", "@type" => "@id", "@container" => "@list"},
1269
- "list_graph" => {"@id" => "http://example.com/graph", "@type" => "@id", "@container" => "@list"},
1270
-
1271
- "set_plain" => {"@id" => "http://example.com/plain", "@container" => "@set"},
1272
- "set_lang" => {"@id" => "http://example.com/lang", "@language" => "en", "@container" => "@set"},
1273
- "set_bool" => {"@id" => "http://example.com/bool", "@type" => "xsd:boolean", "@container" => "@set"},
1274
- "set_integer" => {"@id" => "http://example.com/integer", "@type" => "xsd:integer", "@container" => "@set"},
1275
- "set_double" => {"@id" => "http://example.com/double", "@type" => "xsd:double", "@container" => "@set"},
1276
- "set_date" => {"@id" => "http://example.com/date", "@type" => "xsd:date", "@container" => "@set"},
1277
- "set_id" => {"@id" => "http://example.com/id", "@type" => "@id", "@container" => "@set"},
1278
- 'set_graph' => {'@id' => 'http://example.com/graph', '@container' => ['@graph', '@set']},
1279
-
1280
- "map_lang" => {"@id" => "http://example.com/lang", "@container" => "@language"},
1281
-
1282
- "set_map_lang" => {"@id" => "http://example.com/lang", "@container" => ["@language", "@set"]},
1283
- })
1284
- logger.clear
1285
- c
1286
- end
1287
-
1288
- # Prefered sets and maps over non sets or maps
1289
- {
1290
- "set_plain" => [{"@value" => "foo"}],
1291
- "map_lang" => [{"@value" => "en", "@language" => "en"}],
1292
- "set_bool" => [{"@value" => "true", "@type" => "http://www.w3.org/2001/XMLSchema#boolean"}],
1293
- "set_integer" => [{"@value" => "1", "@type" => "http://www.w3.org/2001/XMLSchema#integer"}],
1294
- "set_id" => [{"@id" => "http://example.org/id"}],
1295
- "graph" => [{"@graph" => [{"@id" => "http://example.org/id"}]}],
1296
- 'json' => [{"@value" => {"some" => "json"}, "@type" => "@json"}],
1297
- 'dir' => [{"@value" => "dir", "@direction" => "ltr"}],
1298
- 'langdir' => [{"@value" => "lang dir", "@language" => "en", "@direction" => "ltr"}],
1299
- }.each do |prop, values|
1300
- context "uses #{prop}" do
1301
- values.each do |value|
1302
- it "for #{value.inspect}" do
1303
- expect(ctx.compact_iri("http://example.com/#{prop.sub(/^\w+_/, '')}", value: value, vocab: true)).
1304
- to produce(prop, logger)
1305
- end
1306
- end
1307
- end
1308
- end
1309
-
1310
- # @language and @type with @list
1311
- context "for @list" do
1312
- {
1313
- "list_plain" => [
1314
- [{"@value" => "foo"}],
1315
- [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => "baz"}],
1316
- [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => 1}],
1317
- [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => 1.1}],
1318
- [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => true}],
1319
- [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => 1}],
1320
- [{"@value" => "de", "@language" => "de"}, {"@value" => "jp", "@language" => "jp"}],
1321
- [{"@value" => true}], [{"@value" => false}],
1322
- [{"@value" => 1}], [{"@value" => 1.1}],
1323
- ],
1324
- "list_lang" => [[{"@value" => "en", "@language" => "en"}]],
1325
- "list_bool" => [[{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}]],
1326
- "list_integer" => [[{"@value" => "1", "@type" => RDF::XSD.integer.to_s}]],
1327
- "list_double" => [[{"@value" => "1", "@type" => RDF::XSD.double.to_s}]],
1328
- "list_date" => [[{"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}]],
1329
- }.each do |prop, values|
1330
- context "uses #{prop}" do
1331
- values.each do |value|
1332
- it "for #{{"@list" => value}.inspect}" do
1333
- expect(ctx.compact_iri("http://example.com/#{prop.sub(/^\w+_/, '')}", value: {"@list" => value}, vocab: true)).
1334
- to produce(prop, logger)
1335
- end
1336
- end
1337
- end
1338
- end
1339
- end
1340
- end
1341
-
1342
- context "Compact IRI compaction" do
1343
- {
1344
- "nil" => [nil, nil],
1345
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1346
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1347
- "unmapped" => ["foo", "foo"],
1348
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1349
- "relative" => ["foo/bar", "http://base/foo/bar"],
1350
- "odd Compact IRI"=> ["ex:perts", "http://example.org/perts"]
1351
- }.each do |title, (result, input)|
1352
- it title do
1353
- if result.is_a?(Class)
1354
- expect {subject.compact_iri(input)}.to raise_error(result)
1355
- else
1356
- expect(subject.compact_iri(input)).to produce(result, logger)
1357
- end
1358
- end
1359
- end
1360
-
1361
- context "and @vocab" do
1362
- before(:each) { subject.vocab = "http://example.org/"}
1363
-
1364
- {
1365
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
1366
- "prefix:suffix" => ["suffix", "http://example.org/suffix"],
1367
- "keyword" => ["@type", "@type"],
1368
- "unmapped" => ["foo", "foo"],
1369
- "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1370
- "relative" => ["http://base/foo/bar", "http://base/foo/bar"],
1371
- "odd Compact IRI"=> ["experts", "http://example.org/perts"]
1372
- }.each do |title, (result, input)|
1373
- it title do
1374
- if result.is_a?(Class)
1375
- expect {subject.compact_iri(input, vocab: true)}.to raise_error(result)
1376
- else
1377
- expect(subject.compact_iri(input, vocab: true)).to produce(result, logger)
1378
- end
1379
- end
1380
- end
1381
- end
1382
- end
1383
-
1384
- context "compact-0018" do
1385
- let(:ctx) do
1386
- subject.parse(JSON.parse %({
1387
- "id1": "http://example.com/id1",
1388
- "type1": "http://example.com/t1",
1389
- "type2": "http://example.com/t2",
1390
- "@language": "de",
1391
- "term": {
1392
- "@id": "http://example.com/term"
1393
- },
1394
- "term1": {
1395
- "@id": "http://example.com/term",
1396
- "@container": "@list"
1397
- },
1398
- "term2": {
1399
- "@id": "http://example.com/term",
1400
- "@container": "@list",
1401
- "@language": "en"
1402
- },
1403
- "term3": {
1404
- "@id": "http://example.com/term",
1405
- "@container": "@list",
1406
- "@language": null
1407
- },
1408
- "term4": {
1409
- "@id": "http://example.com/term",
1410
- "@container": "@list",
1411
- "@type": "type1"
1412
- },
1413
- "term5": {
1414
- "@id": "http://example.com/term",
1415
- "@container": "@list",
1416
- "@type": "type2"
1417
- }
1418
- }))
1419
- end
1420
-
1421
- {
1422
- "term" => [
1423
- '{ "@value": "v0.1", "@language": "de" }',
1424
- '{ "@value": "v0.2", "@language": "en" }',
1425
- '{ "@value": "v0.3"}',
1426
- '{ "@value": 4}',
1427
- '{ "@value": true}',
1428
- '{ "@value": false}'
1429
- ],
1430
- "term1" => %q({
1431
- "@list": [
1432
- { "@value": "v1.1", "@language": "de" },
1433
- { "@value": "v1.2", "@language": "en" },
1434
- { "@value": "v1.3"},
1435
- { "@value": 14},
1436
- { "@value": true},
1437
- { "@value": false}
1438
- ]
1439
- }),
1440
- "term2" => %q({
1441
- "@list": [
1442
- { "@value": "v2.1", "@language": "en" },
1443
- { "@value": "v2.2", "@language": "en" },
1444
- { "@value": "v2.3", "@language": "en" },
1445
- { "@value": "v2.4", "@language": "en" },
1446
- { "@value": "v2.5", "@language": "en" },
1447
- { "@value": "v2.6", "@language": "en" }
1448
- ]
1449
- }),
1450
- "term3" => %q({
1451
- "@list": [
1452
- { "@value": "v3.1"},
1453
- { "@value": "v3.2"},
1454
- { "@value": "v3.3"},
1455
- { "@value": "v3.4"},
1456
- { "@value": "v3.5"},
1457
- { "@value": "v3.6"}
1458
- ]
1459
- }),
1460
- "term4" => %q({
1461
- "@list": [
1462
- { "@value": "v4.1", "@type": "http://example.com/t1" },
1463
- { "@value": "v4.2", "@type": "http://example.com/t1" },
1464
- { "@value": "v4.3", "@type": "http://example.com/t1" },
1465
- { "@value": "v4.4", "@type": "http://example.com/t1" },
1466
- { "@value": "v4.5", "@type": "http://example.com/t1" },
1467
- { "@value": "v4.6", "@type": "http://example.com/t1" }
1468
- ]
1469
- }),
1470
- "term5" => %q({
1471
- "@list": [
1472
- { "@value": "v5.1", "@type": "http://example.com/t2" },
1473
- { "@value": "v5.2", "@type": "http://example.com/t2" },
1474
- { "@value": "v5.3", "@type": "http://example.com/t2" },
1475
- { "@value": "v5.4", "@type": "http://example.com/t2" },
1476
- { "@value": "v5.5", "@type": "http://example.com/t2" },
1477
- { "@value": "v5.6", "@type": "http://example.com/t2" }
1478
- ]
1479
- }),
1480
- }.each do |term, value|
1481
- [value].flatten.each do |v|
1482
- it "Uses #{term} for #{v}" do
1483
- expect(ctx.compact_iri("http://example.com/term", value: JSON.parse(v), vocab: true)).
1484
- to produce(term, logger)
1485
- end
1486
- end
1487
- end
1488
- end
1489
-
1490
- context "compact-0020" do
1491
- let(:ctx) do
1492
- subject.parse({
1493
- "ex" => "http://example.org/ns#",
1494
- "ex:property" => {"@container" => "@list"}
1495
- })
1496
- end
1497
- it "Compact @id that is a property IRI when @container is @list" do
1498
- expect(ctx.compact_iri("http://example.org/ns#property", vocab: false)).
1499
- to produce("ex:property", logger)
1500
- end
1501
- end
1502
-
1503
- context "compact-0041" do
1504
- let(:ctx) do
1505
- subject.parse({"name" => {"@id" => "http://example.com/property", "@container" => "@list"}})
1506
- end
1507
- it "Does not use @list with @index" do
1508
- expect(ctx.compact_iri("http://example.com/property", value: {
1509
- "@list" => ["one item"],
1510
- "@index" => "an annotation"
1511
- })).to produce("http://example.com/property", logger)
1512
- end
1513
- end
1514
- end
1515
-
1516
- describe "#expand_value" do
1517
- subject {
1518
- ctx = context.parse({
1519
- "dc" => RDF::Vocab::DC.to_uri.to_s,
1520
- "ex" => "http://example.org/",
1521
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
1522
- "xsd" => "http://www.w3.org/2001/XMLSchema#",
1523
- "foaf:age" => {"@type" => "xsd:integer"},
1524
- "foaf:knows" => {"@type" => "@id"},
1525
- "dc:created" => {"@type" => "xsd:date"},
1526
- "ex:integer" => {"@type" => "xsd:integer"},
1527
- "ex:double" => {"@type" => "xsd:double"},
1528
- "ex:boolean" => {"@type" => "xsd:boolean"},
1529
- "ex:none" => {"@type" => "@none"},
1530
- "ex:json" => {"@type" => "@json"}
1531
- })
1532
- logger.clear
1533
- ctx
1534
- }
1535
-
1536
- %w(boolean integer string dateTime date time).each do |dt|
1537
- it "expands datatype xsd:#{dt}" do
1538
- expect(subject.expand_value("foo", RDF::XSD[dt])).to produce({"@id" => "http://www.w3.org/2001/XMLSchema##{dt}"}, logger)
1539
- end
1540
- end
1541
-
1542
- {
1543
- "absolute IRI" => ["foaf:knows", "http://example.com/", {"@id" => "http://example.com/"}],
1544
- "term" => ["foaf:knows", "ex", {"@id" => "ex"}],
1545
- "prefix:suffix" => ["foaf:knows", "ex:suffix", {"@id" => "http://example.org/suffix"}],
1546
- "no IRI" => ["foo", "http://example.com/", {"@value" => "http://example.com/"}],
1547
- "no term" => ["foo", "ex", {"@value" => "ex"}],
1548
- "no prefix" => ["foo", "ex:suffix", {"@value" => "ex:suffix"}],
1549
- "integer" => ["foaf:age", "54", {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1550
- "date " => ["dc:created", "2011-12-27Z", {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1551
- "native boolean" => ["foo", true, {"@value" => true}],
1552
- "native integer" => ["foo", 1, {"@value" => 1}],
1553
- "native double" => ["foo", 1.1e1, {"@value" => 1.1E1}],
1554
- "native date" => ["foo", Date.parse("2011-12-27"), {"@value" => "2011-12-27", "@type" => RDF::XSD.date.to_s}],
1555
- "native dateTime" =>["foo", DateTime.parse("2011-12-27T10:11:12Z"), {"@value" => "2011-12-27T10:11:12Z", "@type" => RDF::XSD.dateTime.to_s}],
1556
- "rdf boolean" => ["foo", RDF::Literal(true), {"@value" => "true", "@type" => RDF::XSD.boolean.to_s}],
1557
- "rdf integer" => ["foo", RDF::Literal(1), {"@value" => "1", "@type" => RDF::XSD.integer.to_s}],
1558
- "rdf decimal" => ["foo", RDF::Literal::Decimal.new(1.1), {"@value" => "1.1", "@type" => RDF::XSD.decimal.to_s}],
1559
- "rdf double" => ["foo", RDF::Literal::Double.new(1.1), {"@value" => "1.1E0", "@type" => RDF::XSD.double.to_s}],
1560
- "rdf URI" => ["foo", RDF::URI("foo"), {"@id" => "foo"}],
1561
- "rdf date " => ["foo", RDF::Literal(Date.parse("2011-12-27")), {"@value" => "2011-12-27", "@type" => RDF::XSD.date.to_s}],
1562
- "rdf nonNeg" => ["foo", RDF::Literal::NonNegativeInteger.new(1), {"@value" => "1", "@type" => RDF::XSD.nonNegativeInteger}],
1563
- "rdf float" => ["foo", RDF::Literal::Float.new(1.0), {"@value" => "1.0", "@type" => RDF::XSD.float}],
1564
- "ex:none string" => ["ex:none", "foo", {"@value" => "foo"}],
1565
- "ex:none boolean" =>["ex:none", true, {"@value" => true}],
1566
- "ex:none integer" =>["ex:none", 1, {"@value" => 1}],
1567
- "ex:none double" => ["ex:none", 1.1e1, {"@value" => 1.1E1}],
1568
- "ex:json string" => ["ex:json", "foo", {"@value" => "foo", "@type" => "@json"}],
1569
- "ex:json boolean" =>["ex:json", true, {"@value" => true, "@type" => "@json"}],
1570
- "ex:json integer" =>["ex:json", 1, {"@value" => 1, "@type" => "@json"}],
1571
- "ex:json double" => ["ex:json", 1.1e1, {"@value" => 1.1e1, "@type" => "@json"}],
1572
- "ex:json object" => ["ex:json", {"foo" => "bar"}, {"@value" => {"foo" => "bar"}, "@type" => "@json"}],
1573
- "ex:json array" => ["ex:json", [{"foo" => "bar"}], {"@value" => [{"foo" => "bar"}], "@type" => "@json"}],
1574
- }.each do |title, (key, compacted, expanded)|
1575
- it title do
1576
- expect(subject.expand_value(key, compacted)).to produce(expanded, logger)
1577
- end
1578
- end
1579
-
1580
- context "@language" do
1581
- before(:each) {subject.default_language = "en"}
1582
- {
1583
- "no IRI" => ["foo", "http://example.com/", {"@value" => "http://example.com/", "@language" => "en"}],
1584
- "no term" => ["foo", "ex", {"@value" => "ex", "@language" => "en"}],
1585
- "no prefix" => ["foo", "ex:suffix", {"@value" => "ex:suffix", "@language" => "en"}],
1586
- "native boolean" => ["foo", true, {"@value" => true}],
1587
- "native integer" => ["foo", 1, {"@value" => 1}],
1588
- "native double" => ["foo", 1.1, {"@value" => 1.1}],
1589
- }.each do |title, (key, compacted, expanded)|
1590
- it title do
1591
- expect(subject.expand_value(key, compacted)).to produce(expanded, logger)
1592
- end
1593
- end
1594
- end
1595
-
1596
- context "coercion" do
1597
- before(:each) {subject.default_language = "en"}
1598
- {
1599
- "boolean-boolean" => ["ex:boolean", true, {"@value" => true, "@type" => RDF::XSD.boolean.to_s}],
1600
- "boolean-integer" => ["ex:integer", true, {"@value" => true, "@type" => RDF::XSD.integer.to_s}],
1601
- "boolean-double" => ["ex:double", true, {"@value" => true, "@type" => RDF::XSD.double.to_s}],
1602
- "boolean-json" => ["ex:json", true, {"@value" => true, "@type" => '@json'}],
1603
- "double-boolean" => ["ex:boolean", 1.1, {"@value" => 1.1, "@type" => RDF::XSD.boolean.to_s}],
1604
- "double-double" => ["ex:double", 1.1, {"@value" => 1.1, "@type" => RDF::XSD.double.to_s}],
1605
- "double-integer" => ["foaf:age", 1.1, {"@value" => 1.1, "@type" => RDF::XSD.integer.to_s}],
1606
- "double-json" => ["ex:json", 1.1, {"@value" => 1.1, "@type" => '@json'}],
1607
- "json-json" => ["ex:json", {"foo" => "bar"}, {"@value" => {"foo" => "bar"}, "@type" => '@json'}],
1608
- "integer-boolean" => ["ex:boolean", 1, {"@value" => 1, "@type" => RDF::XSD.boolean.to_s}],
1609
- "integer-double" => ["ex:double", 1, {"@value" => 1, "@type" => RDF::XSD.double.to_s}],
1610
- "integer-integer" => ["foaf:age", 1, {"@value" => 1, "@type" => RDF::XSD.integer.to_s}],
1611
- "integer-json" => ["ex:json", 1, {"@value" => 1, "@type" => '@json'}],
1612
- "string-boolean" => ["ex:boolean", "foo", {"@value" => "foo", "@type" => RDF::XSD.boolean.to_s}],
1613
- "string-double" => ["ex:double", "foo", {"@value" => "foo", "@type" => RDF::XSD.double.to_s}],
1614
- "string-integer" => ["foaf:age", "foo", {"@value" => "foo", "@type" => RDF::XSD.integer.to_s}],
1615
- "string-json" => ["ex:json", "foo", {"@value" => "foo", "@type" => '@json'}],
1616
- }.each do |title, (key, compacted, expanded)|
1617
- it title do
1618
- expect(subject.expand_value(key, compacted)).to produce(expanded, logger)
1619
- end
1620
- end
1621
- end
1622
- end
1623
-
1624
- describe "#compact_value" do
1625
- let(:ctx) do
1626
- c = context.parse({
1627
- "dc" => RDF::Vocab::DC.to_uri.to_s,
1628
- "ex" => "http://example.org/",
1629
- "foaf" => RDF::Vocab::FOAF.to_uri.to_s,
1630
- "xsd" => RDF::XSD.to_s,
1631
- "langmap" => {"@id" => "http://example.com/langmap", "@container" => "@language"},
1632
- "list" => {"@id" => "http://example.org/list", "@container" => "@list"},
1633
- "nolang" => {"@id" => "http://example.org/nolang", "@language" => nil},
1634
- "dc:created" => {"@type" => RDF::XSD.date.to_s},
1635
- "foaf:age" => {"@type" => RDF::XSD.integer.to_s},
1636
- "foaf:knows" => {"@type" => "@id"},
1637
- "ex:none" => {"@type" => "@none"},
1638
- })
1639
- logger.clear
1640
- c
1641
- end
1642
- subject {ctx}
1643
-
1644
- {
1645
- "absolute IRI" => ["foaf:knows", "http://example.com/", {"@id" => "http://example.com/"}],
1646
- "prefix:suffix" => ["foaf:knows", "ex:suffix", {"@id" => "http://example.org/suffix"}],
1647
- "integer" => ["foaf:age", "54", {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1648
- "date " => ["dc:created", "2011-12-27Z", {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1649
- "no IRI" => ["foo", {"@id" =>"http://example.com/"},{"@id" => "http://example.com/"}],
1650
- "no IRI (Compact IRI)" => ["foo", {"@id" => RDF::Vocab::FOAF.Person.to_s}, {"@id" => RDF::Vocab::FOAF.Person.to_s}],
1651
- "no boolean" => ["foo", {"@value" => "true", "@type" => "xsd:boolean"},{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}],
1652
- "no integer" => ["foo", {"@value" => "54", "@type" => "xsd:integer"},{"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1653
- "no date " => ["foo", {"@value" => "2011-12-27Z", "@type" => "xsd:date"}, {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1654
- "no string " => ["foo", "string", {"@value" => "string"}],
1655
- "no lang " => ["nolang", "string", {"@value" => "string"}],
1656
- "native boolean" => ["foo", true, {"@value" => true}],
1657
- "native integer" => ["foo", 1, {"@value" => 1}],
1658
- "native integer(list)"=>["list", 1, {"@value" => 1}],
1659
- "native double" => ["foo", 1.1e1, {"@value" => 1.1E1}],
1660
- "ex:none IRI" => ["ex:none", {"@id" => "http://example.com/"}, {"@id" => "http://example.com/"}],
1661
- "ex:none string" => ["ex:none", {"@value" => "string"}, {"@value" => "string"}],
1662
- "ex:none integer" =>["ex:none", {"@value" => "54", "@type" => "xsd:integer"}, {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1663
- }.each do |title, (key, compacted, expanded)|
1664
- it title do
1665
- expect(subject.compact_value(key, expanded)).to produce(compacted, logger)
1666
- end
1667
- end
1668
-
1669
- context "@language" do
1670
- {
1671
- "@id" => ["foo", {"@id" => "foo"}, {"@id" => "foo"}],
1672
- "integer" => ["foo", {"@value" => "54", "@type" => "xsd:integer"}, {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1673
- "date" => ["foo", {"@value" => "2011-12-27Z","@type" => "xsd:date"},{"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1674
- "no lang" => ["foo", {"@value" => "foo" }, {"@value" => "foo"}],
1675
- "same lang" => ["foo", "foo", {"@value" => "foo", "@language" => "en"}],
1676
- "other lang" => ["foo", {"@value" => "foo", "@language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
1677
- "langmap" => ["langmap", "en", {"@value" => "en", "@language" => "en"}],
1678
- "no lang with @type coercion" => ["dc:created", {"@value" => "foo"}, {"@value" => "foo"}],
1679
- "no lang with @id coercion" => ["foaf:knows", {"@value" => "foo"}, {"@value" => "foo"}],
1680
- "no lang with @language=null" => ["nolang", "string", {"@value" => "string"}],
1681
- "same lang with @type coercion" => ["dc:created", {"@value" => "foo"}, {"@value" => "foo"}],
1682
- "same lang with @id coercion" => ["foaf:knows", {"@value" => "foo"}, {"@value" => "foo"}],
1683
- "other lang with @type coercion" => ["dc:created", {"@value" => "foo", "@language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
1684
- "other lang with @id coercion" => ["foaf:knows", {"@value" => "foo", "@language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
1685
- "native boolean" => ["foo", true, {"@value" => true}],
1686
- "native integer" => ["foo", 1, {"@value" => 1}],
1687
- "native integer(list)" => ["list", 1, {"@value" => 1}],
1688
- "native double" => ["foo", 1.1e1, {"@value" => 1.1E1}],
1689
- }.each do |title, (key, compacted, expanded)|
1690
- it title do
1691
- subject.default_language = "en"
1692
- expect(subject.compact_value(key, expanded)).to produce(compacted, logger)
1693
- end
1694
- end
1695
- end
1696
-
1697
- context "keywords" do
1698
- before(:each) do
1699
- subject.set_mapping("id", "@id")
1700
- subject.set_mapping("type", "@type")
1701
- subject.set_mapping("list", "@list")
1702
- subject.set_mapping("set", "@set")
1703
- subject.set_mapping("language", "@language")
1704
- subject.set_mapping("literal", "@value")
1705
- end
1706
-
1707
- {
1708
- "@id" => [{"id" => "http://example.com/"}, {"@id" => "http://example.com/"}],
1709
- "@type" => [{"literal" => "foo", "type" => "http://example.com/"},
1710
- {"@value" => "foo", "@type" => "http://example.com/"}],
1711
- "@value" => [{"literal" => "foo", "language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
1712
- }.each do |title, (compacted, expanded)|
1713
- it title do
1714
- expect(subject.compact_value("foo", expanded)).to produce(compacted, logger)
1715
- end
1716
- end
1717
- end
1718
- end
1719
-
1720
- describe "#from_vocabulary" do
1721
- it "must be described"
1722
- end
1723
-
1724
- describe "#container" do
1725
- subject {
1726
- ctx = context.parse({
1727
- "ex" => "http://example.org/",
1728
- "graph" => {"@id" => "ex:graph", "@container" => "@graph"},
1729
- "graphSet" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@set"]},
1730
- "graphId" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@id"]},
1731
- "graphIdSet" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@id", "@set"]},
1732
- "graphNdx" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@index"]},
1733
- "graphNdxSet" => {"@id" => "ex:graphSet", "@container" => ["@graph", "@index", "@set"]},
1734
- "id" => {"@id" => "ex:idSet", "@container" => "@id"},
1735
- "idSet" => {"@id" => "ex:id", "@container" => ["@id", "@set"]},
1736
- "language" => {"@id" => "ex:language", "@container" => "@language"},
1737
- "langSet" => {"@id" => "ex:languageSet", "@container" => ["@language", "@set"]},
1738
- "list" => {"@id" => "ex:list", "@container" => "@list"},
1739
- "ndx" => {"@id" => "ex:ndx", "@container" => "@index"},
1740
- "ndxSet" => {"@id" => "ex:ndxSet", "@container" => ["@index", "@set"]},
1741
- "set" => {"@id" => "ex:set", "@container" => "@set"},
1742
- "type" => {"@id" => "ex:type", "@container" => "@type"},
1743
- "typeSet" => {"@id" => "ex:typeSet", "@container" => ["@type", "@set"]},
1744
- })
1745
- logger.clear
1746
- ctx
1747
- }
1748
-
1749
- it "uses TermDefinition" do
1750
- {
1751
- "ex" => Set.new,
1752
- "graph" => Set["@graph"],
1753
- "graphSet" => Set["@graph"],
1754
- "graphId" => Set["@graph", "@id"],
1755
- "graphIdSet" => Set["@graph", "@id"],
1756
- "graphNdx" => Set["@graph", "@index"],
1757
- "graphNdxSet" => Set["@graph", "@index"],
1758
- "id" => Set['@id'],
1759
- "idSet" => Set['@id'],
1760
- "language" => Set['@language'],
1761
- "langSet" => Set['@language'],
1762
- "list" => Set['@list'],
1763
- "ndx" => Set['@index'],
1764
- "ndxSet" => Set['@index'],
1765
- "set" => Set.new,
1766
- "type" => Set['@type'],
1767
- "typeSet" => Set['@type'],
1768
- }.each do |defn, container|
1769
- expect(subject.container(subject.term_definitions[defn])).to eq container
1770
- end
1771
- end
1772
-
1773
- it "#as_array" do
1774
- {
1775
- "ex" => false,
1776
- "graph" => false,
1777
- "graphSet" => true,
1778
- "graphId" => false,
1779
- "graphIdSet" => true,
1780
- "graphNdx" => false,
1781
- "graphNdxSet" => true,
1782
- "id" => false,
1783
- "idSet" => true,
1784
- "language" => false,
1785
- "langSet" => true,
1786
- "list" => true,
1787
- "ndx" => false,
1788
- "ndxSet" => true,
1789
- "set" => true,
1790
- "type" => false,
1791
- "typeSet" => true,
1792
- }.each do |defn, as_array|
1793
- expect(subject.as_array?(subject.term_definitions[defn])).to eq as_array
1794
- end
1795
- end
1796
-
1797
- it "uses array" do
1798
- {
1799
- "ex" => Set.new,
1800
- "graph" => Set["@graph"],
1801
- "graphSet" => Set["@graph"],
1802
- "graphId" => Set["@graph", "@id"],
1803
- "graphIdSet" => Set["@graph", "@id"],
1804
- "graphNdx" => Set["@graph", "@index"],
1805
- "graphNdxSet" => Set["@graph", "@index"],
1806
- "id" => Set['@id'],
1807
- "idSet" => Set['@id'],
1808
- "language" => Set['@language'],
1809
- "langSet" => Set['@language'],
1810
- "list" => Set['@list'],
1811
- "ndx" => Set['@index'],
1812
- "ndxSet" => Set['@index'],
1813
- "set" => Set.new,
1814
- "type" => Set['@type'],
1815
- "typeSet" => Set['@type'],
1816
- }.each do |defn, container|
1817
- expect(subject.container(defn)).to eq container
1818
- end
1819
- end
1820
- end
1821
-
1822
- describe "#language" do
1823
- subject {
1824
- ctx = context.parse({
1825
- "ex" => "http://example.org/",
1826
- "nil" => {"@id" => "ex:nil", "@language" => nil},
1827
- "en" => {"@id" => "ex:en", "@language" => "en"},
1828
- })
1829
- logger.clear
1830
- ctx
1831
- }
1832
- it "uses TermDefinition" do
1833
- expect(subject.language(subject.term_definitions['ex'])).to be_falsey
1834
- expect(subject.language(subject.term_definitions['nil'])).to be_falsey
1835
- expect(subject.language(subject.term_definitions['en'])).to eq 'en'
1836
- end
1837
-
1838
- it "uses string" do
1839
- expect(subject.language('ex')).to be_falsey
1840
- expect(subject.language('nil')).to be_falsey
1841
- expect(subject.language('en')).to eq 'en'
1842
- end
1843
- end
1844
-
1845
- describe "#reverse?" do
1846
- subject {
1847
- ctx = context.parse({
1848
- "ex" => "http://example.org/",
1849
- "reverse" => {"@reverse" => "ex:reverse"},
1850
- })
1851
- logger.clear
1852
- ctx
1853
- }
1854
- it "uses TermDefinition" do
1855
- expect(subject.reverse?(subject.term_definitions['ex'])).to be_falsey
1856
- expect(subject.reverse?(subject.term_definitions['reverse'])).to be_truthy
1857
- end
1858
-
1859
- it "uses string" do
1860
- expect(subject.reverse?('ex')).to be_falsey
1861
- expect(subject.reverse?('reverse')).to be_truthy
1862
- end
1863
- end
1864
-
1865
- describe "#nest" do
1866
- subject {
1867
- ctx = context.parse({
1868
- "ex" => "http://example.org/",
1869
- "nest" => {"@id" => "ex:nest", "@nest" => "@nest"},
1870
- "nest2" => {"@id" => "ex:nest2", "@nest" => "nest-alias"},
1871
- "nest-alias" => "@nest"
1872
- })
1873
- logger.clear
1874
- ctx
1875
- }
1876
-
1877
- it "uses term" do
1878
- {
1879
- "ex" => nil,
1880
- "nest" => "@nest",
1881
- "nest2" => "nest-alias",
1882
- "nest-alias" => nil,
1883
- }.each do |defn, nest|
1884
- expect(subject.nest(defn)).to eq nest
1885
- end
1886
- end
1887
-
1888
- context "detects error" do
1889
- it "does not allow a keyword other than @nest for the value of @nest" do
1890
- expect {
1891
- context.parse({"no-keyword-nest" => {"@id" => "http://example/f", "@nest" => "@id"}})
1892
- }.to raise_error JSON::LD::JsonLdError::InvalidNestValue
1893
- end
1894
-
1895
- it "does not allow @nest with @reverse" do
1896
- expect {
1897
- context.parse({"no-reverse-nest" => {"@reverse" => "http://example/f", "@nest" => "@nest"}})
1898
- }.to raise_error JSON::LD::JsonLdError::InvalidReverseProperty
1899
- end
1900
- end
1901
- end
1902
-
1903
- describe "#reverse_term" do
1904
- subject {
1905
- ctx = context.parse({
1906
- "ex" => "http://example.org/",
1907
- "reverse" => {"@reverse" => "ex"},
1908
- })
1909
- logger.clear
1910
- ctx
1911
- }
1912
- it "uses TermDefinition" do
1913
- expect(subject.reverse_term(subject.term_definitions['ex'])).to eql subject.term_definitions['reverse']
1914
- expect(subject.reverse_term(subject.term_definitions['reverse'])).to eql subject.term_definitions['ex']
1915
- end
1916
-
1917
- it "uses string" do
1918
- expect(subject.reverse_term('ex')).to eql subject.term_definitions['reverse']
1919
- expect(subject.reverse_term('reverse')).to eql subject.term_definitions['ex']
1920
- end
1921
- end
1922
-
1923
- describe "protected contexts" do
1924
- it "seals a term with @protected true" do
1925
- ctx = context.parse({
1926
- "protected" => {"@id" => "http://example.com/protected", "@protected" => true},
1927
- "unprotected" => {"@id" => "http://example.com/unprotected"},
1928
- })
1929
- expect(ctx.term_definitions["protected"]).to be_protected
1930
- expect(ctx.term_definitions["unprotected"]).not_to be_protected
1931
- end
1932
-
1933
- it "seals all term with @protected true in context" do
1934
- ctx = context.parse({
1935
- "@protected" => true,
1936
- "protected" => {"@id" => "http://example.com/protected"},
1937
- "protected2" => {"@id" => "http://example.com/protected2"},
1938
- })
1939
- expect(ctx.term_definitions["protected"]).to be_protected
1940
- expect(ctx.term_definitions["protected2"]).to be_protected
1941
- end
1942
-
1943
- it "does not seal term with @protected: false when context is protected" do
1944
- ctx = context.parse({
1945
- "@protected" => true,
1946
- "protected" => {"@id" => "http://example.com/protected"},
1947
- "unprotected" => {"@id" => "http://example.com/unprotected", "@protected" => false},
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 "does not error when redefining an identical term" do
1954
- c = {
1955
- "protected" => {"@id" => "http://example.com/protected", "@protected" => true}
1956
- }
1957
- ctx = context.parse(c)
1958
-
1959
- expect {ctx.parse(c)}.not_to raise_error
1960
- end
1961
-
1962
- it "errors when redefining a protected term" do
1963
- ctx = context.parse({
1964
- "protected" => {"@id" => "http://example.com/protected", "@protected" => true}
1965
- })
1966
-
1967
- expect {ctx.parse({"protected" => "http://example.com/different"})}.to raise_error(JSON::LD::JsonLdError::ProtectedTermRedefinition)
1968
- end
1969
-
1970
- it "errors when clearing a context having protected terms" do
1971
- ctx = context.parse({
1972
- "protected" => {"@id" => "http://example.com/protected", "@protected" => true}
1973
- })
1974
-
1975
- expect {ctx.parse(nil)}.to raise_error(JSON::LD::JsonLdError::InvalidContextNullification)
1976
- end
1977
- end
1978
-
1979
- describe JSON::LD::Context::TermDefinition do
1980
- context "with nothing" do
1981
- subject {described_class.new("term")}
1982
- its(:term) {is_expected.to eq "term"}
1983
- its(:id) {is_expected.to be_nil}
1984
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term"))}
1985
- end
1986
-
1987
- context "with id" do
1988
- subject {described_class.new("term", id: "http://example.org/term")}
1989
- its(:term) {is_expected.to eq "term"}
1990
- its(:id) {is_expected.to eq "http://example.org/term"}
1991
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", id: "http://example.org/term"))}
1992
- end
1993
-
1994
- context "with type_mapping" do
1995
- subject {described_class.new("term", type_mapping: "http://example.org/type")}
1996
- its(:type_mapping) {is_expected.to eq "http://example.org/type"}
1997
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", type_mapping: "http://example.org/type"))}
1998
- end
1999
-
2000
- context "with container_mapping @set" do
2001
- subject {described_class.new("term", container_mapping: "@set")}
2002
- its(:container_mapping) {is_expected.to be_empty}
2003
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: "@set"))}
2004
- end
2005
-
2006
- context "with container_mapping @id @set" do
2007
- subject {described_class.new("term", container_mapping: %w(@id @set))}
2008
- its(:container_mapping) {is_expected.to eq Set['@id']}
2009
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: ["@id", "@set"]))}
2010
- end
2011
-
2012
- context "with container_mapping @list" do
2013
- subject {described_class.new("term", container_mapping: "@list")}
2014
- its(:container_mapping) {is_expected.to eq Set['@list']}
2015
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: "@list"))}
2016
- end
2017
-
2018
- context "with language_mapping" do
2019
- subject {described_class.new("term", language_mapping: "en")}
2020
- its(:language_mapping) {is_expected.to eq "en"}
2021
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", language_mapping: "en"))}
2022
- end
2023
-
2024
- context "with reverse_property" do
2025
- subject {described_class.new("term", reverse_property: true)}
2026
- its(:reverse_property) {is_expected.to be_truthy}
2027
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", reverse_property: true))}
2028
- end
2029
-
2030
- context "with simple" do
2031
- subject {described_class.new("term", simple: true)}
2032
- its(:simple) {is_expected.to be_truthy}
2033
- its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", simple: true))}
2034
- end
2035
- end
2036
- end