json-ld 3.1.3 → 3.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/VERSION +1 -1
- data/lib/json/ld.rb +3 -0
- data/lib/json/ld/api.rb +31 -24
- data/lib/json/ld/compact.rb +37 -21
- data/lib/json/ld/context.rb +532 -473
- data/lib/json/ld/expand.rb +131 -68
- data/lib/json/ld/from_rdf.rb +7 -8
- data/lib/json/ld/reader.rb +19 -10
- data/lib/json/ld/streaming_reader.rb +578 -0
- data/spec/context_spec.rb +4 -42
- data/spec/reader_spec.rb +33 -34
- data/spec/streaming_reader_spec.rb +237 -0
- data/spec/suite_helper.rb +14 -8
- metadata +6 -3
data/spec/context_spec.rb
CHANGED
@@ -56,13 +56,6 @@ describe JSON::LD::Context do
|
|
56
56
|
describe "#parse" do
|
57
57
|
context "remote" do
|
58
58
|
|
59
|
-
it "retrieves and parses a remote context document" 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_yield(remote_doc)
|
62
|
-
ec = subject.parse("http://example.com/context")
|
63
|
-
expect(ec.provided_context).to produce("http://example.com/context", logger)
|
64
|
-
end
|
65
|
-
|
66
59
|
it "fails given a missing remote @context" do
|
67
60
|
JSON::LD::Context.instance_variable_set(:@cache, nil)
|
68
61
|
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_raise(IOError)
|
@@ -190,12 +183,6 @@ describe JSON::LD::Context do
|
|
190
183
|
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
191
184
|
subject.parse(ctx)
|
192
185
|
end
|
193
|
-
|
194
|
-
it "does not use passed context as provided_context" do
|
195
|
-
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
196
|
-
ec = subject.parse(ctx)
|
197
|
-
expect(ec.provided_context).to produce(ctx, logger)
|
198
|
-
end
|
199
186
|
end
|
200
187
|
|
201
188
|
context "pre-loaded remote" do
|
@@ -645,14 +632,6 @@ describe JSON::LD::Context do
|
|
645
632
|
|
646
633
|
describe "#serialize" do
|
647
634
|
before {JSON::LD::Context.instance_variable_set(:@cache, nil)}
|
648
|
-
it "context document" do
|
649
|
-
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
650
|
-
ec = subject.parse("http://example.com/context")
|
651
|
-
expect(ec.serialize).to produce({
|
652
|
-
"@context" => "http://example.com/context"
|
653
|
-
}, logger)
|
654
|
-
end
|
655
|
-
|
656
635
|
it "context hash" do
|
657
636
|
ctx = {"foo" => "http://example.com/"}
|
658
637
|
|
@@ -684,7 +663,7 @@ describe JSON::LD::Context do
|
|
684
663
|
|
685
664
|
it "term mappings" do
|
686
665
|
c = subject.
|
687
|
-
parse({'foo' => "http://example.com/"})
|
666
|
+
parse({'foo' => "http://example.com/"})
|
688
667
|
expect(c.serialize).to produce({
|
689
668
|
"@context" => {
|
690
669
|
"foo" => "http://example.com/"
|
@@ -696,7 +675,7 @@ describe JSON::LD::Context do
|
|
696
675
|
it "@context" do
|
697
676
|
expect(subject.parse({
|
698
677
|
"foo" => {"@id" => "http://example.com/", "@context" => {"bar" => "http://example.com/baz"}}
|
699
|
-
}).
|
678
|
+
}).
|
700
679
|
serialize).to produce({
|
701
680
|
"@context" => {
|
702
681
|
"foo" => {
|
@@ -712,7 +691,6 @@ describe JSON::LD::Context do
|
|
712
691
|
'xsd' => "http://www.w3.org/2001/XMLSchema#",
|
713
692
|
'homepage' => {'@id' => RDF::Vocab::FOAF.homepage.to_s, '@type' => '@id'}
|
714
693
|
}).
|
715
|
-
send(:clear_provided_context).
|
716
694
|
serialize).to produce({
|
717
695
|
"@context" => {
|
718
696
|
"xsd" => RDF::XSD.to_uri.to_s,
|
@@ -725,7 +703,6 @@ describe JSON::LD::Context do
|
|
725
703
|
expect(subject.parse({
|
726
704
|
'knows' => {'@id' => RDF::Vocab::FOAF.knows.to_s, '@container' => '@list'}
|
727
705
|
}).
|
728
|
-
send(:clear_provided_context).
|
729
706
|
serialize).to produce({
|
730
707
|
"@context" => {
|
731
708
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
|
@@ -737,7 +714,6 @@ describe JSON::LD::Context do
|
|
737
714
|
expect(subject.parse({
|
738
715
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@set"}
|
739
716
|
}).
|
740
|
-
send(:clear_provided_context).
|
741
717
|
serialize).to produce({
|
742
718
|
"@context" => {
|
743
719
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@set"}
|
@@ -749,7 +725,6 @@ describe JSON::LD::Context do
|
|
749
725
|
expect(subject.parse({
|
750
726
|
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "en"}
|
751
727
|
}).
|
752
|
-
send(:clear_provided_context).
|
753
728
|
serialize).to produce({
|
754
729
|
"@context" => {
|
755
730
|
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "en"}
|
@@ -762,7 +737,6 @@ describe JSON::LD::Context do
|
|
762
737
|
"@language" => 'en',
|
763
738
|
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => 'en'}
|
764
739
|
}).
|
765
|
-
send(:clear_provided_context).
|
766
740
|
serialize).to produce({
|
767
741
|
"@context" => {
|
768
742
|
"@language" => 'en',
|
@@ -776,7 +750,6 @@ describe JSON::LD::Context do
|
|
776
750
|
"@language" => 'en',
|
777
751
|
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "de"}
|
778
752
|
}).
|
779
|
-
send(:clear_provided_context).
|
780
753
|
serialize).to produce({
|
781
754
|
"@context" => {
|
782
755
|
"@language" => 'en',
|
@@ -790,7 +763,6 @@ describe JSON::LD::Context do
|
|
790
763
|
"@language" => 'en',
|
791
764
|
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => nil}
|
792
765
|
}).
|
793
|
-
send(:clear_provided_context).
|
794
766
|
serialize).to produce({
|
795
767
|
"@context" => {
|
796
768
|
"@language" => 'en',
|
@@ -803,7 +775,6 @@ describe JSON::LD::Context do
|
|
803
775
|
expect(subject.parse({
|
804
776
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
|
805
777
|
}).
|
806
|
-
send(:clear_provided_context).
|
807
778
|
serialize).to produce({
|
808
779
|
"@context" => {
|
809
780
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
|
@@ -815,7 +786,6 @@ describe JSON::LD::Context do
|
|
815
786
|
expect(subject.parse({
|
816
787
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
|
817
788
|
}).
|
818
|
-
send(:clear_provided_context).
|
819
789
|
serialize).to produce({
|
820
790
|
"@context" => {
|
821
791
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
|
@@ -827,7 +797,6 @@ describe JSON::LD::Context do
|
|
827
797
|
expect(subject.parse({
|
828
798
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@json"}
|
829
799
|
}).
|
830
|
-
send(:clear_provided_context).
|
831
800
|
serialize).to produce({
|
832
801
|
"@context" => {
|
833
802
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@json"}
|
@@ -842,7 +811,6 @@ describe JSON::LD::Context do
|
|
842
811
|
"@container" => "@list"
|
843
812
|
}
|
844
813
|
}).
|
845
|
-
send(:clear_provided_context).
|
846
814
|
serialize).to produce({
|
847
815
|
"@context" => {
|
848
816
|
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
|
@@ -858,7 +826,6 @@ describe JSON::LD::Context do
|
|
858
826
|
"id" => "@id",
|
859
827
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
|
860
828
|
}).
|
861
|
-
send(:clear_provided_context).
|
862
829
|
serialize).to produce({
|
863
830
|
"@context" => {
|
864
831
|
"id" => "@id",
|
@@ -875,7 +842,6 @@ describe JSON::LD::Context do
|
|
875
842
|
"@type" => "@id"
|
876
843
|
}
|
877
844
|
}).
|
878
|
-
send(:clear_provided_context).
|
879
845
|
serialize).to produce({
|
880
846
|
"@context" => {
|
881
847
|
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
|
@@ -893,7 +859,6 @@ describe JSON::LD::Context do
|
|
893
859
|
"type" => "@type",
|
894
860
|
"foaf:homepage" => {"@type" => "@id"}
|
895
861
|
}).
|
896
|
-
send(:clear_provided_context).
|
897
862
|
serialize).to produce({
|
898
863
|
"@context" => {
|
899
864
|
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
|
@@ -908,7 +873,6 @@ describe JSON::LD::Context do
|
|
908
873
|
"container" => "@container",
|
909
874
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
|
910
875
|
}).
|
911
|
-
send(:clear_provided_context).
|
912
876
|
serialize).to produce({
|
913
877
|
"@context" => {
|
914
878
|
"container" => "@container",
|
@@ -922,7 +886,6 @@ describe JSON::LD::Context do
|
|
922
886
|
"ex" => 'http://example.org/',
|
923
887
|
"term" => {"@id" => "ex:term", "@type" => "ex:datatype"}
|
924
888
|
}).
|
925
|
-
send(:clear_provided_context).
|
926
889
|
serialize).to produce({
|
927
890
|
"@context" => {
|
928
891
|
"ex" => 'http://example.org/',
|
@@ -936,7 +899,6 @@ describe JSON::LD::Context do
|
|
936
899
|
"@vocab" => 'http://example.org/',
|
937
900
|
"term" => {"@id" => "http://example.org/term", "@type" => "datatype"}
|
938
901
|
}).
|
939
|
-
send(:clear_provided_context).
|
940
902
|
serialize).to produce({
|
941
903
|
"@context" => {
|
942
904
|
"@vocab" => 'http://example.org/',
|
@@ -1245,7 +1207,7 @@ describe JSON::LD::Context do
|
|
1245
1207
|
it "does not use @vocab if it would collide with a term" do
|
1246
1208
|
subject.set_mapping("name", "http://xmlns.com/foaf/0.1/name")
|
1247
1209
|
subject.set_mapping("ex", nil)
|
1248
|
-
expect(subject.compact_iri("http://example.org/name",
|
1210
|
+
expect(subject.compact_iri("http://example.org/name", vocab: true)).
|
1249
1211
|
not_to produce("name", logger)
|
1250
1212
|
end
|
1251
1213
|
|
@@ -1528,7 +1490,7 @@ describe JSON::LD::Context do
|
|
1528
1490
|
})
|
1529
1491
|
end
|
1530
1492
|
it "Compact @id that is a property IRI when @container is @list" do
|
1531
|
-
expect(ctx.compact_iri("http://example.org/ns#property",
|
1493
|
+
expect(ctx.compact_iri("http://example.org/ns#property", vocab: false)).
|
1532
1494
|
to produce("ex:property", logger)
|
1533
1495
|
end
|
1534
1496
|
end
|
data/spec/reader_spec.rb
CHANGED
@@ -43,40 +43,39 @@ describe JSON::LD::Reader do
|
|
43
43
|
{
|
44
44
|
plain: %q({
|
45
45
|
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
</script>),
|
46
|
+
"@id": "_:bnode1",
|
47
|
+
"@type": "foaf:Person",
|
48
|
+
"foaf:homepage": "http://example.com/bob/",
|
49
|
+
"foaf:name": "Bob"
|
50
|
+
}),
|
51
|
+
leading_comment: %q(
|
52
|
+
// A comment before content
|
53
|
+
{
|
54
|
+
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
55
|
+
"@id": "_:bnode1",
|
56
|
+
"@type": "foaf:Person",
|
57
|
+
"foaf:homepage": "http://example.com/bob/",
|
58
|
+
"foaf:name": "Bob"
|
59
|
+
}),
|
60
|
+
script: %q(<script type="application/ld+json">
|
61
|
+
{
|
62
|
+
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
63
|
+
"@id": "_:bnode1",
|
64
|
+
"@type": "foaf:Person",
|
65
|
+
"foaf:homepage": "http://example.com/bob/",
|
66
|
+
"foaf:name": "Bob"
|
67
|
+
}
|
68
|
+
</script>),
|
69
|
+
script_comments: %q(<script type="application/ld+json">
|
70
|
+
// A comment before content
|
71
|
+
{
|
72
|
+
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
73
|
+
"@id": "_:bnode1",
|
74
|
+
"@type": "foaf:Person",
|
75
|
+
"foaf:homepage": "http://example.com/bob/",
|
76
|
+
"foaf:name": "Bob"
|
77
|
+
}
|
78
|
+
</script>),
|
80
79
|
}.each do |variant, src|
|
81
80
|
context variant do
|
82
81
|
subject {src}
|
@@ -0,0 +1,237 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require 'rdf/spec/reader'
|
4
|
+
|
5
|
+
describe JSON::LD::Reader do
|
6
|
+
let!(:doap) {File.expand_path("../../etc/doap.jsonld", __FILE__)}
|
7
|
+
let!(:doap_nt) {File.expand_path("../../etc/doap.nt", __FILE__)}
|
8
|
+
let!(:doap_count) {File.open(doap_nt).each_line.to_a.length}
|
9
|
+
let(:logger) {RDF::Spec.logger}
|
10
|
+
|
11
|
+
after(:each) {|example| puts logger.to_s if example.exception}
|
12
|
+
|
13
|
+
it_behaves_like 'an RDF::Reader' do
|
14
|
+
let(:reader_input) {File.read(doap)}
|
15
|
+
let(:reader) {JSON::LD::Reader.new(reader_input, stream: true)}
|
16
|
+
let(:reader_count) {doap_count}
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when validating", pending: ("JRuby support for jsonlint" if RUBY_ENGINE == "jruby") do
|
20
|
+
it "detects invalid JSON" do
|
21
|
+
expect do |b|
|
22
|
+
described_class.new(StringIO.new(%({"a": "b", "a": "c"})), validate: true, logger: false).each_statement(&b)
|
23
|
+
end.to raise_error(RDF::ReaderError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context :interface do
|
28
|
+
{
|
29
|
+
plain: %q({
|
30
|
+
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
31
|
+
"@type": "foaf:Person",
|
32
|
+
"@id": "_:bnode1",
|
33
|
+
"foaf:homepage": "http://example.com/bob/",
|
34
|
+
"foaf:name": "Bob"
|
35
|
+
}),
|
36
|
+
leading_comment: %q(
|
37
|
+
// A comment before content
|
38
|
+
{
|
39
|
+
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
40
|
+
"@type": "foaf:Person",
|
41
|
+
"@id": "_:bnode1",
|
42
|
+
"foaf:homepage": "http://example.com/bob/",
|
43
|
+
"foaf:name": "Bob"
|
44
|
+
}),
|
45
|
+
script: %q(<script type="application/ld+json">
|
46
|
+
{
|
47
|
+
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
48
|
+
"@type": "foaf:Person",
|
49
|
+
"@id": "_:bnode1",
|
50
|
+
"foaf:homepage": "http://example.com/bob/",
|
51
|
+
"foaf:name": "Bob"
|
52
|
+
}
|
53
|
+
</script>),
|
54
|
+
script_comments: %q(<script type="application/ld+json">
|
55
|
+
// A comment before content
|
56
|
+
{
|
57
|
+
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
58
|
+
"@type": "foaf:Person",
|
59
|
+
"@id": "_:bnode1",
|
60
|
+
"foaf:homepage": "http://example.com/bob/",
|
61
|
+
"foaf:name": "Bob"
|
62
|
+
}
|
63
|
+
</script>),
|
64
|
+
}.each do |variant, src|
|
65
|
+
context variant do
|
66
|
+
subject {src}
|
67
|
+
|
68
|
+
describe "#initialize" do
|
69
|
+
it "yields reader given string" do
|
70
|
+
inner = double("inner")
|
71
|
+
expect(inner).to receive(:called).with(JSON::LD::Reader)
|
72
|
+
JSON::LD::Reader.new(subject, stream: true) do |reader|
|
73
|
+
inner.called(reader.class)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "yields reader given IO" do
|
78
|
+
inner = double("inner")
|
79
|
+
expect(inner).to receive(:called).with(JSON::LD::Reader)
|
80
|
+
JSON::LD::Reader.new(StringIO.new(subject), stream: true) do |reader|
|
81
|
+
inner.called(reader.class)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "returns reader" do
|
86
|
+
expect(JSON::LD::Reader.new(subject, stream: true)).to be_a(JSON::LD::Reader)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#each_statement" do
|
91
|
+
it "yields statements" do
|
92
|
+
inner = double("inner")
|
93
|
+
expect(inner).to receive(:called).with(RDF::Statement).exactly(3)
|
94
|
+
JSON::LD::Reader.new(subject, stream: true).each_statement do |statement|
|
95
|
+
inner.called(statement.class)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#each_triple" do
|
101
|
+
it "yields statements" do
|
102
|
+
inner = double("inner")
|
103
|
+
expect(inner).to receive(:called).exactly(3)
|
104
|
+
JSON::LD::Reader.new(subject, stream: true).each_triple do |subject, predicate, object|
|
105
|
+
inner.called(subject.class, predicate.class, object.class)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "Selected toRdf tests" do
|
114
|
+
{
|
115
|
+
"e004": {
|
116
|
+
input: %({
|
117
|
+
"@context": {
|
118
|
+
"mylist1": {"@id": "http://example.com/mylist1", "@container": "@list"}
|
119
|
+
},
|
120
|
+
"@id": "http://example.org/id",
|
121
|
+
"mylist1": { "@list": [ ] },
|
122
|
+
"http://example.org/list1": { "@list": [ null ] },
|
123
|
+
"http://example.org/list2": { "@list": [ {"@value": null} ] }
|
124
|
+
}),
|
125
|
+
expect: %(
|
126
|
+
<http://example.org/id> <http://example.com/mylist1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
127
|
+
<http://example.org/id> <http://example.org/list1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
128
|
+
<http://example.org/id> <http://example.org/list2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
129
|
+
)
|
130
|
+
},
|
131
|
+
"e015": {
|
132
|
+
input: %({
|
133
|
+
"@context": {
|
134
|
+
"myset2": {"@id": "http://example.com/myset2", "@container": "@set" }
|
135
|
+
},
|
136
|
+
"@id": "http://example.org/id",
|
137
|
+
"myset2": [ [], { "@set": [ null ] }, [ null ] ]
|
138
|
+
}),
|
139
|
+
expect: %(
|
140
|
+
)
|
141
|
+
},
|
142
|
+
"in06": {
|
143
|
+
input: %({
|
144
|
+
"@context": {
|
145
|
+
"@version": 1.1,
|
146
|
+
"@vocab": "http://example.org/vocab#",
|
147
|
+
"@base": "http://example.org/base/",
|
148
|
+
"id": "@id",
|
149
|
+
"type": "@type",
|
150
|
+
"data": "@nest",
|
151
|
+
"links": "@nest",
|
152
|
+
"relationships": "@nest",
|
153
|
+
"self": {"@type": "@id"},
|
154
|
+
"related": {"@type": "@id"}
|
155
|
+
},
|
156
|
+
"data": [{
|
157
|
+
"type": "articles",
|
158
|
+
"id": "1",
|
159
|
+
"author": {
|
160
|
+
"data": { "type": "people", "id": "9" }
|
161
|
+
}
|
162
|
+
}]
|
163
|
+
}),
|
164
|
+
expect: %(
|
165
|
+
<http://example.org/base/1> <http://example.org/vocab#author> <http://example.org/base/9> .
|
166
|
+
<http://example.org/base/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#articles> .
|
167
|
+
<http://example.org/base/9> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#people> .
|
168
|
+
),
|
169
|
+
pending: "@nest defining @id"
|
170
|
+
}
|
171
|
+
}.each do |name, params|
|
172
|
+
it name do
|
173
|
+
run_to_rdf params
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "test suite" do
|
179
|
+
require_relative 'suite_helper'
|
180
|
+
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::STREAM_SUITE}stream-toRdf-manifest.jsonld")
|
181
|
+
describe m.name do
|
182
|
+
m.entries.each do |t|
|
183
|
+
specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
|
184
|
+
pending "Generalized RDF" if t.options[:produceGeneralizedRdf]
|
185
|
+
pending "@nest defining @id" if %w(#tin06).include?(t.property('@id'))
|
186
|
+
pending "double @reverse" if %w(#te043).include?(t.property('@id'))
|
187
|
+
pending "graph map containing named graph" if %w(#te084 #te087 #te098 #te101 #te105 #te106).include?(t.property('@id'))
|
188
|
+
pending "named graphs" if %w(#t0029 #te021).include?(t.property('@id'))
|
189
|
+
|
190
|
+
if %w(#t0118).include?(t.property('@id'))
|
191
|
+
expect {t.run self}.to write(/Statement .* is invalid/).to(:error)
|
192
|
+
elsif %w(#twf07).include?(t.property('@id'))
|
193
|
+
expect {t.run self}.to write(/skipping graph statement within invalid graph name/).to(:error)
|
194
|
+
elsif %w(#te075).include?(t.property('@id'))
|
195
|
+
expect {t.run self}.to write(/is invalid/).to(:error)
|
196
|
+
elsif %w(#te005 #tpr34 #tpr35 #tpr36 #tpr37 #tpr38 #tpr39 #te119 #te120).include?(t.property('@id'))
|
197
|
+
expect {t.run self}.to write("beginning with '@' are reserved for future use").to(:error)
|
198
|
+
elsif %w(#te068).include?(t.property('@id'))
|
199
|
+
expect {t.run self}.to write("[DEPRECATION]").to(:error)
|
200
|
+
elsif %w(#twf05).include?(t.property('@id'))
|
201
|
+
expect {t.run self}.to write("@language must be valid BCP47").to(:error)
|
202
|
+
else
|
203
|
+
expect {t.run self}.not_to write.to(:error)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end unless ENV['CI']
|
209
|
+
|
210
|
+
def run_to_rdf(params)
|
211
|
+
input = params[:input]
|
212
|
+
logger.info("input: #{input}")
|
213
|
+
output = RDF::Repository.new
|
214
|
+
if params[:expect]
|
215
|
+
RDF::NQuads::Reader.new(params[:expect], validate: false) {|r| output << r}
|
216
|
+
logger.info("expect (quads): #{output.dump(:nquads, validate: false)}")
|
217
|
+
else
|
218
|
+
logger.info("expect: #{Regexp.new params[:exception]}")
|
219
|
+
end
|
220
|
+
|
221
|
+
graph = params[:graph] || RDF::Repository.new
|
222
|
+
pending params.fetch(:pending, "test implementation") if !input || params[:pending]
|
223
|
+
if params[:exception]
|
224
|
+
expect do |b|
|
225
|
+
JSON::LD::Reader.new(input, stream: true, validate: true, logger: false, **params).each_statement(&b)
|
226
|
+
end.to raise_error {|er| expect(er.message).to include params[:exception]}
|
227
|
+
else
|
228
|
+
if params[:write]
|
229
|
+
expect{JSON::LD::Reader.new(input, stream: true, logger: logger, **params) {|st| graph << st}}.to write(params[:write]).to(:error)
|
230
|
+
else
|
231
|
+
expect{JSON::LD::Reader.new(input, stream: true, logger: logger, **params) {|st| graph << st}}.not_to write.to(:error)
|
232
|
+
end
|
233
|
+
logger.info("results (quads): #{graph.dump(:nquads, validate: false)}")
|
234
|
+
expect(graph).to be_equivalent_graph(output, logger: logger, inputDocument: input)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|