json-ld 2.2.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -272,6 +272,105 @@ describe JSON::LD::API do
272
272
  }],
273
273
  RDF::NQuads::Reader
274
274
  ],
275
+ "multiple graphs with shared BNode (at head)" => [
276
+ %q(
277
+ <http://www.example.com/z> <http://www.example.com/q> _:z0 <http://www.example.com/G> .
278
+ _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "cell-A" <http://www.example.com/G> .
279
+ _:z0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:z1 <http://www.example.com/G> .
280
+ _:z1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "cell-B" <http://www.example.com/G> .
281
+ _:z1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://www.example.com/G> .
282
+ <http://www.example.com/z> <http://www.example.com/q> _:z0 <http://www.example.com/G1> .
283
+ ),
284
+ [{
285
+ "@id" => "http://www.example.com/G",
286
+ "@graph" => [{
287
+ "@id" => "_:z0",
288
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" => [{"@value" => "cell-A"}],
289
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest" => [{"@list" => [{ "@value" => "cell-B" }]}]
290
+ }, {
291
+ "@id" => "http://www.example.com/z",
292
+ "http://www.example.com/q" => [{"@id" => "_:z0"}]
293
+ }]
294
+ },
295
+ {
296
+ "@id" => "http://www.example.com/G1",
297
+ "@graph" => [{
298
+ "@id" => "http://www.example.com/z",
299
+ "http://www.example.com/q" => [{"@id" => "_:z0"}]
300
+ }]
301
+ }],
302
+ RDF::NQuads::Reader
303
+ ],
304
+ "@list containing empty @list" => [
305
+ %(
306
+ <http://example.com/a> <http://example.com/property> (()) .
307
+ ),
308
+ JSON.parse(%([{
309
+ "@id": "http://example.com/a",
310
+ "http://example.com/property": [{"@list": [{"@list": []}]}]
311
+ }])),
312
+ RDF::Turtle::Reader
313
+ ],
314
+ "@list containing multiple lists" => [
315
+ %(
316
+ <http://example.com/a> <http://example.com/property> (("a") ("b")) .
317
+ ),
318
+ JSON.parse(%([{
319
+ "@id": "http://example.com/a",
320
+ "http://example.com/property": [{"@list": [
321
+ {"@list": [{"@value": "a"}]},
322
+ {"@list": [{"@value": "b"}]}
323
+ ]}]
324
+ }])),
325
+ RDF::Turtle::Reader
326
+ ],
327
+ "0008a" => [
328
+ %(
329
+ <http://example.com> <http://example.com/property> _:outerlist .
330
+ _:outerlist <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:lista .
331
+ _:outerlist <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b0 .
332
+
333
+ _:lista <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "a1" .
334
+ _:lista <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:a2 .
335
+ _:a2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "a2" .
336
+ _:a2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:a3 .
337
+ _:a3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "a3" .
338
+ _:a3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
339
+
340
+ _:c0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:c1 .
341
+ _:c0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
342
+ _:c1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "c1" .
343
+ _:c1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:c2 .
344
+ _:c2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "c2" .
345
+ _:c2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:c3 .
346
+ _:c3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "c3" .
347
+ _:c3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
348
+
349
+ _:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:b1 .
350
+ _:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:c0 .
351
+ _:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "b1" .
352
+ _:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b2 .
353
+ _:b2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "b2" .
354
+ _:b2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b3 .
355
+ _:b3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "b3" .
356
+ _:b3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
357
+ ),
358
+ JSON.parse(%([
359
+ {
360
+ "@id": "http://example.com",
361
+ "http://example.com/property": [
362
+ {
363
+ "@list": [
364
+ {"@list": [{"@value": "a1"}, {"@value": "a2"}, {"@value": "a3"}]},
365
+ {"@list": [{"@value": "b1"}, {"@value": "b2"}, {"@value": "b3"}]},
366
+ {"@list": [{"@value": "c1"}, {"@value": "c2"}, {"@value": "c3"}]}
367
+ ]
368
+ }
369
+ ]
370
+ }
371
+ ])),
372
+ RDF::NQuads::Reader
373
+ ]
275
374
  }.each do |name, (input, output, reader)|
