Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test to make sure parsing of lexically invalid literals still creates…

… proper RDF.

When serializing, recover from an attempt to generate a human-readable value for an invalid literal.
  • Loading branch information...
commit 7a966e48656b1365985ae29bb598b54db25c193f 1 parent f456726
@gkellogg authored
View
4 Gemfile
@@ -9,11 +9,13 @@ group :development do
gem 'open-uri-cached', '>= 0.0.3'
gem 'rdf-spec', :git => "https://github.com/gkellogg/rdf-spec.git", :branch => "0.4.x", :require => 'rdf/spec'
gem 'rdf-isomorphic', '>= 0.3.4', :require => 'rdf/isomorphic'
- gem 'rdf-n3', '>= 0.3.1', :require => 'rdf/n3'
+ gem 'rdf-n3', '>= 0.3.4', :require => 'rdf/n3'
+ gem 'rdf-rdfxml', '>= 0.3.3', :require => 'rdf/rdfxml'
gem 'rspec', '>= 2.1.0'
gem 'sxp', :git => "https://github.com/gkellogg/sxp-ruby.git", :branch => "query-algebra"
gem 'sparql-algebra', :git => "https://github.com/gkellogg/sparql-algebra.git", :require => 'sparql/algebra'
gem 'sparql-grammar', :git => "https://github.com/gkellogg/sparql-grammar.git", :require => 'sparql/grammar'
gem 'spira', '>= 0.0.12'
gem 'yard', '>= 0.6.4'
+ gem 'wirble'
end
View
5,056 example-files/openlinksw-pricing.html
5,056 additions, 0 deletions not shown
View
2  lib/rdf/rdfa/writer.rb
@@ -729,6 +729,8 @@ def get_value(literal)
else
literal.to_s
end
+ rescue
+ literal.to_s # When all else fails ...
end
# Haml rendering helper. Return an appropriate label for a resource.
View
734 spec/reader_spec.rb
@@ -2,7 +2,7 @@
require File.join(File.dirname(__FILE__), 'spec_helper')
describe RDF::RDFa::Format do
- context "should be discover 'rdfa'" do
+ context "should discover 'rdfa'" do
[
[:rdfa, RDF::RDFa::Format],
["etc/foaf.html", RDF::RDFa::Format],
@@ -37,7 +37,7 @@
end
describe "RDF::RDFa::Reader" do
- describe "discovery" do
+ context "discovery" do
{
"html" => RDF::Reader.for(:rdfa),
"etc/foaf.html" => RDF::Reader.for("etc/foaf.html"),
@@ -51,7 +51,7 @@
end
end
- describe :interface do
+ context :interface do
before(:each) do
@sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
@@ -96,426 +96,434 @@
end
end
- describe "parsing a simple doc" do
- before :each do
- sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:dc="http://purl.org/dc/elements/1.1/">
- <head>
- <title>Test 0001</title>
- </head>
- <body>
- <p>This photo was taken by <span class="author" about="photo1.jpg" property="dc:creator">Mark Birbeck</span>.</p>
- </body>
- </html>
- )
+ context "sanity checking" do
+ context "simple doc" do
+ before :each do
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <head>
+ <title>Test 0001</title>
+ </head>
+ <body>
+ <p>This photo was taken by <span class="author" about="photo1.jpg" property="dc:creator">Mark Birbeck</span>.</p>
+ </body>
+ </html>
+ )
- @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0001.xhtml", :validate => true)
- @statement = @graph.statements.first
- end
+ @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0001.xhtml", :validate => true)
+ @statement = @graph.statements.first
+ end
- it "should return 1 triple" do
- @graph.size.should == 1
- end
+ it "should return 1 triple" do
+ @graph.size.should == 1
+ end
- it "should have a subject with an expanded URI" do
- @statement.subject.should == RDF::URI('http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/photo1.jpg')
- end
+ it "should have a subject with an expanded URI" do
+ @statement.subject.should == RDF::URI('http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/photo1.jpg')
+ end
- it "should have a predicate of dc:creator" do
- @statement.predicate.should == RDF::DC11.creator
- end
+ it "should have a predicate of dc:creator" do
+ @statement.predicate.should == RDF::DC11.creator
+ end
- it "should have an object of type literal and value 'Mark Birkbeck'" do
- @statement.object.should == RDF::Literal("Mark Birbeck")
+ it "should have an object of type literal and value 'Mark Birkbeck'" do
+ @statement.object.should == RDF::Literal("Mark Birbeck")
+ end
end
end
- describe "parsing a simple doc without a base URI" do
- before :each do
- sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:dc="http://purl.org/dc/elements/1.1/">
- <body>
- <p>This photo was taken by <span class="author" about="_:photo" property="dc:creator">Mark Birbeck</span>.</p>
- </body>
- </html>
- )
-
- @graph = parse(sampledoc, :validate => true)
- @statement = @graph.statements.first
- end
+ context :features do
+ describe "XML Literal" do
+ before :each do
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <head>
+ <title>Test 0011</title>
+ </head>
+ <body>
+ <div about="">
+ Author: <span property="dc:creator">Albert Einstein</span>
+ <h2 property="dc:title" datatype="rdf:XMLLiteral">E = mc<sup>2</sup>: The Most Urgent Problem of Our Time</h2>
+ </div>
+ </body>
+ </html>
+ )
- it "should return 1 triple" do
- @graph.size.should == 1
- end
+ @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml", :validate => true)
+ end
- it "should have a Blank Node named 'photo' as the subject of the triple" do
- @statement.subject.should == RDF::Node('photo')
- end
+ it "should return 2 triples" do
+ @graph.size.should == 2
+ end
- it "should have a predicate of dc:creator" do
- @statement.predicate.should == RDF::DC11.creator
- end
+ it "should have a triple for the dc:creator of the document" do
+ @graph.should have_triple([
+ RDF::URI('http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml'),
+ RDF::DC11.creator,
+ "Albert Einstein"
+ ])
+ end
- it "should have an object of type literal and value 'Mark Birkbeck'" do
- @statement.object.should == RDF::Literal("Mark Birbeck")
+ it "should have an XML Literal for the dc:title of the document" do
+ begin
+ @graph.should have_triple([
+ RDF::URI('http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml'),
+ RDF::DC11.title,
+ RDF::Literal(%(E = mc<sup xmlns="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">2</sup>: The Most Urgent Problem of Our Time), :datatype => RDF.XMLLiteral)
+ ])
+ rescue RSpec::Expectations::ExpectationNotMetError => e
+ pending("XMLLiteral canonicalization not implemented yet")
+ end
+ end
end
- end
- describe "parsing a document containing an XML Literal" do
- before :each do
- sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
- <head>
- <title>Test 0011</title>
- </head>
- <body>
- <div about="">
- Author: <span property="dc:creator">Albert Einstein</span>
- <h2 property="dc:title" datatype="rdf:XMLLiteral">E = mc<sup>2</sup>: The Most Urgent Problem of Our Time</h2>
- </div>
- </body>
- </html>
- )
+ describe "bnodes" do
+ before :each do
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
+ xmlns:foaf="http://xmlns.com/foaf/0.1/">
+ <head>
+ <title>Test 0017</title>
+ </head>
+ <body>
+ <p>
+ <span about="[_:a]" property="foaf:name">Manu Sporny</span>
+ <span about="[_:a]" rel="foaf:knows" resource="[_:b]">knows</span>
+ <span about="[_:b]" property="foaf:name">Ralph Swick</span>.
+ </p>
+ </body>
+ </html>
+ )
+
+ @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0017.xhtml", :validate => true)
+ end
- @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml", :validate => true)
- end
+ it "should return 3 triples" do
+ @graph.size.should == 3
+ end
- it "should return 2 triples" do
- @graph.size.should == 2
- end
+ it "should have a triple for the foaf:name of BNode A" do
+ @graph.should have_triple([
+ RDF::Node('a'),
+ RDF::FOAF.name,
+ "Manu Sporny"
+ ])
+ end
- it "should have a triple for the dc:creator of the document" do
- @graph.should have_triple([
- RDF::URI('http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml'),
- RDF::DC11.creator,
- "Albert Einstein"
- ])
- end
+ it "should have a triple for the foaf:name of BNode B" do
+ @graph.should have_triple([
+ RDF::Node('b'),
+ RDF::FOAF.name,
+ "Ralph Swick"
+ ])
+ end
- it "should have an XML Literal for the dc:title of the document" do
- begin
+ it "should have a triple for BNode A knows BNode B" do
@graph.should have_triple([
- RDF::URI('http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml'),
- RDF::DC11.title,
- RDF::Literal(%(E = mc<sup xmlns="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">2</sup>: The Most Urgent Problem of Our Time), :datatype => RDF.XMLLiteral)
+ RDF::Node('a'),
+ RDF::FOAF.knows,
+ RDF::Node('b'),
])
- rescue RSpec::Expectations::ExpectationNotMetError => e
- pending("XMLLiteral canonicalization not implemented yet")
end
end
- end
-
- describe "parsing a document containing sereral bnodes" do
- before :each do
- sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
- xmlns:foaf="http://xmlns.com/foaf/0.1/">
- <head>
- <title>Test 0017</title>
- </head>
- <body>
- <p>
- <span about="[_:a]" property="foaf:name">Manu Sporny</span>
- <span about="[_:a]" rel="foaf:knows" resource="[_:b]">knows</span>
- <span about="[_:b]" property="foaf:name">Ralph Swick</span>.
- </p>
- </body>
- </html>
- )
- @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0017.xhtml", :validate => true)
- end
+ describe "typeof" do
+ before :each do
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
+ xmlns:foaf="http://xmlns.com/foaf/0.1/">
+ <head>
+ <title>Test 0049</title>
+ </head>
+ <body>
+ <div about="http://www.example.org/#me" typeof="foaf:Person">
+ <p property="foaf:name">John Doe</p>
+ </div>
+ </body>
+ </html>
+ )
+
+ @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0049.xhtml", :validate => true)
+ end
- it "should return 3 triples" do
- @graph.size.should == 3
- end
+ it "should return 2 triples" do
+ @graph.size.should == 2
+ end
- it "should have a triple for the foaf:name of BNode A" do
- @graph.should have_triple([
- RDF::Node('a'),
- RDF::FOAF.name,
- "Manu Sporny"
- ])
- end
+ it "should have a triple stating that #me is of type foaf:Person" do
+ @graph.should have_triple([
+ RDF::URI('http://www.example.org/#me'),
+ RDF.type,
+ RDF::FOAF.Person
+ ])
+ end
- it "should have a triple for the foaf:name of BNode B" do
- @graph.should have_triple([
- RDF::Node('b'),
- RDF::FOAF.name,
- "Ralph Swick"
- ])
+ it "should have a triple stating that #me has name 'John Doe'" do
+ @graph.should have_triple([
+ RDF::URI('http://www.example.org/#me'),
+ RDF::FOAF.name,
+ RDF::Literal("John Doe")
+ ])
+ end
end
- it "should have a triple for BNode A knows BNode B" do
- @graph.should have_triple([
- RDF::Node('a'),
- RDF::FOAF.knows,
- RDF::Node('b'),
- ])
- end
- end
+ describe "html>head>base" do
+ before :each do
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <head>
+ <base href="http://www.example.org/"></base>
+ <title>Test 0072</title>
+ </head>
+ <body>
+ <p about="faq">
+ Learn more by reading the example.org
+ <span property="dc:title">Example FAQ</span>.
+ </p>
+ </body>
+ </html>
+ )
+
+ @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0072.xhtml", :validate => true)
+ end
- describe "parsing a document that uses the typeof attribute" do
- before :each do
- sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
- xmlns:foaf="http://xmlns.com/foaf/0.1/">
- <head>
- <title>Test 0049</title>
- </head>
- <body>
- <div about="http://www.example.org/#me" typeof="foaf:Person">
- <p property="foaf:name">John Doe</p>
- </div>
- </body>
- </html>
- )
+ it "should return 1 triple" do
+ @graph.size.should == 1
+ end
- @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0049.xhtml", :validate => true)
+ it "should have the subject of the triple relative to the URI in base" do
+ @graph.should have_subject RDF::URI('http://www.example.org/faq')
+ end
end
- it "should return 2 triples" do
- @graph.size.should == 2
- end
+ context :profile do
+ describe "prefix" do
+ before :each do
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1">
+ <head>
+ <title>Test</title>
+ <base href="http://example.org/"/>
+ </head>
+ <body profile="http://rdfa.digitalbazaar.com/test-suite/test-cases/tests/../../profiles/basic">
+ <div about="#me">
+ <p>
+ <span property="foaf:name">Ivan Herman</span>
+ </p>
+ </div>
+ </body>
+ </html>
+ )
- it "should have a triple stating that #me is of type foaf:Person" do
- @graph.should have_triple([
- RDF::URI('http://www.example.org/#me'),
- RDF.type,
- RDF::FOAF.Person
- ])
- end
+ @graph = parse(sampledoc, :validate => true)
+ @statement = @graph.statements.first
+ end
- it "should have a triple stating that #me has name 'John Doe'" do
- @graph.should have_triple([
- RDF::URI('http://www.example.org/#me'),
- RDF::FOAF.name,
- RDF::Literal("John Doe")
- ])
- end
- end
+ it "should return 1 triple" do
+ @graph.size.should == 1
+ end
- describe "parsing a document with a <base> tag in the <head>" do
- before :each do
- sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1"
- xmlns:dc="http://purl.org/dc/elements/1.1/">
- <head>
- <base href="http://www.example.org/"></base>
- <title>Test 0072</title>
- </head>
- <body>
- <p about="faq">
- Learn more by reading the example.org
- <span property="dc:title">Example FAQ</span>.
- </p>
- </body>
- </html>
- )
+ it "should have a subject of http://example.org/#me" do
+ @statement.subject.should == RDF::URI('http://example.org/#me')
+ end
- @graph = parse(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0072.xhtml", :validate => true)
- end
+ it "should have a predicate of foaf:name" do
+ @statement.predicate.should == RDF::FOAF.name
+ end
- it "should return 1 triple" do
- @graph.size.should == 1
- end
+ it "should have an object with the literal 'Ivan Herman'" do
+ @statement.object.should == RDF::Literal('Ivan Herman')
+ end
+ end
- it "should have the subject of the triple relative to the URI in base" do
- @graph.should have_subject RDF::URI('http://www.example.org/faq')
- end
- end
+ describe "term" do
+ before :each do
+ sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1">
+ <head>
+ <title>Test</title>
+ <base href="http://example.org/"/>
+ </head>
+ <body profile="http://rdfa.digitalbazaar.com/test-suite/test-cases/tests/../../profiles/foaf">
+ <div about="#me">
+ <p>
+ <span property="name">Ivan Herman</span>
+ </p>
+ </div>
+ </body>
+ </html>
+ )
- describe "parsing a document with a profile containing a prefix mapping" do
- before :each do
- sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1">
- <head>
- <title>Test</title>
- <base href="http://example.org/"/>
- </head>
- <body profile="http://rdfa.digitalbazaar.com/test-suite/test-cases/tests/../../profiles/basic">
- <div about="#me">
- <p>
- <span property="foaf:name">Ivan Herman</span>
- </p>
- </div>
- </body>
- </html>
- )
-
- @graph = parse(sampledoc, :validate => true)
- @statement = @graph.statements.first
- end
+ @graph = parse(sampledoc, :validate => true)
+ @statement = @graph.statements.first
+ end
- it "should return 1 triple" do
- @graph.size.should == 1
- end
+ it "should return 1 triple" do
+ @graph.size.should == 1
+ end
- it "should have a subject of http://example.org/#me" do
- @statement.subject.should == RDF::URI('http://example.org/#me')
- end
+ it "should have a subject of http://example.org/#me" do
+ @statement.subject.should == RDF::URI('http://example.org/#me')
+ end
- it "should have a predicate of foaf:name" do
- @statement.predicate.should == RDF::FOAF.name
- end
+ it "should have a predicate of foaf:name" do
+ @statement.predicate.should == RDF::FOAF.name
+ end
- it "should have an object with the literal 'Ivan Herman'" do
- @statement.object.should == RDF::Literal('Ivan Herman')
- end
- end
+ it "should have an object with the literal 'Ivan Herman'" do
+ @statement.object.should == RDF::Literal('Ivan Herman')
+ end
+ end
- describe "parsing a document with a profile containing a term mapping" do
- before :each do
- sampledoc = %(<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.1">
- <head>
- <title>Test</title>
- <base href="http://example.org/"/>
- </head>
- <body profile="http://rdfa.digitalbazaar.com/test-suite/test-cases/tests/../../profiles/foaf">
- <div about="#me">
- <p>
- <span property="name">Ivan Herman</span>
- </p>
- </div>
- </body>
- </html>
- )
-
- @graph = parse(sampledoc, :validate => true)
- @statement = @graph.statements.first
- end
+ describe :parsing do
+ before(:each) do
+ @profile = StringIO.new(%q(<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE html>
+ <html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Test mappings</title>
+ </head>
+ <body prefix="rdfa: http://www.w3.org/ns/rdfa#">
+ <p typeof=""><span property="rdfa:uri">http://example.org/</span><span property="rdfa:prefix">foo</span></p>
+ <p typeof=""><span property="rdfa:uri">http://example.org/title</span><span property="rdfa:term">title</span></p>
+ </body>
+ </html>
+ ))
+ def @profile.content_type; "text/html"; end
+ def @profile.base_uri; "http://example.com/profile"; end
+
+ @doc = %(<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE html>
+ <html xmlns="http://www.w3.org/1999/xhtml">
+ <body profile="http://example.com/profile">
+ <div about="http://example.com/doc" typeof="foo:Agent">
+ <p property="title">A particular agent</p>
+ </div>
+ </body>
+ </html>
+ )
+
+ RDF::Util::File.stub!(:open_file).and_yield(@profile)
+
+ @profile_repository = RDF::Repository.new(:title => "Test Profile Repository")
+ @debug = []
+ @reader = RDF::RDFa::Reader.new(@doc, :profile_repository => @profile_repository, :debug => @debug, :validate => true)
+
+ @expected = RDF::Graph.new
+ @expected << [RDF::URI("http://example.com/doc"), RDF.type, RDF::URI("http://example.org/Agent")]
+ @expected << [RDF::URI("http://example.com/doc"), RDF::URI("http://example.org/title"), "A particular agent"]
+ end
- it "should return 1 triple" do
- @graph.size.should == 1
- end
+ it "parses profile" do
+ RDF::Reader.should_receive(:for).at_least(1).times.and_return(RDF::RDFa::Reader)
+ g = RDF::Graph.load(@profile)
+ g.count.should == 4
+ end
- it "should have a subject of http://example.org/#me" do
- @statement.subject.should == RDF::URI('http://example.org/#me')
- end
+ describe "new profile" do
+ subject do
+ # Clear vocabulary cache
+ RDF::RDFa::Profile.cache.send(:initialize)
+ RDF::Graph.new << @reader
+ end
- it "should have a predicate of foaf:name" do
- @statement.predicate.should == RDF::FOAF.name
- end
+ it "matches expected" do
+ subject.should be_equivalent_graph(@expected, :trace => @debug.join("\n"))
+ end
+ end
- it "should have an object with the literal 'Ivan Herman'" do
- @statement.object.should == RDF::Literal('Ivan Herman')
- end
- end
+ describe "cached profile" do
+ before(:each) do
+ # Clear vocabulary cache
+ RDF::RDFa::Profile.cache.send(:initialize)
+ @reader.each {|s|}
+ end
- describe :profiles do
- before(:each) do
- @profile = StringIO.new(%q(<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Test mappings</title>
- </head>
- <body prefix="rdfa: http://www.w3.org/ns/rdfa#">
- <p typeof=""><span property="rdfa:uri">http://example.org/</span><span property="rdfa:prefix">foo</span></p>
- <p typeof=""><span property="rdfa:uri">http://example.org/title</span><span property="rdfa:term">title</span></p>
- </body>
- </html>
- ))
- def @profile.content_type; "text/html"; end
- def @profile.base_uri; "http://example.com/profile"; end
-
- @doc = %(<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <body profile="http://example.com/profile">
- <div about="http://example.com/doc" typeof="foo:Agent">
- <p property="title">A particular agent</p>
- </div>
- </body>
- </html>
- )
+ it "should not re-parse profile" do
+ RDF::RDFa::Profile.cache.send(:initialize)
+ RDF::Reader.should_not_receive(:open).with("http://example.com/profile")
+ RDF::RDFa::Reader.new(@doc, :profile_repository => @profile_repository).each {|p|}
+ end
- RDF::Util::File.stub!(:open_file).and_yield(@profile)
+ it "should create vocab_cache" do
+ RDF::RDFa::Profile.cache.should be_a(RDF::Util::Cache)
+ end
+ end
- @profile_repository = RDF::Repository.new(:title => "Test Profile Repository")
- @debug = []
- @reader = RDF::RDFa::Reader.new(@doc, :profile_repository => @profile_repository, :debug => @debug, :validate => true)
-
- @expected = RDF::Graph.new
- @expected << [RDF::URI("http://example.com/doc"), RDF.type, RDF::URI("http://example.org/Agent")]
- @expected << [RDF::URI("http://example.com/doc"), RDF::URI("http://example.org/title"), "A particular agent"]
- end
+ describe "profile content" do
+ before(:each) do
+ bn_p = RDF::Node.new("prefix")
+ bn_t = RDF::Node.new("term")
+ ctx = RDF::URI("http://example.com/profile")
+ @profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.prefix, RDF::Literal.new("foo"), :context => ctx)
+ @profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.uri, RDF::Literal.new("http://example.org/"), :context => ctx)
+ @profile_repository << RDF::Statement.new(bn_t, RDF::RDFA.term, RDF::Literal.new("title"), :context => ctx)
+ @profile_repository << RDF::Statement.new(bn_t, RDF::RDFA.uri, RDF::Literal.new("http://example.org/title"), :context => ctx)
+
+ # Clear vocabulary cache
+ RDF::RDFa::Profile.cache.send(:initialize)
+ end
- it "parses profile" do
- RDF::Reader.should_receive(:for).at_least(1).times.and_return(RDF::RDFa::Reader)
- g = RDF::Graph.load(@profile)
- g.count.should == 4
- end
+ it "should not recieve RDF::Reader.open" do
+ RDF::Reader.should_not_receive(:open).with("http://example.com/profile")
+ @reader.each {|s|}
+ end
- describe "new profile" do
- subject do
- # Clear vocabulary cache
- RDF::RDFa::Profile.cache.send(:initialize)
- RDF::Graph.new << @reader
- end
-
- it "matches expected" do
- subject.should be_equivalent_graph(@expected, :trace => @debug.join("\n"))
- end
- end
-
- describe "cached profile" do
- before(:each) do
- # Clear vocabulary cache
- RDF::RDFa::Profile.cache.send(:initialize)
- @reader.each {|s|}
- end
-
- it "should not re-parse profile" do
- RDF::RDFa::Profile.cache.send(:initialize)
- RDF::Reader.should_not_receive(:open).with("http://example.com/profile")
- RDF::RDFa::Reader.new(@doc, :profile_repository => @profile_repository).each {|p|}
- end
-
- it "should create vocab_cache" do
- RDF::RDFa::Profile.cache.should be_a(RDF::Util::Cache)
+ it "matches expected" do
+ graph = RDF::Graph.new << @reader
+ graph.should be_equivalent_graph(@expected, :trace => @debug.join("\n"))
+ end
+ end
end
end
-
- describe "profile content" do
- before(:each) do
- bn_p = RDF::Node.new("prefix")
- bn_t = RDF::Node.new("term")
- ctx = RDF::URI("http://example.com/profile")
- @profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.prefix, RDF::Literal.new("foo"), :context => ctx)
- @profile_repository << RDF::Statement.new(bn_p, RDF::RDFA.uri, RDF::Literal.new("http://example.org/"), :context => ctx)
- @profile_repository << RDF::Statement.new(bn_t, RDF::RDFA.term, RDF::Literal.new("title"), :context => ctx)
- @profile_repository << RDF::Statement.new(bn_t, RDF::RDFA.uri, RDF::Literal.new("http://example.org/title"), :context => ctx)
-
- # Clear vocabulary cache
- RDF::RDFa::Profile.cache.send(:initialize)
- end
- it "should not recieve RDF::Reader.open" do
- RDF::Reader.should_not_receive(:open).with("http://example.com/profile")
- @reader.each {|s|}
- end
+ context "malformed datatypes" do
+ {
+ "xsd:boolean" => %w(foo),
+ "xsd:date" => %w(+2010-01-01Z 2010-01-01TFOO 02010-01-01 2010-1-1 0000-01-01 2011-07 2011),
+ "xsd:dateTime" => %w(+2010-01-01T00:00:00Z 2010-01-01T00:00:00FOO 02010-01-01T00:00:00 2010-01-01 2010-1-1T00:00:00 0000-01-01T00:00:00 2011-07 2011),
+ "xsd:decimal" => %w(12.xyz),
+ "xsd:double" => %w(xy.z +1.0z),
+ "xsd:integer" => %w(+1.0z foo),
+ "xsd:time" => %w(+00:00:00Z -00:00:00Z 00:00 00),
+ }.each do |dt, values|
+ context dt do
+ values.each do |value|
+ before(:all) do
+ @rdfa = %(<span about="" property="rdf:value" datatype="#{dt}" content="#{value}"/>)
+ dt_uri = RDF::XSD.send(dt.split(':').last)
+ @expected = RDF::Graph.new << RDF::Statement.new(RDF::URI(""), RDF.value, RDF::Literal.new(value, :datatype => dt_uri))
+ end
- it "matches expected" do
- graph = RDF::Graph.new << @reader
- graph.should be_equivalent_graph(@expected, :trace => @debug.join("\n"))
+ context "with #{value}" do
+ it "creates triple with invalid literal" do
+ parse(@rdfa, :validate => false).should be_equivalent_graph(@expected)
+ end
+
+ it "does not create triple when validating" do
+ lambda {parse(@rdfa, :validate => true)}.should raise_error(RDF::ReaderError)
+ end
+ end
+ end
+ end
end
end
end
-
+
+ context :validation do
+ end
+
# W3C Test suite from http://www.w3.org/2006/07/SWD/RDFa/testsuite/
describe "w3c test cases" do
require 'test_helper'

0 comments on commit 7a966e4

Please sign in to comment.
Something went wrong with that request. Please try again.