Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/rdf/spec/mutable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
skip "Immutable resource" unless mutable.mutable?
@statements = RDF::Spec.triples
@supports_named_graphs = mutable.respond_to?(:supports?) && mutable.supports?(:graph_name)
@supports_literal_equality = mutable.respond_to?(:supports?) && mutable.supports?(:literal_equality)
end

let(:resource) { RDF::URI('http://rubygems.org/gems/rdf') }
Expand Down Expand Up @@ -189,7 +190,30 @@
subject.delete(s3)
expect(subject.count).to eq count - (@supports_named_graphs ? 3 : 1)
end


it 'does not delete literal with different language' do
if subject.mutable?
en = RDF::Literal('abc', language: 'en')
fi = RDF::Literal('abc', language: 'fi')

subject.insert([RDF::URI('s'), RDF::URI('p'), en])
expect { subject.delete([RDF::URI('s'), RDF::URI('p'), fi]) }
.not_to change { subject.count }
end
end

it 'does not delete literal with different datatype' do
if subject.mutable? && @supports_literal_equality
float = RDF::Literal::Float.new(1.0)
double = RDF::Literal::Double.new(1.0)

subject.insert([RDF::URI('s'), RDF::URI('p'), float])

expect { subject.delete([RDF::URI('s'), RDF::URI('p'), double]) }
.not_to change { subject.count }
end
end

describe '#delete_insert' do
let(:statement) do
RDF::Statement.new(resource,
Expand Down
25 changes: 25 additions & 0 deletions lib/rdf/spec/writable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
let(:filename) {RDF::Spec::TRIPLES_FILE}
let(:statements) {RDF::NTriples::Reader.new(File.open(filename)).to_a}
let(:supports_graph_name) {writable.respond_to?(:supports?) && writable.supports?(:graph_name)}
let(:supports_literal_equality) {writable.respond_to?(:supports?) && writable.supports?(:literal_equality)}

before :each do
raise 'writable must be defined in with let(:writable)' unless
Expand Down Expand Up @@ -88,6 +89,30 @@
expect(subject.count).to eq 1
end

it "should insert statement with literal with unique language" do
if subject.writable?
statement.object = RDF::Literal('abc', language: 'en')
subject.insert(statement)

statement.object = RDF::Literal('abc', language: 'fi')
subject.insert(statement)

expect(subject.count).to eq 2
end
end

it "should insert statement with literal with unique datatype" do
if subject.writable? && supports_literal_equality
statement.object = RDF::Literal::Float.new(1.0)
subject.insert(statement)

statement.object = RDF::Literal::Double.new(1.0)
subject.insert(statement)

expect(subject.count).to eq 2
end
end

it "should not insert an incomplete statement" do
expect {subject.insert(RDF::Statement.from(statement.to_hash.merge(subject: nil)))}.to raise_error(ArgumentError)
expect {subject.insert(RDF::Statement.from(statement.to_hash.merge(predicate: nil)))}.to raise_error(ArgumentError)
Expand Down