<commit_before>require File.join(File.dirname(__FILE__), 'spec_helper')
require 'rdf/spec/format'
require 'rdf/spec/reader'
require 'rdf/spec/writer'

describe RDF::Raptor::RDFXML::Format do
  before :each do
    @format_class = RDF::Raptor::RDFXML::Format
  end

  it_should_behave_like RDF_Format
  
  it "should be discoverable" do
    formats = [
      RDF::Format.for(:rdfxml),
      RDF::Format.for("input.rdf"),
      RDF::Format.for(:file_name      => "input.rdf"),
      RDF::Format.for(:file_extension => "rdf"),
      RDF::Format.for(:content_type   => "application/rdf+xml"),
    ]
    formats.each { |format| format.should == RDF::Raptor::RDFXML::Format }
  end
end

describe RDF::Raptor::RDFXML::Reader do
  before :each do
    @reader = RDF::Raptor::RDFXML::Reader.new(StringIO.new(""))
  end

  it_should_behave_like RDF_Reader
  
  it "should be discoverable" do
    readers = [
      RDF::Reader.for(:rdfxml),
      RDF::Reader.for("input.rdf"),
      RDF::Reader.for(:file_name      => "input.rdf"),
      RDF::Reader.for(:file_extension => "rdf"),
      RDF::Reader.for(:content_type   => "application/rdf+xml"),
    ]
    readers.each { |reader| reader.should == RDF::Raptor::RDFXML::Reader }
  end
  
  context :interface do
    before(:each) do
      @reader = RDF::Raptor::RDFXML::Reader.new(%q(<?xml version="1.0" ?>
        <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:ex="http://www.example.org/" xml:lang="en" xml:base="http://www.example.org/foo">
          <ex:Thing rdf:about="http://example.org/joe" ex:name="bar">
            <ex:belongsTo rdf:resource="http://tommorris.org/" />
            <ex:sampleText rdf:datatype="http://www.w3.org/2001/XMLSchema#string">foo</ex:sampleText>
            <ex:hadADodgyRelationshipWith>
              <rdf:Description>
                <ex:name>Tom</ex:name>
                <ex:hadADodgyRelationshipWith>
                  <rdf:Description>
                    <ex:name>Rob</ex:name>
                    <ex:hadADodgyRelationshipWith>
                      <rdf:Description>
                        <ex:name>Mary</ex:name>
                      </rdf:Description>
                    </ex:hadADodgyRelationshipWith>
                  </rdf:Description>
                </ex:hadADodgyRelationshipWith>
              </rdf:Description>
            </ex:hadADodgyRelationshipWith>
          </ex:Thing>
        </rdf:RDF>))
    end

    it "should return reader" do
      @reader.should be_a(RDF::Raptor::RDFXML::Reader)
    end

    it "should yield statements" do
      inner = mock("inner")
      inner.should_receive(:called).with(RDF::Statement).exactly(3).times
      @reader.each_statement do |statement|
        inner.called(statement.class)
      end
    end

    it "should yield triples" do
      inner = mock("inner")
      inner.should_receive(:called).with(RDF::URI, RDF::URI, RDF::URI).once
      inner.should_receive(:called).with(RDF::URI, RDF::URI, RDF::Literal).once
      @reader.each_triple do |subject, predicate, object|<commit_msg>Fixed RDFXML spec<commit_after>require File.join(File.dirname(__FILE__), 'spec_helper')
require 'rdf/spec/format'
require 'rdf/spec/reader'
require 'rdf/spec/writer'

describe RDF::Raptor::RDFXML::Format do
  before :each do
    @format_class = RDF::Raptor::RDFXML::Format
  end

  it_should_behave_like RDF_Format
  
  it "should be discoverable" do
    formats = [
      RDF::Format.for(:rdfxml),
      RDF::Format.for("input.rdf"),
      RDF::Format.for(:file_name      => "input.rdf"),
      RDF::Format.for(:file_extension => "rdf"),
      RDF::Format.for(:content_type   => "application/rdf+xml"),
    ]
    formats.each { |format| format.should == RDF::Raptor::RDFXML::Format }
  end
end

describe RDF::Raptor::RDFXML::Reader do
  before :each do
    @reader = RDF::Raptor::RDFXML::Reader.new(StringIO.new(""))
  end

  it_should_behave_like RDF_Reader
  
  it "should be discoverable" do
    readers = [
      RDF::Reader.for(:rdfxml),
      RDF::Reader.for("input.rdf"),
      RDF::Reader.for(:file_name      => "input.rdf"),
      RDF::Reader.for(:file_extension => "rdf"),
      RDF::Reader.for(:content_type   => "application/rdf+xml"),
    ]
    readers.each { |reader| reader.should == RDF::Raptor::RDFXML::Reader }
  end
  
  context :interface do
    before(:each) do
      @reader = RDF::Raptor::RDFXML::Reader.new(%q(<?xml version="1.0" ?>
        <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:ex="http://www.example.org/" xml:lang="en" xml:base="http://www.example.org/foo">
          <ex:Thing rdf:about="http://example.org/joe" ex:name="bar">
            <ex:belongsTo rdf:resource="http://tommorris.org/" />
            <ex:sampleText rdf:datatype="http://www.w3.org/2001/XMLSchema#string">foo</ex:sampleText>
          </ex:Thing>
        </rdf:RDF>))
    end

    it "should return reader" do
      @reader.should be_a(RDF::Raptor::RDFXML::Reader)
    end

    it "should yield statements" do
      inner = mock("inner")
      inner.should_receive(:called).with(RDF::Statement).exactly(4).times
      @reader.each_statement do |statement|
        inner.called(statement.class)
      end
    end

    it "should yield triples" do
      inner = mock("inner")
      inner.should_receive(:called).with(RDF::URI, RDF::URI, RDF::URI).twice
      inner.should_receive(:called).with(RDF::URI, RDF::URI, RDF::Literal).twice
      @reader.each_triple do |subject, predicate, object|
{'fraction_non_alphanumeric': 0.16241341596791833, 'fraction_numerical': 0.006197593875318994, 'mean_word_length': 2.9446441409058233, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 2, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2182339', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1912, 'n_words': 282}