276
375
  it name do
277
376
  r = serialize(input, reader: reader)
@@ -398,17 +497,17 @@ describe JSON::LD::API do
398
497
  end
399
498
  end
400
499
 
401
- def parse(input, options = {})
500
+ def parse(input, **options)
402
501
  reader = options[:reader] || RDF::TriG::Reader
403
502
  reader.new(input, options, &:each_statement).to_a.extend(RDF::Enumerable)
404
503
  end
405
504
 
406
505
  # Serialize ntstr to a string and compare against regexps
407
- def serialize(ntstr, options = {})
506
+ def serialize(ntstr, **options)
408
507
  logger.info ntstr if ntstr.is_a?(String)
409
508
  g = ntstr.is_a?(String) ? parse(ntstr, options) : ntstr
410
509
  logger.info g.dump(:trig)
411
510
  statements = g.each_statement.to_a
412
- JSON::LD::API.fromRdf(statements, options.merge(logger: logger))
511
+ JSON::LD::API.fromRdf(statements, logger: logger, **options)
413
512
  end
414
513
  end
@@ -50,10 +50,10 @@ describe JSON::LD::StreamingWriter do
50
50
  )
51
51
  obj = serialize(input)
52
52
  expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse(input), logger: logger)
53
- expect(obj).to contain_exactly *JSON.parse(%{[
53
+ expect(obj).to contain_exactly(*JSON.parse(%{[
54
54
  {"@id": "http://example.com/test-cases/0001", "@type": ["http://www.w3.org/2006/03/test-description#TestCase"]},
55
55
  {"@id": "http://example.com/test-cases/0002", "@type": ["http://www.w3.org/2006/03/test-description#TestCase"]}
56
- ]})
56
+ ]}))
57
57
  end
58
58
  end
59
59
 
@@ -91,7 +91,7 @@ describe JSON::LD::StreamingWriter do
91
91
  context title do
92
92
  subject {serialize(input)}
93
93
  it "matches expected json" do
94
- expect(subject).to contain_exactly *JSON.parse(matches)
94
+ expect(subject).to contain_exactly(*JSON.parse(matches))
95
95
  end
96
96
  end
97
97
  end
@@ -100,7 +100,7 @@ describe JSON::LD::StreamingWriter do
100
100
 
101
101
  context "Writes fromRdf tests to isomorphic graph" do
102
102
  require 'suite_helper'
103
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/fromRdf-manifest.jsonld")
103
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}fromRdf-manifest.jsonld")
104
104
  [nil, {}].each do |ctx|
105
105
  context "with context #{ctx.inspect}" do
106
106
  describe m.name do
@@ -109,7 +109,7 @@ describe JSON::LD::StreamingWriter do
109
109
  t.logger = RDF::Spec.logger
110
110
  t.logger.info "test: #{t.inspect}"
111
111
  t.logger.info "source: #{t.input}"
112
- specify "#{t.property('input')}: #{t.name}" do
112
+ specify "#{t.property('@id')}: #{t.name}" do
113
113
  repo = RDF::Repository.load(t.input_loc, format: :nquads)
114
114
  jsonld = JSON::LD::Writer.buffer(stream: true, context: ctx, logger: t.logger) do |writer|
115
115
  writer << repo
@@ -125,18 +125,17 @@ describe JSON::LD::StreamingWriter do
125
125
  end
126
126
  end unless ENV['CI']
127
127
 
128
- def parse(input, options = {})
129
- format = options.fetch(:format, :trig)
128
+ def parse(input, format: :trig, **options)
130
129
  reader = RDF::Reader.for(format)
131
130
  RDF::Repository.new << reader.new(input, options)
132
131
  end
133
132
 
134
133
  # Serialize ntstr to a string and compare against regexps
135
- def serialize(ntstr, options = {})
134
+ def serialize(ntstr, **options)
136
135
  g = ntstr.is_a?(String) ? parse(ntstr, options) : ntstr
