Skip to content

Commit f3d1fd2

Browse files
author
Thomas Johnson
committed
Merge pull request #60 from ruby-rdf/feature/equality
Test literal equality handling on insert/delete
2 parents 67551e5 + 633efd0 commit f3d1fd2

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

lib/rdf/spec/mutable.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
skip "Immutable resource" unless mutable.mutable?
1212
@statements = RDF::Spec.triples
1313
@supports_named_graphs = mutable.respond_to?(:supports?) && mutable.supports?(:graph_name)
14+
@supports_literal_equality = mutable.respond_to?(:supports?) && mutable.supports?(:literal_equality)
1415
end
1516

1617
let(:resource) { RDF::URI('http://rubygems.org/gems/rdf') }
@@ -189,7 +190,30 @@
189190
subject.delete(s3)
190191
expect(subject.count).to eq count - (@supports_named_graphs ? 3 : 1)
191192
end
192-
193+
194+
it 'does not delete literal with different language' do
195+
if subject.mutable?
196+
en = RDF::Literal('abc', language: 'en')
197+
fi = RDF::Literal('abc', language: 'fi')
198+
199+
subject.insert([RDF::URI('s'), RDF::URI('p'), en])
200+
expect { subject.delete([RDF::URI('s'), RDF::URI('p'), fi]) }
201+
.not_to change { subject.count }
202+
end
203+
end
204+
205+
it 'does not delete literal with different datatype' do
206+
if subject.mutable? && @supports_literal_equality
207+
float = RDF::Literal::Float.new(1.0)
208+
double = RDF::Literal::Double.new(1.0)
209+
210+
subject.insert([RDF::URI('s'), RDF::URI('p'), float])
211+
212+
expect { subject.delete([RDF::URI('s'), RDF::URI('p'), double]) }
213+
.not_to change { subject.count }
214+
end
215+
end
216+
193217
describe '#delete_insert' do
194218
let(:statement) do
195219
RDF::Statement.new(resource,

lib/rdf/spec/writable.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
let(:filename) {RDF::Spec::TRIPLES_FILE}
66
let(:statements) {RDF::NTriples::Reader.new(File.open(filename)).to_a}
77
let(:supports_graph_name) {writable.respond_to?(:supports?) && writable.supports?(:graph_name)}
8+
let(:supports_literal_equality) {writable.respond_to?(:supports?) && writable.supports?(:literal_equality)}
89

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

92+
it "should insert statement with literal with unique language" do
93+
if subject.writable?
94+
statement.object = RDF::Literal('abc', language: 'en')
95+
subject.insert(statement)
96+
97+
statement.object = RDF::Literal('abc', language: 'fi')
98+
subject.insert(statement)
99+
100+
expect(subject.count).to eq 2
101+
end
102+
end
103+
104+
it "should insert statement with literal with unique datatype" do
105+
if subject.writable? && supports_literal_equality
106+
statement.object = RDF::Literal::Float.new(1.0)
107+
subject.insert(statement)
108+
109+
statement.object = RDF::Literal::Double.new(1.0)
110+
subject.insert(statement)
111+
112+
expect(subject.count).to eq 2
113+
end
114+
end
115+
91116
it "should not insert an incomplete statement" do
92117
expect {subject.insert(RDF::Statement.from(statement.to_hash.merge(subject: nil)))}.to raise_error(ArgumentError)
93118
expect {subject.insert(RDF::Statement.from(statement.to_hash.merge(predicate: nil)))}.to raise_error(ArgumentError)

0 commit comments

Comments
 (0)