require File.join(File.dirname(__FILE__), 'spec_helper') require 'rdfa_helper' # Time to add your specs! # http://rspec.info/ describe "RDFa parser" do it "should parse simple doc" do sampledoc = <<-EOF; Test 0001

This photo was taken by Mark Birbeck.

EOF parser = RdfaParser::RdfaParser.new parser.parse(sampledoc, "http://www.w3.org/2006/07/SWD/RDFa/testsuite/xhtml1-testcases/0001.xhtml") parser.graph.size.should == 1 parser.graph.to_rdfxml.should be_valid_xml end it "should parse XML Literal and generate valid XML" do sampledoc = <<-EOF Test 0011
Author: Albert Einstein

E = mc2: The Most Urgent Problem of Our Time

EOF parser = RdfaParser::RdfaParser.new parser.parse(sampledoc, "http://www.w3.org/2006/07/SWD/RDFa/testsuite/xhtml1-testcases/0011.xhtml") parser.graph.size.should == 2 xml = parser.graph.to_rdfxml xml.should be_valid_xml # Ensure that enclosed literal is also valid xml.should include("E = mc2: The Most Urgent Problem of Our Time") end it "should parse BNodes" do sampledoc = <<-EOF Test 0017

Manu Sporny knows Ralph Swick.

EOF parser = RdfaParser::RdfaParser.new parser.parse(sampledoc, "http://www.w3.org/2006/07/SWD/RDFa/testsuite/xhtml1-testcases/0011.xhtml") parser.graph.size.should == 3 xml = parser.graph.to_rdfxml xml.should be_valid_xml xml.should include("Ralph Swick") xml.should include("Manu Sporny") end # W3C Test suite from http://www.w3.org/2006/07/SWD/RDFa/testsuite/ describe "w3c xhtml1 testcases" do def self.test_cases RdfaHelper::TestCase.test_cases end test_cases.each do |t| #next unless t.name == "Test0100" specify "test #{t.name}: #{t.title}" do rdfa_string = File.read(t.informationResourceInput) rdfa_parser = RdfaParser::RdfaParser.new rdfa_parser.parse(rdfa_string, t.originalInformationResourceInput) query_string = t.informationResourceResults ? File.read(t.informationResourceResults) : "" if query_string.match(/UNION|OPTIONAL/) # Check triples, as Rasql doesn't implement UNION ntriples = File.read(t.informationResourceResults.sub("sparql", "nt")) parser = NTriplesParser.new(ntriples) rdfa_parser.graph.should be_equivalent_graph(parser.graph, t.information) else rdfa_parser.graph.should pass_query(query_string, t.information) end rdfa_parser.graph.to_rdfxml.should be_valid_xml end end end end