spec/n3reader_spec.rb in rdf-n3-0.2.1 vs spec/n3reader_spec.rb in rdf-n3-0.2.2
- old
+ new
@@ -1,6 +1,7 @@
# coding: utf-8
+$:.unshift "."
require File.join(File.dirname(__FILE__), 'spec_helper')
describe "RDF::N3::Reader" do
context "discovery" do
{
@@ -146,11 +147,10 @@
n3 = %(@prefix : <http://example.org/foo#> . :a :b "\\U00015678another" .)
if defined?(::Encoding)
statement = parse(n3).statements.first
statement.object.value.should == "\u{15678}another"
else
- lambda { parse(n3) }.should raise_error(RDF::ReaderError, "Long Unicode escapes no supported in Ruby 1.8")
pending("Not supported in Ruby 1.8")
end
end
it "should parse multi-line literal" do
@@ -265,21 +265,21 @@
%(<joe> <knows> <jane> .) => %(<http://a/joe> <http://a/knows> <http://a/jane> .),
%(:joe :knows :jane .) => %(<http://a/b#joe> <http://a/b#knows> <http://a/b#jane> .),
%(<#D%C3%BCrst> a "URI percent ^encoded as C3, BC".) => %(<http://a/b#D%C3%BCrst> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "URI percent ^encoded as C3, BC" .),
}.each_pair do |n3, nt|
it "for '#{n3}'" do
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
end
{
%(<#Dürst> a "URI straight in UTF8".) => %(<http://a/b#D\\u00FCrst> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "URI straight in UTF8" .),
- %(:a :related :\u3072\u3089\u304C\u306A.) => %(<http://a/b#a> <http://a/b#related> <http://a/b#\\u3072\\u3089\\u304C\\u306A> .),
+ #%(:a :related :ひらがな .) => %(<http://a/b#a> <http://a/b#related> <http://a/b#\\u3072\\u3089\\u304C\\u306A> .),
}.each_pair do |n3, nt|
it "for '#{n3}'" do
begin
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
rescue
if defined?(::Encoding)
raise
else
pending("Unicode URIs not supported in Ruby 1.8") { raise }
@@ -287,11 +287,11 @@
end
end
end
end
- it "should create URIRefs" do
+ it "should create URIs" do
n3doc = "<http://example.org/joe> <http://xmlns.com/foaf/0.1/knows> <http://example.org/jane> ."
statement = parse(n3doc).statements.first
statement.subject.class.should == RDF::URI
statement.object.class.should == RDF::URI
end
@@ -336,66 +336,66 @@
end
it "should use <> as a prefix and as a triple node" do
n3 = %(@prefix : <> . <> a :a.)
nt = %(
- <http://a/b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://a/b#a> .
+ <http://a/b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://a/ba> .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should use <#> as a prefix and as a triple node" do
n3 = %(@prefix : <#> . <#> a :a.)
nt = %(
<http://a/b#> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://a/b#a> .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should generate rdf:type for 'a'" do
n3 = %(@prefix a: <http://foo/a#> . a:b a <http://www.w3.org/2000/01/rdf-schema#resource> .)
nt = %(<http://foo/a#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#resource> .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should generate rdf:type for '@a'" do
n3 = %(@prefix a: <http://foo/a#> . a:b @a <http://www.w3.org/2000/01/rdf-schema#resource> .)
nt = %(<http://foo/a#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#resource> .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should generate inverse predicate for 'is xxx of'" do
n3 = %("value" is :prop of :b . :b :prop "value" .)
nt = %(<http://a/b#b> <http://a/b#prop> "value" .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should generate inverse predicate for '@is xxx @of'" do
n3 = %("value" @is :prop @of :b . :b :prop "value" .)
nt = %(<http://a/b#b> <http://a/b#prop> "value" .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should generate inverse predicate for 'is xxx of' with object list" do
n3 = %("value" is :prop of :b, :c . )
nt = %(
<http://a/b#b> <http://a/b#prop> "value" .
<http://a/b#c> <http://a/b#prop> "value" .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should generate predicate for 'has xxx'" do
n3 = %(@prefix a: <http://foo/a#> . a:b has :pred a:c .)
nt = %(<http://foo/a#b> <http://a/b#pred> <http://foo/a#c> .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should generate predicate for '@has xxx'" do
n3 = %(@prefix a: <http://foo/a#> . a:b @has :pred a:c .)
nt = %(<http://foo/a#b> <http://a/b#pred> <http://foo/a#c> .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should create log:implies predicate for '=>'" do
n3 = %(@prefix a: <http://foo/a#> . _:a => a:something .)
nt = %(_:a <http://www.w3.org/2000/10/swap/log#implies> <http://foo/a#something> .)
@@ -431,50 +431,74 @@
end
it "should accept empty localname" do
n3 = %(: : : .)
nt = %(<http://a/b#> <http://a/b#> <http://a/b#> .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should accept prefix with empty local name" do
n3 = %(@prefix foo: <http://foo/bar#> . foo: foo: foo: .)
nt = %(<http://foo/bar#> <http://foo/bar#> <http://foo/bar#> .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should do something for @forAll"
it "should do something for @forSome"
end
describe "namespaces" do
+ it "should not append # for http://foo/bar" do
+ n3 = %(@prefix : <http://foo/bar> . :a : :b .)
+ nt = %(
+ <http://foo/bara> <http://foo/bar> <http://foo/barb> .
+ )
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
+ end
+
+ it "should not append # for http://foo/bar/" do
+ n3 = %(@prefix : <http://foo/bar/> . :a : :b .)
+ nt = %(
+ <http://foo/bar/a> <http://foo/bar/> <http://foo/bar/b> .
+ )
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
+ end
+
+ it "should not append # for http://foo/bar#" do
+ n3 = %(@prefix : <http://foo/bar#> . :a : :b .)
+ nt = %(
+ <http://foo/bar#a> <http://foo/bar#> <http://foo/bar#b> .
+ )
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
+ end
+
it "should set absolute base" do
n3 = %(@base <http://foo/bar> . <> :a <b> . <#c> :d </e>.)
nt = %(
- <http://foo/bar> <http://foo/bara> <http://foo/b> .
- <http://foo/bar#c> <http://foo/bard> <http://foo/e> .
+ <http://foo/bar> <http://foo/bar#a> <http://foo/b> .
+ <http://foo/bar#c> <http://foo/bar#d> <http://foo/e> .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should set absolute base (trailing /)" do
n3 = %(@base <http://foo/bar/> . <> :a <b> . <#c> :d </e>.)
nt = %(
<http://foo/bar/> <http://foo/bar/a> <http://foo/bar/b> .
<http://foo/bar/#c> <http://foo/bar/d> <http://foo/e> .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should set absolute base (trailing #)" do
n3 = %(@base <http://foo/bar#> . <> :a <b> . <#c> :d </e>.)
nt = %(
- <http://foo/bar> <http://foo/bar#a> <http://foo/b> .
+ <http://foo/bar#> <http://foo/bar#a> <http://foo/b> .
<http://foo/bar#c> <http://foo/bar#d> <http://foo/e> .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should set relative base" do
n3 = %(
@base <http://example.org/products/>.
@@ -490,11 +514,11 @@
<http://example.org/products/prod123/> <http://example.org/products/prod123/a> <http://example.org/products/prod123/b> .
<http://example.org/products/prod123/> <http://example.org/products/prod123/a> <http://example.org/products/prod123/#c> .
<http://example.org/products/> <http://example.org/products/a> <http://example.org/products/d> .
<http://example.org/products/> <http://example.org/products/a> <http://example.org/products/#e> .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
end
describe "keywords" do
[
@@ -520,11 +544,11 @@
%(c :a :t) => %(<http://a/b#c> <http://a/b#a> <http://a/b#t> .),
%(:c a :t) => %(<http://a/b#c> <http://a/b#a> <http://a/b#t> .),
%(:c :a t) => %(<http://a/b#c> <http://a/b#a> <http://a/b#t> .),
}.each_pair do |n3, nt|
it "should use default_ns for '#{n3}'" do
- parse("@keywords . #{n3}", :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse("@keywords . #{n3}", :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
end
{
%(@keywords true. :a :b true.) => %(<http://a/b#a> <http://a/b#b> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .),
@@ -533,11 +557,11 @@
%(@keywords is. :a is :b @of :c.) => %(<http://a/b#c> <http://a/b#b> <http://a/b#a> .),
%(@keywords of. :a @is :b of :c.) => %(<http://a/b#c> <http://a/b#b> <http://a/b#a> .),
%(@keywords has. :a has :b :c.) => %(<http://a/b#a> <http://a/b#b> <http://a/b#c> .),
} .each_pair do |n3, nt|
it "should use keyword for '#{n3}'" do
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
end
it "should raise error if unknown keyword set" do
n3 = %(@keywords foo.)
@@ -571,25 +595,25 @@
)
nt = %(
<http://host/A#b> <http://host/A#p> <http://host/A#v> .
<http://host/Z#b> <http://host/Z#p> <http://host/Z#v> .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should process sequential @base declarations (swap base.n3)" do
n3 = %(
@base <http://example.com/ontolgies>. <a> :b <foo/bar#baz>.
@base <path/DFFERENT/>. <a2> :b2 <foo/bar#baz2>.
@prefix : <#>. <d3> :b3 <e3>.
)
nt = %(
- <http://example.com/a> <http://example.com/ontolgiesb> <http://example.com/foo/bar#baz> .
+ <http://example.com/a> <http://example.com/ontolgies#b> <http://example.com/foo/bar#baz> .
<http://example.com/path/DFFERENT/a2> <http://example.com/path/DFFERENT/b2> <http://example.com/path/DFFERENT/foo/bar#baz2> .
<http://example.com/path/DFFERENT/d3> <http://example.com/path/DFFERENT/#b3> <http://example.com/path/DFFERENT/e3> .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
end
describe "BNodes" do
it "should create BNode for identifier with '_' prefix" do
@@ -598,17 +622,19 @@
end
it "should create BNode for [] as subject" do
n3 = %(@prefix a: <http://foo/a#> . [] a:p a:v .)
nt = %(_:bnode0 <http://foo/a#p> <http://foo/a#v> .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
+ g = parse(n3, :base_uri => "http://a/b")
+ normalize_bnodes(g, "bnode0").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
end
it "should create BNode for [] as predicate" do
n3 = %(@prefix a: <http://foo/a#> . a:s [] a:o .)
nt = %(<http://foo/a#s> _:bnode0 <http://foo/a#o> .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
+ g = parse(n3, :base_uri => "http://a/b")
+ normalize_bnodes(g, "bnode0").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array, :anon => "bnode")
end
it "should create BNode for [] as object" do
n3 = %(@prefix a: <http://foo/a#> . a:s a:p [] .)
nt = %(<http://foo/a#s> <http://foo/a#p> _:bnode0 .)
@@ -783,20 +809,20 @@
<http://foo/a#b> <http://foo/a#p1> "123" .
<http://foo/a#b> <http://foo/a#p1> "456" .
<http://foo/a#b> <http://foo/a#p2> <http://foo/a#v1> .
<http://foo/a#b> <http://foo/a#p3> <http://foo/a#v2> .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
end
describe "lists" do
it "should parse empty list" do
n3 = %(@prefix :<http://example.com/>. :empty :set ().)
nt = %(
<http://example.com/empty> <http://example.com/set> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should parse list with single element" do
n3 = %(@prefix :<http://example.com/>. :gregg :wrote ("RdfContext").)
nt = %(
@@ -841,11 +867,11 @@
end
it "should add property to nil list" do
n3 = %(@prefix a: <http://foo/a#> . () a:prop "nilProp" .)
nt = %(<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://foo/a#prop> "nilProp" .)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
+ parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
end
it "should parse with compound items" do
n3 = %(
@prefix a: <http://foo/a#> .
@@ -855,25 +881,26 @@
("inner list") ) .
<http://resource1> a:p "value" .
)
nt = %(
- _:bnode0 <http://foo/a#p2> "v1" .
- _:bnode1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:bnode0 .
- _:bnode1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode2 .
- _:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://resource1> .
- _:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode3 .
- _:bnode3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://resource2> .
- _:bnode4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "inner list" .
- _:bnode4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
- _:bnode3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode5 .
+ <http://foo/a#a> <http://foo/a#p> _:bnode5 .
_:bnode5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:bnode4 .
- _:bnode5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
- <http://foo/a#a> <http://foo/a#p> _:bnode1 .
+ _:bnode5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode2 .
+ _:bnode4 <http://foo/a#p2> "v1" .
+ _:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://resource1> .
<http://resource1> <http://foo/a#p> "value" .
+ _:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode1 .
+ _:bnode1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://resource2> .
+ _:bnode1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:bnode0 .
+ _:bnode0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:bnode3 .
+ _:bnode0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
+ _:bnode3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "inner list" .
+ _:bnode3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
)
- parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
+ g = parse(n3, :base_uri => "http://a/b")
+ normalize_bnodes(g, "bnode0").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
end
end
# n3p tests taken from http://inamidst.com/n3p/test/
@@ -969,10 +996,10 @@
EOF
graph = parse(sampledoc, :base_uri => "http://www.w3.org/2000/10/rdf-tests/rdfcore/amp-in-url/Manifest.rdf")
graph.should be_equivalent_graph(sampledoc,
:about => "http://www.w3.org/2000/10/rdf-tests/rdfcore/amp-in-url/Manifest.rdf",
- :trace => @debug, :compare => :array
+ :trace => @debug
)
end
def parse(input, options = {})
@debug = []