137
136
  logger = RDF::Spec.logger
138
137
  logger.info(g.dump(:ttl))
139
- result = JSON::LD::Writer.buffer(options.merge(logger: logger, stream: true)) do |writer|
138
+ result = JSON::LD::Writer.buffer(logger: logger, stream: true, **options) do |writer|
140
139
  writer << g
141
140
  end
142
141
  puts result if $verbose
@@ -4,10 +4,10 @@ require_relative 'spec_helper'
4
4
  describe JSON::LD do
5
5
  describe "test suite" do
6
6
  require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/compact-manifest.jsonld")
7
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}compact-manifest.jsonld")
8
8
  describe m.name do
9
9
  m.entries.each do |t|
10
- specify "#{t.property('input')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
10
+ specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
11
11
  t.run self
12
12
  end
13
13
  end
@@ -4,10 +4,10 @@ require_relative 'spec_helper'
4
4
  describe JSON::LD do
5
5
  describe "test suite" do
6
6
  require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/expand-manifest.jsonld")
7
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}expand-manifest.jsonld")
8
8
  describe m.name do
9
9
  m.entries.each do |t|
10
- specify "#{t.property('input')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
10
+ specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
11
11
  t.run self
12
12
  end
13
13
  end
@@ -4,10 +4,10 @@ require_relative 'spec_helper'
4
4
  describe JSON::LD do
5
5
  describe "test suite" do
6
6
  require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/flatten-manifest.jsonld")
7
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}flatten-manifest.jsonld")
8
8
  describe m.name do
9
9
  m.entries.each do |t|
10
- specify "#{t.property('input')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
10
+ specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
11
11
  pending "context corner-case" if t.input_loc.end_with?('flatten-0044-in.jsonld')
12
12
  t.run self
13
13
  end
@@ -4,7 +4,7 @@ require_relative 'spec_helper'
4
4
  describe JSON::LD do
5
5
  describe "test suite" do
6
6
  require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/frame-manifest.jsonld")
7
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::FRAME_SUITE}frame-manifest.jsonld")
8
8
  describe m.name do
9
9
  m.entries.each do |t|
10
10
  specify "#{t.property('input')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
@@ -13,4 +13,4 @@ describe JSON::LD do
13
13
  end
14
14
  end
15
15
  end
16
- end unless ENV['CI']
16
+ end unless ENV['CI'] || true
@@ -4,11 +4,10 @@ require_relative 'spec_helper'
4
4
  describe JSON::LD do
5
5
  describe "test suite" do
6
6
  require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/fromRdf-manifest.jsonld")
7
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}fromRdf-manifest.jsonld")
8
8
  describe m.name do
9
9
  m.entries.each do |t|
10
- specify "#{t.property('input')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
11
- pending "Shared list BNode in different graphs" if t.property('input').include?("fromRdf-0021")
10
+ specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
12
11
  t.run self
13
12
  end
14
13
  end
@@ -4,8 +4,11 @@ require_relative 'support/extensions'
4
4
  # For now, override RDF::Utils::File.open_file to look for the file locally before attempting to retrieve it
5
5
  module RDF::Util
6
6
  module File
7
- REMOTE_PATH = "https://json-ld.org/test-suite/"
8
- LOCAL_PATH = ::File.expand_path("../json-ld.org/test-suite", __FILE__) + '/'
7
+ LOCAL_PATHS = {
8
+ "https://w3c.github.io/json-ld-api/tests/" => ::File.expand_path("../json-ld-api/tests", __FILE__) + '/',
9
+ "https://w3c.github.io/json-ld-framing/tests/" => ::File.expand_path("../json-ld-framing/tests", __FILE__) + '/',
10
+ "file:" => ""
11
+ }
9
12
 
10
13
  class << self
11
14
  alias_method :original_open_file, :open_file
@@ -20,32 +23,29 @@ module RDF::Util
20
23
  # HTTP Request headers.
21
24
  # @return [IO] File stream
22
25
  # @yield [IO] File stream
