json-ld 2.2.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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/remote-doc-manifest.jsonld")
7
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}remote-doc-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,12 +4,12 @@ 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/toRdf-manifest.jsonld")
7
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}toRdf-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
- skip "Native value fidelity" if %w(toRdf-0035-in.jsonld).include?(t.property('input'))
12
- pending "Generalized RDF" if %w(toRdf-0118-in.jsonld).include?(t.property('input'))
10
+ specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
11
+ skip "Native value fidelity" if %w(toRdf/0035-in.jsonld).include?(t.property('input'))
12
+ pending "Generalized RDF" if %w(toRdf/0118-in.jsonld).include?(t.property('input'))
13
13
  t.run self
14
14
  end
15
15
  end
@@ -356,6 +356,24 @@ describe JSON::LD::API do
356
356
  _:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
357
357
  )
358
358
  ],
359
+ "@list containing @list" => [
360
+ %q({
361
+ "@id": "http://example/A",
362
+ "http://example.com/foo": {"@list": [{"@list": ["baz"]}]}
363
+ }),
364
+ %q(
365
+ <http://example/A> <http://example.com/foo> (("baz")) .
366
+ )
367
+ ],
368
+ "@list containing empty @list" => [
369
+ %({
370
+ "@id": "http://example/A",
371
+ "http://example.com/foo": {"@list": [{"@list": []}]}
372
+ }),
373
+ %q(
374
+ <http://example/A> <http://example.com/foo> (()) .
375
+ )
376
+ ],
359
377
  }.each do |title, (js, ttl)|
360
378
  it title do
361
379
  ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
@@ -649,7 +667,7 @@ describe JSON::LD::API do
649
667
  %q(
650
668
  [<http://rdfs.org/sioc/ns#content> "foo"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>] .
651
669
  )
652
- ]
670
+ ],
653
671
  }.each do |title, (js, ttl)|
654
672
  it title do
655
673
  ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
@@ -657,6 +675,62 @@ describe JSON::LD::API do
657
675
  end
658
676
  end
659
677
  end
678
+
679
+ context "exceptions" do
680
+ {
681
+ "Invalid subject" => {
682
+ input: %({
683
+ "@id": "http://example.com/a b",
684
+ "http://example.com/foo": "bar"
685
+ }),
686
+ output: %()
687
+ },
688
+ "Invalid predicate" => {
689
+ input: %({
690
+ "@id": "http://example.com/foo",
691
+ "http://example.com/a b": "bar"
692
+ }),
693
+ output: %()
694
+ },
695
+ "Invalid object" => {
696
+ input: %({
697
+ "@id": "http://example.com/foo",
698
+ "http://example.com/bar": {"@id": "http://example.com/baz z"}
699
+ }),
700
+ output: %()
701
+ },
702
+ "Invalid type" => {
703
+ input: %({
704
+ "@id": "http://example.com/foo",
705
+ "@type": ["http://example.com/bar", "relative"]
706
+ }),
707
+ output: %(<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/bar> .)
708
+ },
709
+ "Invalid language" => {
710
+ input: %({
711
+ "@id": "http://example.com/foo",
712
+ "http://example.com/bar": {"@value": "bar", "@language": "a b"}
713
+ }),
714
+ output: %()
715
+ },
716
+ "Invalid datatype" => {
717
+ input: %({
718
+ "@id": "http://example.com/foo",
719
+ "http://example.com/bar": {"@value": "bar", "@type": "http://example.com/baz z"}
720
+ }),
721
+ output: %()
722
+ },
723
+ "Injected IRIs check" => {
724
+ input: %({
725
+ "@id": "http://foo/> <http://bar/> <http://baz> .\n<data:little> <data:bobby> <data:tables> .\n<data:in-ur-base",
726
+ "http://killin/#yer": "dudes"
727
+ }),
728
+ output: %()
729
+ },
730
+ }.each do |title, params|
731
+ it(title) {run_to_rdf params}
732
+ end
733
+ end
660
734
  end
661
735
 
662
736
  def parse(input, options = {})
@@ -665,4 +739,17 @@ describe JSON::LD::API do
665
739
  JSON::LD::API.toRdf(StringIO.new(input), options) {|st| graph << st}
666
740
  graph
667
741
  end
