json-ld 1.0.5 → 1.0.6
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.
- checksums.yaml +8 -8
- data/README.md +9 -8
- data/VERSION +1 -1
- data/bin/jsonld +2 -1
- data/lib/json/ld.rb +43 -42
- data/lib/json/ld/api.rb +184 -39
- data/lib/json/ld/compact.rb +1 -1
- data/lib/json/ld/context.rb +88 -58
- data/lib/json/ld/expand.rb +27 -25
- data/lib/json/ld/extensions.rb +0 -23
- data/lib/json/ld/flatten.rb +1 -1
- data/lib/json/ld/reader.rb +2 -2
- data/lib/json/ld/resource.rb +1 -1
- data/spec/api_spec.rb +3 -1
- data/spec/compact_spec.rb +6 -4
- data/spec/context_spec.rb +20 -35
- data/spec/expand_spec.rb +42 -22
- data/spec/frame_spec.rb +1 -1
- data/spec/from_rdf_spec.rb +4 -22
- data/spec/suite_compact_spec.rb +2 -19
- data/spec/suite_error_spec.rb +17 -0
- data/spec/suite_expand_spec.rb +2 -16
- data/spec/suite_flatten_spec.rb +2 -16
- data/spec/suite_frame_spec.rb +2 -16
- data/spec/suite_from_rdf_spec.rb +2 -18
- data/spec/suite_helper.rb +218 -60
- data/spec/suite_remote_doc_spec.rb +17 -0
- data/spec/suite_to_rdf_spec.rb +2 -19
- data/spec/to_rdf_spec.rb +5 -5
- data/spec/writer_spec.rb +3 -3
- metadata +8 -6
- data/spec/suite_error_expand_spec.rb +0 -23
data/lib/json/ld/extensions.rb
CHANGED
@@ -38,29 +38,6 @@ module RDF
|
|
38
38
|
Node.new(id + value.to_s)
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
|
-
class Literal
|
43
|
-
class Double
|
44
|
-
##
|
45
|
-
# Converts this literal into its canonical lexical representation.
|
46
|
-
# Update to use %.15E to avoid precision problems
|
47
|
-
def canonicalize!
|
48
|
-
@string = case
|
49
|
-
when @object.nan? then 'NaN'
|
50
|
-
when @object.infinite? then @object.to_s[0...-'inity'.length].upcase
|
51
|
-
when @object.zero? then '0.0E0'
|
52
|
-
else
|
53
|
-
i, f, e = ('%.15E' % @object.to_f).split(/[\.E]/)
|
54
|
-
f.sub!(/0*$/, '') # remove any trailing zeroes
|
55
|
-
f = '0' if f.empty? # ...but there must be a digit to the right of the decimal point
|
56
|
-
e.sub!(/^\+?0+(\d)$/, '\1') # remove the optional leading '+' sign and any extra leading zeroes
|
57
|
-
"#{i}.#{f}E#{e}"
|
58
|
-
end
|
59
|
-
@object = Float(@string) unless @object.nil?
|
60
|
-
self
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
41
|
end
|
65
42
|
|
66
43
|
class Array
|
data/lib/json/ld/flatten.rb
CHANGED
@@ -114,7 +114,7 @@ module JSON::LD
|
|
114
114
|
|
115
115
|
# If element has an @index member, set the @index member of node to its value. If node has already an @index member with a different value, a conflicting indexes error has been detected and processing is aborted. Otherwise, continue by removing the @index member from element.
|
116
116
|
if element.has_key?('@index')
|
117
|
-
raise
|
117
|
+
raise JsonLdError::ConflictingIndexes,
|
118
118
|
"Element already has index #{node['@index']} dfferent from #{element['@index']}" if
|
119
119
|
node['@index'] && node['@index'] != element['@index']
|
120
120
|
node['@index'] = element.delete('@index')
|
data/lib/json/ld/reader.rb
CHANGED
@@ -20,7 +20,7 @@ module JSON::LD
|
|
20
20
|
#
|
21
21
|
# @param [IO, File, String] input
|
22
22
|
# @param [Hash{Symbol => Object}] options
|
23
|
-
# any additional options (see `RDF::Reader#initialize`)
|
23
|
+
# any additional options (see `RDF::Reader#initialize` and {JSON::LD::API.initialize})
|
24
24
|
# @yield [reader] `self`
|
25
25
|
# @yieldparam [RDF::Reader] reader
|
26
26
|
# @yieldreturn [void] ignored
|
@@ -49,7 +49,7 @@ module JSON::LD
|
|
49
49
|
# @private
|
50
50
|
# @see RDF::Reader#each_statement
|
51
51
|
def each_statement(&block)
|
52
|
-
JSON::LD::API.toRDF(@doc, @options
|
52
|
+
JSON::LD::API.toRDF(@doc, @options).each do |statement|
|
53
53
|
# If RDF version is 1.0, fold literals with xsd:string to be just simple literals
|
54
54
|
statement.object.datatype = nil if
|
55
55
|
RDF::VERSION.to_s < "1.1" &&
|
data/lib/json/ld/resource.rb
CHANGED
@@ -128,7 +128,7 @@ module JSON::LD
|
|
128
128
|
end
|
129
129
|
|
130
130
|
compacted = nil
|
131
|
-
JSON::LD::API.expand(node_definition, @context) do |expanded|
|
131
|
+
JSON::LD::API.expand(node_definition, :expandContext => @context) do |expanded|
|
132
132
|
compacted = JSON::LD::API.compact(expanded, @context)
|
133
133
|
end
|
134
134
|
compacted.delete_if {|k, v| k == '@context'}
|
data/spec/api_spec.rb
CHANGED
@@ -18,7 +18,9 @@ describe JSON::LD::API do
|
|
18
18
|
|
19
19
|
context test do
|
20
20
|
it "expands" do
|
21
|
-
|
21
|
+
options = {:debug => @debug}
|
22
|
+
options[:expandContext] = File.open(context) if context
|
23
|
+
jld = JSON::LD::API.expand(File.open(filename), options)
|
22
24
|
jld.should produce(JSON.load(File.open(expanded)), @debug)
|
23
25
|
end if File.exist?(expanded)
|
24
26
|
|
data/spec/compact_spec.rb
CHANGED
@@ -378,8 +378,10 @@ describe JSON::LD::API do
|
|
378
378
|
end
|
379
379
|
|
380
380
|
context "context as reference" do
|
381
|
+
let(:remote_doc) do
|
382
|
+
JSON::LD::API::RemoteDocument.new("http://example.com/context", %q({"@context": {"b": "http://example.com/b"}}))
|
383
|
+
end
|
381
384
|
it "uses referenced context" do
|
382
|
-
ctx = StringIO.new(%q({"@context": {"b": "http://example.com/b"}}))
|
383
385
|
input = {
|
384
386
|
"http://example.com/b" => "c"
|
385
387
|
}
|
@@ -387,7 +389,7 @@ describe JSON::LD::API do
|
|
387
389
|
"@context" => "http://example.com/context",
|
388
390
|
"b" => "c"
|
389
391
|
}
|
390
|
-
|
392
|
+
JSON::LD::API.stub(:documentLoader).with("http://example.com/context").and_yield(remote_doc)
|
391
393
|
jld = JSON::LD::API.compact(input, "http://example.com/context", :debug => @debug, :validate => true)
|
392
394
|
jld.should produce(expected, @debug)
|
393
395
|
end
|
@@ -490,14 +492,14 @@ describe JSON::LD::API do
|
|
490
492
|
:input => {
|
491
493
|
"http://example.org/foo" => {"@list" => [{"@list" => ["baz"]}]}
|
492
494
|
},
|
493
|
-
:exception => JSON::LD::
|
495
|
+
:exception => JSON::LD::JsonLdError::ListOfLists
|
494
496
|
},
|
495
497
|
"@list containing @list (with coercion)" => {
|
496
498
|
:input => {
|
497
499
|
"@context" => {"http://example.org/foo" => {"@container" => "@list"}},
|
498
500
|
"http://example.org/foo" => [{"@list" => ["baz"]}]
|
499
501
|
},
|
500
|
-
:exception => JSON::LD::
|
502
|
+
:exception => JSON::LD::JsonLdError::ListOfLists
|
501
503
|
},
|
502
504
|
}.each do |title, params|
|
503
505
|
it title do
|
data/spec/context_spec.rb
CHANGED
@@ -25,38 +25,36 @@ end
|
|
25
25
|
describe JSON::LD::Context do
|
26
26
|
before(:each) {
|
27
27
|
@debug = []
|
28
|
-
|
28
|
+
}
|
29
|
+
let(:context) {JSON::LD::Context.new(:debug => @debug, :validate => true)}
|
30
|
+
let(:remote_doc) do
|
31
|
+
JSON::LD::API::RemoteDocument.new("http://example.com/context", %q({
|
29
32
|
"@context": {
|
30
33
|
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
31
34
|
"name": "http://xmlns.com/foaf/0.1/name",
|
32
35
|
"homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id"},
|
33
36
|
"avatar": {"@id": "http://xmlns.com/foaf/0.1/avatar", "@type": "@id"}
|
34
37
|
}
|
35
|
-
})
|
36
|
-
|
37
|
-
let(:context) {JSON::LD::Context.new(:debug => @debug, :validate => true)}
|
38
|
+
}))
|
39
|
+
end
|
38
40
|
subject {context}
|
39
41
|
|
40
42
|
describe "#parse" do
|
41
43
|
context "remote" do
|
42
|
-
before(:each) do
|
43
|
-
@ctx = StringIO.new(@ctx_json)
|
44
|
-
def @ctx.content_type; "application/ld+json"; end
|
45
|
-
end
|
46
44
|
|
47
45
|
it "retrieves and parses a remote context document" do
|
48
|
-
|
46
|
+
JSON::LD::API.stub(:documentLoader).with("http://example.com/context").and_yield(remote_doc)
|
49
47
|
ec = subject.parse("http://example.com/context")
|
50
48
|
ec.provided_context.should produce("http://example.com/context", @debug)
|
51
49
|
end
|
52
50
|
|
53
51
|
it "fails given a missing remote @context" do
|
54
|
-
|
55
|
-
lambda {subject.parse("http://example.com/context")}.should raise_error(JSON::LD::
|
52
|
+
JSON::LD::API.stub(:documentLoader).with("http://example.com/context").and_raise(IOError)
|
53
|
+
lambda {subject.parse("http://example.com/context")}.should raise_error(JSON::LD::JsonLdError::LoadingRemoteContextFailed, %r{http://example.com/context})
|
56
54
|
end
|
57
55
|
|
58
56
|
it "creates mappings" do
|
59
|
-
|
57
|
+
JSON::LD::API.stub(:documentLoader).with("http://example.com/context").and_yield(remote_doc)
|
60
58
|
ec = subject.parse("http://example.com/context")
|
61
59
|
ec.mappings.should produce({
|
62
60
|
"xsd" => "http://www.w3.org/2001/XMLSchema#",
|
@@ -71,9 +69,9 @@ describe JSON::LD::Context do
|
|
71
69
|
end
|
72
70
|
|
73
71
|
it "parses a referenced context at a relative URI" do
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
rd1 = JSON::LD::API::RemoteDocument.new("http://example.com/c1", %({"@context": "context"}))
|
73
|
+
JSON::LD::API.stub(:documentLoader).with("http://example.com/c1").and_yield(rd1)
|
74
|
+
JSON::LD::API.stub(:documentLoader).with("http://example.com/context").and_yield(remote_doc)
|
77
75
|
ec = subject.parse("http://example.com/c1")
|
78
76
|
ec.mappings.should produce({
|
79
77
|
"xsd" => "http://www.w3.org/2001/XMLSchema#",
|
@@ -261,7 +259,7 @@ describe JSON::LD::Context do
|
|
261
259
|
lambda {
|
262
260
|
ec = subject.parse(context)
|
263
261
|
ec.serialize.should produce({}, @debug)
|
264
|
-
}.should raise_error(JSON::LD::
|
262
|
+
}.should raise_error(JSON::LD::JsonLdError)
|
265
263
|
end
|
266
264
|
end
|
267
265
|
|
@@ -270,24 +268,14 @@ describe JSON::LD::Context do
|
|
270
268
|
lambda {
|
271
269
|
ec = subject.parse({kw => "http://example.com/"})
|
272
270
|
ec.serialize.should produce({}, @debug)
|
273
|
-
}.should raise_error(JSON::LD::
|
271
|
+
}.should raise_error(JSON::LD::JsonLdError)
|
274
272
|
end
|
275
273
|
|
276
274
|
it "does not redefine #{kw} with an @id" do
|
277
275
|
lambda {
|
278
276
|
ec = subject.parse({kw => {"@id" => "http://example.com/"}})
|
279
277
|
ec.serialize.should produce({}, @debug)
|
280
|
-
}.should raise_error(JSON::LD::
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
describe "Load Errors" do
|
286
|
-
{
|
287
|
-
"fixme" => "FIXME",
|
288
|
-
}.each do |title, context|
|
289
|
-
it title do
|
290
|
-
lambda { subject.parse(context) }.should raise_error(JSON::LD::InvalidContext::InvalidRemoteContext)
|
278
|
+
}.should raise_error(JSON::LD::JsonLdError)
|
291
279
|
end
|
292
280
|
end
|
293
281
|
end
|
@@ -295,10 +283,7 @@ describe JSON::LD::Context do
|
|
295
283
|
|
296
284
|
describe "#serialize" do
|
297
285
|
it "context document" do
|
298
|
-
|
299
|
-
def ctx.content_type; "application/ld+json"; end
|
300
|
-
|
301
|
-
RDF::Util::File.stub(:open_file).with("http://example.com/context").and_yield(ctx)
|
286
|
+
JSON::LD::API.stub(:documentLoader).with("http://example.com/context").and_yield(remote_doc)
|
302
287
|
ec = subject.parse("http://example.com/context")
|
303
288
|
ec.serialize.should produce({
|
304
289
|
"@context" => "http://example.com/context"
|
@@ -994,10 +979,10 @@ describe JSON::LD::Context do
|
|
994
979
|
"native date" => ["foo", Date.parse("2011-12-27Z"), {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
|
995
980
|
"native time" => ["foo", Time.parse("10:11:12Z"), {"@value" => "10:11:12Z", "@type" => RDF::XSD.time.to_s}],
|
996
981
|
"native dateTime" =>["foo", DateTime.parse("2011-12-27T10:11:12Z"), {"@value" => "2011-12-27T10:11:12Z", "@type" => RDF::XSD.dateTime.to_s}],
|
997
|
-
"rdf boolean" => ["foo", RDF::Literal(true), {"@value" => true}],
|
998
|
-
"rdf integer" => ["foo", RDF::Literal(1), {"@value" => 1}],
|
982
|
+
"rdf boolean" => ["foo", RDF::Literal(true), {"@value" => "true", "@type" => RDF::XSD.boolean.to_s}],
|
983
|
+
"rdf integer" => ["foo", RDF::Literal(1), {"@value" => "1", "@type" => RDF::XSD.integer.to_s}],
|
999
984
|
"rdf decimal" => ["foo", RDF::Literal::Decimal.new(1.1), {"@value" => "1.1", "@type" => RDF::XSD.decimal.to_s}],
|
1000
|
-
"rdf double" => ["foo", RDF::Literal::Double.new(1.1), {"@value" => 1.
|
985
|
+
"rdf double" => ["foo", RDF::Literal::Double.new(1.1), {"@value" => "1.1E0", "@type" => RDF::XSD.double.to_s}],
|
1001
986
|
"rdf URI" => ["foo", RDF::URI("foo"), {"@id" => "foo"}],
|
1002
987
|
"rdf date " => ["foo", RDF::Literal(Date.parse("2011-12-27Z")), {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
|
1003
988
|
"rdf nonNeg" => ["foo", RDF::Literal::NonNegativeInteger.new(1), {"@value" => "1", "@type" => RDF::XSD.nonNegativeInteger}],
|
data/spec/expand_spec.rb
CHANGED
@@ -67,7 +67,7 @@ describe JSON::LD::API do
|
|
67
67
|
}
|
68
68
|
}.each_pair do |title, params|
|
69
69
|
it title do
|
70
|
-
jld = JSON::LD::API.expand(params[:input],
|
70
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
71
71
|
jld.should produce(params[:output], @debug)
|
72
72
|
end
|
73
73
|
end
|
@@ -114,7 +114,7 @@ describe JSON::LD::API do
|
|
114
114
|
},
|
115
115
|
}.each do |title, params|
|
116
116
|
it title do
|
117
|
-
jld = JSON::LD::API.expand(params[:input],
|
117
|
+
jld = JSON::LD::API.expand(params[:input], :base => "http://example.org/", :debug => @debug)
|
118
118
|
jld.should produce(params[:output], @debug)
|
119
119
|
end
|
120
120
|
end
|
@@ -173,7 +173,7 @@ describe JSON::LD::API do
|
|
173
173
|
},
|
174
174
|
}.each do |title, params|
|
175
175
|
it title do
|
176
|
-
jld = JSON::LD::API.expand(params[:input],
|
176
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
177
177
|
jld.should produce(params[:output], @debug)
|
178
178
|
end
|
179
179
|
end
|
@@ -228,7 +228,7 @@ describe JSON::LD::API do
|
|
228
228
|
},
|
229
229
|
}.each do |title, params|
|
230
230
|
it title do
|
231
|
-
jld = JSON::LD::API.expand(params[:input],
|
231
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
232
232
|
jld.should produce(params[:output], @debug)
|
233
233
|
end
|
234
234
|
end
|
@@ -256,7 +256,7 @@ describe JSON::LD::API do
|
|
256
256
|
},
|
257
257
|
}.each do |title, params|
|
258
258
|
it title do
|
259
|
-
jld = JSON::LD::API.expand(params[:input],
|
259
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
260
260
|
jld.should produce(params[:output], @debug)
|
261
261
|
end
|
262
262
|
end
|
@@ -300,7 +300,7 @@ describe JSON::LD::API do
|
|
300
300
|
}
|
301
301
|
}.each do |title, params|
|
302
302
|
it title do
|
303
|
-
jld = JSON::LD::API.expand(params[:input],
|
303
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
304
304
|
jld.should produce(params[:output], @debug)
|
305
305
|
end
|
306
306
|
end
|
@@ -328,7 +328,7 @@ describe JSON::LD::API do
|
|
328
328
|
},
|
329
329
|
}.each do |title, params|
|
330
330
|
it title do
|
331
|
-
jld = JSON::LD::API.expand(params[:input],
|
331
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
332
332
|
jld.should produce(params[:output], @debug)
|
333
333
|
end
|
334
334
|
end
|
@@ -394,7 +394,7 @@ describe JSON::LD::API do
|
|
394
394
|
}
|
395
395
|
}.each do |title, params|
|
396
396
|
it title do
|
397
|
-
jld = JSON::LD::API.expand(params[:input],
|
397
|
+
jld = JSON::LD::API.expand(params[:input],
|
398
398
|
:base => "http://foo/bar/",
|
399
399
|
:debug => @debug)
|
400
400
|
jld.should produce(params[:output], @debug)
|
@@ -451,7 +451,7 @@ describe JSON::LD::API do
|
|
451
451
|
]}
|
452
452
|
}.each do |title, params|
|
453
453
|
it title do
|
454
|
-
jld = JSON::LD::API.expand(params[:input],
|
454
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug, :base => 'http://example/')
|
455
455
|
jld.should produce(params[:output], @debug)
|
456
456
|
end
|
457
457
|
end
|
@@ -530,7 +530,7 @@ describe JSON::LD::API do
|
|
530
530
|
}
|
531
531
|
}.each do |title, params|
|
532
532
|
it title do
|
533
|
-
jld = JSON::LD::API.expand(params[:input],
|
533
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
534
534
|
jld.should produce(params[:output], @debug)
|
535
535
|
end
|
536
536
|
end
|
@@ -583,7 +583,7 @@ describe JSON::LD::API do
|
|
583
583
|
},
|
584
584
|
}.each do |title, params|
|
585
585
|
it title do
|
586
|
-
jld = JSON::LD::API.expand(params[:input],
|
586
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
587
587
|
jld.should produce(params[:output], @debug)
|
588
588
|
end
|
589
589
|
end
|
@@ -651,7 +651,7 @@ describe JSON::LD::API do
|
|
651
651
|
}
|
652
652
|
}.each do |title, params|
|
653
653
|
it title do
|
654
|
-
jld = JSON::LD::API.expand(params[:input],
|
654
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
655
655
|
jld.should produce(params[:output], @debug)
|
656
656
|
end
|
657
657
|
end
|
@@ -748,7 +748,7 @@ describe JSON::LD::API do
|
|
748
748
|
},
|
749
749
|
}.each do |title, params|
|
750
750
|
it title do
|
751
|
-
jld = JSON::LD::API.expand(params[:input],
|
751
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
752
752
|
jld.should produce(params[:output], @debug)
|
753
753
|
end
|
754
754
|
end
|
@@ -783,7 +783,7 @@ describe JSON::LD::API do
|
|
783
783
|
},
|
784
784
|
}.each do |title, params|
|
785
785
|
it title do
|
786
|
-
jld = JSON::LD::API.expand(params[:input],
|
786
|
+
jld = JSON::LD::API.expand(params[:input], :debug => @debug)
|
787
787
|
jld.should produce(params[:output], @debug)
|
788
788
|
end
|
789
789
|
end
|
@@ -793,43 +793,63 @@ describe JSON::LD::API do
|
|
793
793
|
{
|
794
794
|
"non-null @value and null @type" => {
|
795
795
|
:input => {"http://example.com/foo" => {"@value" => "foo", "@type" => nil}},
|
796
|
-
:exception => JSON::LD::
|
796
|
+
:exception => JSON::LD::JsonLdError::InvalidTypeValue
|
797
797
|
},
|
798
798
|
"non-null @value and null @language" => {
|
799
799
|
:input => {"http://example.com/foo" => {"@value" => "foo", "@language" => nil}},
|
800
|
-
:exception => JSON::LD::
|
800
|
+
:exception => JSON::LD::JsonLdError::InvalidLanguageTaggedString
|
801
801
|
},
|
802
802
|
"value with null language" => {
|
803
803
|
:input => {
|
804
804
|
"@context" => {"@language" => "en"},
|
805
805
|
"http://example.org/nolang" => {"@value" => "no language", "@language" => nil}
|
806
806
|
},
|
807
|
-
:exception => JSON::LD::
|
807
|
+
:exception => JSON::LD::JsonLdError::InvalidLanguageTaggedString
|
808
808
|
},
|
809
809
|
"@list containing @list" => {
|
810
810
|
:input => {
|
811
811
|
"http://example.com/foo" => {"@list" => [{"@list" => ["baz"]}]}
|
812
812
|
},
|
813
|
-
:exception => JSON::LD::
|
813
|
+
:exception => JSON::LD::JsonLdError::ListOfLists
|
814
814
|
},
|
815
815
|
"@list containing @list (with coercion)" => {
|
816
816
|
:input => {
|
817
817
|
"@context" => {"foo" => {"@id" => "http://example.com/foo", "@container" => "@list"}},
|
818
818
|
"foo" => [{"@list" => ["baz"]}]
|
819
819
|
},
|
820
|
-
:exception => JSON::LD::
|
820
|
+
:exception => JSON::LD::JsonLdError::ListOfLists
|
821
821
|
},
|
822
822
|
"coerced @list containing an array" => {
|
823
823
|
:input => {
|
824
824
|
"@context" => {"foo" => {"@id" => "http://example.com/foo", "@container" => "@list"}},
|
825
825
|
"foo" => [["baz"]]
|
826
826
|
},
|
827
|
-
:exception => JSON::LD::
|
827
|
+
:exception => JSON::LD::JsonLdError::ListOfLists
|
828
828
|
},
|
829
|
+
"@reverse object with an @id property" => {
|
830
|
+
:input => JSON.parse(%({
|
831
|
+
"@id": "http://example/foo",
|
832
|
+
"@reverse": {
|
833
|
+
"@id": "http://example/bar"
|
834
|
+
}
|
835
|
+
})),
|
836
|
+
:exception => JSON::LD::JsonLdError::InvalidReversePropertyMap,
|
837
|
+
},
|
838
|
+
"colliding keywords" => {
|
839
|
+
:input => JSON.parse(%({
|
840
|
+
"@context": {
|
841
|
+
"id": "@id",
|
842
|
+
"ID": "@id"
|
843
|
+
},
|
844
|
+
"id": "http://example/foo",
|
845
|
+
"ID": "http://example/bar"
|
846
|
+
})),
|
847
|
+
:exception => JSON::LD::JsonLdError::CollidingKeywords,
|
848
|
+
}
|
829
849
|
}.each do |title, params|
|
830
850
|
it title do
|
831
|
-
#JSON::LD::API.expand(params[:input],
|
832
|
-
lambda {JSON::LD::API.expand(params[:input]
|
851
|
+
#JSON::LD::API.expand(params[:input], :debug => @debug).should produce([], @debug)
|
852
|
+
lambda {JSON::LD::API.expand(params[:input])}.should raise_error(params[:exception])
|
833
853
|
end
|
834
854
|
end
|
835
855
|
end
|
data/spec/frame_spec.rb
CHANGED
@@ -505,7 +505,7 @@ describe JSON::LD::API do
|
|
505
505
|
begin
|
506
506
|
jld = JSON::LD::API.frame(params[:input], params[:frame], :debug => @debug)
|
507
507
|
jld.should produce(params[:output], @debug)
|
508
|
-
rescue JSON::LD::
|
508
|
+
rescue JSON::LD::JsonLdError, JSON::LD::JsonLdError, JSON::LD::InvalidFrame => e
|
509
509
|
fail("#{e.class}: #{e.message}\n" +
|
510
510
|
"#{@debug.join("\n")}\n" +
|
511
511
|
"Backtrace:\n#{e.backtrace.join("\n")}")
|
data/spec/from_rdf_spec.rb
CHANGED
@@ -69,7 +69,7 @@ describe JSON::LD::API do
|
|
69
69
|
|
70
70
|
it "integer" do
|
71
71
|
input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1 .)
|
72
|
-
serialize(input).should produce([{
|
72
|
+
serialize(input, :useNativeTypes => true).should produce([{
|
73
73
|
'@id' => "http://example.com/a",
|
74
74
|
"http://example.com/b" => [{"@value" => 1}]
|
75
75
|
}], @debug)
|
@@ -85,7 +85,7 @@ describe JSON::LD::API do
|
|
85
85
|
|
86
86
|
it "boolean" do
|
87
87
|
input = %(@prefix ex: <http://example.com/> . ex:a ex:b true .)
|
88
|
-
serialize(input).should produce([{
|
88
|
+
serialize(input, :useNativeTypes => true).should produce([{
|
89
89
|
'@id' => "http://example.com/a",
|
90
90
|
"http://example.com/b" => [{"@value" => true}]
|
91
91
|
}], @debug)
|
@@ -101,7 +101,7 @@ describe JSON::LD::API do
|
|
101
101
|
|
102
102
|
it "decmal" do
|
103
103
|
input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0 .)
|
104
|
-
serialize(input).should produce([{
|
104
|
+
serialize(input, :useNativeTypes => true).should produce([{
|
105
105
|
'@id' => "http://example.com/a",
|
106
106
|
"http://example.com/b" => [{"@value" => "1.0", "@type" => "http://www.w3.org/2001/XMLSchema#decimal"}]
|
107
107
|
}], @debug)
|
@@ -109,7 +109,7 @@ describe JSON::LD::API do
|
|
109
109
|
|
110
110
|
it "double" do
|
111
111
|
input = %(@prefix ex: <http://example.com/> . ex:a ex:b 1.0e0 .)
|
112
|
-
serialize(input).should produce([{
|
112
|
+
serialize(input, :useNativeTypes => true).should produce([{
|
113
113
|
'@id' => "http://example.com/a",
|
114
114
|
"http://example.com/b" => [{"@value" => 1.0E0}]
|
115
115
|
}], @debug)
|
@@ -337,24 +337,6 @@ describe JSON::LD::API do
|
|
337
337
|
end
|
338
338
|
end
|
339
339
|
end
|
340
|
-
|
341
|
-
context "useRdfType option" do
|
342
|
-
it "uses @type if set to false" do
|
343
|
-
input = %(@prefix ex: <http://example.com/> . ex:a a ex:b .)
|
344
|
-
serialize(input, :useRdfType => false).should produce([{
|
345
|
-
'@id' => "http://example.com/a",
|
346
|
-
"@type" => ["http://example.com/b"]
|
347
|
-
}], @debug)
|
348
|
-
end
|
349
|
-
|
350
|
-
it "does not use @type if set to true" do
|
351
|
-
input = %(@prefix ex: <http://example.com/> . ex:a a ex:b .)
|
352
|
-
serialize(input, :useRdfType => true).should produce([{
|
353
|
-
'@id' => "http://example.com/a",
|
354
|
-
'@type' => ["http://example.com/b"]
|
355
|
-
}], @debug)
|
356
|
-
end
|
357
|
-
end
|
358
340
|
|
359
341
|
context "problems" do
|
360
342
|
{
|