23
- def self.open_file(filename_or_url, options = {}, &block)
24
- case
25
- when filename_or_url.to_s =~ /^file:/
26
- path = filename_or_url[5..-1]
27
- Kernel.open(path.to_s, options, &block)
28
- when Dir.exist?(LOCAL_PATH) &&
29
- !filename_or_url.to_s.include?('remote-doc') &&
30
- filename_or_url.to_s =~ %r{^#{REMOTE_PATH}}
26
+ def self.open_file(filename_or_url, **options, &block)
27
+ LOCAL_PATHS.each do |r, l|
28
+ next unless Dir.exist?(l) && filename_or_url.start_with?(r)
31
29
  #puts "attempt to open #{filename_or_url} locally"
32
- localpath = filename_or_url.to_s.sub(REMOTE_PATH, LOCAL_PATH)
30
+ localpath = filename_or_url.to_s.sub(r, l)
33
31
  response = begin
34
32
  ::File.open(localpath)
35
33
  rescue Errno::ENOENT => e
36
34
  raise IOError, e.message
37
35
  end
36
+
38
37
  document_options = {
39
38
  base_uri: RDF::URI(filename_or_url),
40
39
  charset: Encoding::UTF_8,
41
40
  code: 200,
42
- headers: {}
41
+ headers: options.fetch(:headers, {})
43
42
  }
44
43
  #puts "use #{filename_or_url} locally"
45
44
  document_options[:headers][:content_type] = case filename_or_url.to_s
46
45
  when /\.ttl$/ then 'text/turtle'
47
46
  when /\.nt$/ then 'application/n-triples'
48
47
  when /\.jsonld$/ then 'application/ld+json'
48
+ when /\.json$/ then 'application/json'
49
49
  else 'unknown'
50
50
  end
51
51
 
@@ -55,25 +55,26 @@ module RDF::Util
55
55
 
56
56
  remote_document = RDF::Util::File::RemoteDocument.new(response.read, document_options)
57
57
  if block_given?
58
- yield remote_document
58
+ return yield remote_document
59
59
  else
60
- remote_document
60
+ return remote_document
61
61
  end
62
- else
63
- original_open_file(filename_or_url, options, &block)
64
62
  end
63
+
64
+ original_open_file(filename_or_url, options, &block)
65
65
  end
66
66
  end
67
67
  end
68
68
 
69
69
  module Fixtures
70
70
  module SuiteTest
71
- SUITE = RDF::URI("https://json-ld.org/test-suite/")
71
+ SUITE = RDF::URI("https://w3c.github.io/json-ld-api/tests/")
72
+ FRAME_SUITE = RDF::URI("https://w3c.github.io/json-ld-framing/tests/")
72
73
 
73
74
  class Manifest < JSON::LD::Resource
74
75
  def self.open(file)
75
- Fixtures::SuiteTest.documentLoader(file) do |remote|
76
- json = JSON.parse(remote.document)
76
+ RDF::Util::File.open_file(file) do |remote|
77
+ json = JSON.parse(remote.read)
77
78
  if block_given?
78
79
  yield self.from_jsonld(json)
79
80
  else
@@ -101,12 +102,13 @@ module Fixtures
101
102
 
102
103
  # Base is expanded input file
103
104
  def base
104
- options.fetch('base', "#{SUITE}tests/#{property('input')}")
105
+ options.fetch('base', "#{SUITE}#{property('input')}")
105
106
  end
106
107
 
107
108
  def options
108
109
  @options ||= begin
109
110
  opts = {documentLoader: Fixtures::SuiteTest.method(:documentLoader)}
111
+ opts = {}
110
112
  {'specVersion' => "json-ld-1.1"}.merge(property('option') || {}).each do |k, v|
111
113
  opts[k.to_sym] = v
112
114
  end
@@ -119,13 +121,25 @@ module Fixtures
119
121
  define_method(m.to_sym) do
120
122
  return nil unless property(m)
121
123
  res = nil
122
- Fixtures::SuiteTest.documentLoader("#{SUITE}tests/#{property(m)}", safe: true) do |remote_doc|
123
- res = remote_doc.document
124
+ file = self.send("#{m}_loc".to_sym)
125
+
126
+ dl_opts = {safe: true}
127
+ RDF::Util::File.open_file(file, dl_opts) do |remote_doc|
128
+ res = remote_doc.read
124
129
  end
125
130
  res
126
131
  end
127
132
 
128
- define_method("#{m}_loc".to_sym) {property(m) && "#{SUITE}tests/#{property(m)}"}
133
+ define_method("#{m}_loc".to_sym) do
134
+ file = property(m)
135
+
136
+ # Handle redirection internally
137
+ if m == "input" && options[:redirectTo]
138
+ file = options[:redirectTo]
139
+ end
140
+
141
+ property(m) && "#{SUITE}#{file}"
142
+ end
129
143
 
130
144
  define_method("#{m}_json".to_sym) do
131
145
  JSON.parse(self.send(m)) if property(m)
@@ -149,16 +163,13 @@ module Fixtures
149
163
  def run(rspec_example = nil)
150
164
  logger = @logger = RDF::Spec.logger
151
165
  logger.info "test: #{inspect}"
152
- logger.info "source: #{input}"
166
+ logger.info "purpose: #{purpose}"
167
+ logger.info "source: #{input rescue nil}"
153
168
  logger.info "context: #{context}" if context_loc
154
169
  logger.info "options: #{options.inspect}" unless options.empty?
155
170
  logger.info "frame: #{frame}" if frame_loc
156
171
 
157
- options = if self.options[:useDocumentLoader]
158
- self.options.merge(documentLoader: Fixtures::SuiteTest.method(:documentLoader))
159
- else
160
- self.options.dup
161
- end
172
+ options = self.options.merge(documentLoader: Fixtures::SuiteTest.method(:documentLoader))
162
173
  options = {validate: true}.merge(options)
163
174
 
164
175
  unless options[:specVersion] == "json-ld-1.1"
@@ -171,25 +182,26 @@ module Fixtures
171
182
  begin
172
183
  result = case testType
173
184
  when "jld:ExpandTest"
174
- JSON::LD::API.expand(input_loc, options.merge(logger: logger))
185
+ JSON::LD::API.expand(input_loc, logger: logger, **options)
175
186
  when "jld:CompactTest"
176
- JSON::LD::API.compact(input_loc, context_json['@context'], options.merge(logger: logger))
187
+ JSON::LD::API.compact(input_loc, context_json['@context'], logger: logger, **options)
177
188
  when "jld:FlattenTest"
178
- JSON::LD::API.flatten(input_loc, context_loc, options.merge(logger: logger))
189
+ JSON::LD::API.flatten(input_loc, (context_json['@context'] if context_loc), logger: logger, **options)
179
190
  when "jld:FrameTest"
180
- JSON::LD::API.frame(input_loc, frame_loc, options.merge(logger: logger))
191
+ JSON::LD::API.frame(input_loc, frame_loc, logger: logger, **options)
181
192
  when "jld:FromRDFTest"
182
193
  # Use an array, to preserve input order
183
194
  repo = RDF::NQuads::Reader.open(input_loc) do |reader|
184
195
  reader.each_statement.to_a
185
- end.extend(RDF::Enumerable)
196
+ end.uniq.extend(RDF::Enumerable)
186
197
  logger.info "repo: #{repo.dump(id == '#t0012' ? :nquads : :trig)}"
187
- JSON::LD::API.fromRdf(repo, options.merge(logger: logger))
198
+ JSON::LD::API.fromRdf(repo, logger: logger, **options)
188
199
  when "jld:ToRDFTest"
189
200
  repo = RDF::Repository.new
190
- JSON::LD::API.toRdf(input_loc, options.merge(logger: logger)) do |statement|
201
+ JSON::LD::API.toRdf(input_loc, logger: logger, **options) do |statement|
191
202
  repo << statement
192
203
  end
204
+ logger.info "nq: #{repo.to_nquads}"
193
205
  repo
194
206
  else
195
207
  fail("Unknown test type: #{testType}")
@@ -222,19 +234,19 @@ module Fixtures
222
234
  expect do
223
235
  case t.testType
224
236
  when "jld:ExpandTest"
225
- JSON::LD::API.expand(t.input_loc, options.merge(logger: logger))
237
+ JSON::LD::API.expand(t.input_loc, logger: logger, **options)
226
238
  when "jld:CompactTest"
227
- JSON::LD::API.compact(t.input_loc, t.context_json['@context'], options.merge(logger: logger))
239
+ JSON::LD::API.compact(t.input_loc, t.context_json['@context'], logger: logger, **options)
228
240
  when "jld:FlattenTest"
229
- JSON::LD::API.flatten(t.input_loc, t.context_loc, options.merge(logger: logger))
241
+ JSON::LD::API.flatten(t.input_loc, t.context_loc, logger: logger, **options)
230
242
  when "jld:FrameTest"
231
- JSON::LD::API.frame(t.input_loc, t.frame_loc, options.merge(logger: logger))
243
+ JSON::LD::API.frame(t.input_loc, t.frame_loc, logger: logger, **options)
232
244
  when "jld:FromRDFTest"
233
245
  repo = RDF::Repository.load(t.input_loc)
234
246
  logger.info "repo: #{repo.dump(id == '#t0012' ? :nquads : :trig)}"
235
- JSON::LD::API.fromRdf(repo, options.merge(logger: logger))
247
+ JSON::LD::API.fromRdf(repo, logger: logger, **options)
236
248
  when "jld:ToRDFTest"
237
- JSON::LD::API.toRdf(t.input_loc, options.merge(logger: logger)) {}
249
+ JSON::LD::API.toRdf(t.input_loc, logger: logger, **options) {}
238
250
  else
239
251
  success("Unknown test type: #{testType}")
240
252
  end
@@ -286,8 +298,6 @@ module Fixtures
286
298
  end
287
299
  end
288
300
 
289
- REMOTE_PATH = "https://json-ld.org/test-suite/"
290
- LOCAL_PATH = ::File.expand_path("../json-ld.org/test-suite", __FILE__) + '/'
291
301
  ##
292
302
  # Document loader to use for tests having `useDocumentLoader` option
293
303
  #
@@ -299,25 +309,11 @@ module Fixtures
299
309
  # @yield remote_document
300
310
  # @yieldparam [RemoteDocument] remote_document
301
311
  # @raise [JsonLdError]
302
- def documentLoader(url, options = {}, &block)
303
- remote_document = nil
312
+ def documentLoader(url, **options, &block)
304
313
  options[:headers] ||= JSON::LD::API::OPEN_OPTS[:headers]
305
-
314
+ options[:headers][:link] = Array(options[:httpLink]).join(',') if options[:httpLink]
315
+
306
316
  url = url.to_s[5..-1] if url.to_s.start_with?("file:")
307
-
308
- if url.to_s.start_with?(REMOTE_PATH) && ::File.exist?(LOCAL_PATH) && url.to_s !~ /remote-doc/
309
- #puts "attempt to open #{filename_or_url} locally"
310
- local_filename = url.to_s.sub(REMOTE_PATH, LOCAL_PATH)
311
- if ::File.exist?(local_filename)
312
- remote_document = JSON::LD::API::RemoteDocument.new(url.to_s, ::File.read(local_filename))
313
- return block_given? ? yield(remote_document) : remote_document
314
- else
315
- raise JSON::LD::JsonLdError::LoadingDocumentFailed, "no such file #{local_filename}"
316
- end
317
- end
318
-
319
- # don't cache for these specs
320
- options = options.merge(use_net_http: true) if url.to_s =~ /remote-doc/
321
317
  JSON::LD::API.documentLoader(url, options, &block)
322
318
  rescue JSON::LD::JsonLdError::LoadingDocumentFailed, JSON::LD::JsonLdError::MultipleContextLinkHeaders
323
319
  raise unless options[:safe]