742
+
743
+ def run_to_rdf(params)
744
+ input, output, processingMode = params[:input], params[:output], params[:processingMode]
745
+ graph = params[:graph] || RDF::Graph.new
746
+ input = StringIO.new(input) if input.is_a?(String)
747
+ pending params.fetch(:pending, "test implementation") unless input
748
+ if params[:exception]
749
+ expect {JSON::LD::API.toRdf(input, {processingMode: processingMode}.merge(params))}.to raise_error(params[:exception])
750
+ else
751
+ JSON::LD::API.toRdf(input, base: params[:base], logger: logger, processingMode: processingMode) {|st| graph << st}
752
+ expect(graph).to be_equivalent_graph(output, logger: logger, inputDocument: input)
753
+ end
754
+ end
668
755
  end
@@ -191,11 +191,11 @@ describe JSON::LD::Writer do
191
191
 
192
192
  context "Writes fromRdf tests to isomorphic graph" do
193
193
  require 'suite_helper'
194
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/fromRdf-manifest.jsonld")
194
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}fromRdf-manifest.jsonld")
195
195
  describe m.name do
196
196
  m.entries.each do |t|
197
197
  next unless t.positiveTest? && !t.property('input').include?('0016')
198
- specify "#{t.property('input')}: #{t.name}" do
198
+ specify "#{t.property('@id')}: #{t.name}" do
199
199
  logger.info "test: #{t.inspect}"
200
200
  logger.info "source: #{t.input}"
201
201
  t.logger = logger
@@ -213,17 +213,16 @@ describe JSON::LD::Writer do
213
213
  end
214
214
  end unless ENV['CI']
215
215
 
216
- def parse(input, options = {})
217
- format = options.fetch(:format, :trig)
216
+ def parse(input, format: :trig, **options)
218
217
  reader = RDF::Reader.for(format)
219
218
  RDF::Repository.new << reader.new(input, options)
220
219
  end
221
220
 
222
221
  # Serialize ntstr to a string and compare against regexps
223
- def serialize(ntstr, options = {})
222
+ def serialize(ntstr, **options)
224
223
  g = ntstr.is_a?(String) ? parse(ntstr, options) : ntstr
225
224
  #logger.info g.dump(:ttl)
226
- result = JSON::LD::Writer.buffer(options.merge(logger: logger)) do |writer|
225
+ result = JSON::LD::Writer.buffer(logger: logger, **options) do |writer|
227
226
  writer << g
228
227
  end
229
228
  if $verbose
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-ld
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-13 00:00:00.000000000 Z
11
+ date: 2018-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdf
@@ -240,14 +240,14 @@ dependencies:
240
240
  requirements:
241
241
  - - "~>"
242
242
  - !ruby/object:Gem::Version
243
- version: '0.8'
243
+ version: 0.9.12
244
244
  type: :development
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
248
  - - "~>"
249
249
  - !ruby/object:Gem::Version
250
- version: '0.8'
250
+ version: 0.9.12
251
251
  description: JSON::LD parses and serializes JSON-LD into RDF and implements expansion,
252
252
  compaction and framing API interfaces.
253
253
  email: public-linked-json@w3.org
@@ -291,7 +291,6 @@ files:
291
291
  - spec/spec_helper.rb
292
292
  - spec/streaming_writer_spec.rb
293
293
  - spec/suite_compact_spec.rb
294
- - spec/suite_error_spec.rb
295
294
  - spec/suite_expand_spec.rb
296
295
  - spec/suite_flatten_spec.rb
297
296
  - spec/suite_frame_spec.rb
@@ -371,13 +370,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
371
370
  version: '0'
372
371
  requirements: []
373
372
  rubyforge_project:
374
- rubygems_version: 2.6.14
373
+ rubygems_version: 2.7.6
375
374
  signing_key:
376
375
  specification_version: 4
377
376
  summary: JSON-LD reader/writer for Ruby.
378
377
  test_files:
379
378
  - spec/spec_helper.rb
380
- - spec/suite_error_spec.rb
381
379
  - spec/api_spec.rb
382
380
  - spec/suite_from_rdf_spec.rb
383
381
  - spec/context_spec.rb
@@ -1,16 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
-
4
- describe JSON::LD do
5
- describe "test suite" do
6
- require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/error-manifest.jsonld")
8
- describe m.name do
9
- m.entries.each do |t|
10
- specify "#{t.property('input')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
11
- t.run self
12
- end
13
- end
14
- end
15
- end
16
- end unless ENV['CI']