Skip to content

Commit 98d97d8

Browse files
author
Thomas Johnson
authored
Merge pull request #67 from ruby-rdf/feature/literal-eq
Filter for `#supports?(:literal_equality)`
2 parents 5dccaef + 1086cc1 commit 98d97d8

2 files changed

Lines changed: 38 additions & 16 deletions

File tree

lib/rdf/spec/enumerable.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,16 @@
391391

392392
its(:each_term) {is_expected.to be_an_enumerator}
393393
context "#each_term" do
394-
specify {
395-
expect(subject.each_term.reject(&:node?).size).to eq non_bnode_terms.length
396-
}
397-
specify {expect(subject.each_term).to all(be_a_term)}
398-
specify {subject.each_term {|value| expect(non_bnode_terms).to include(value) unless value.node?}}
394+
it 'has correct number of terms' do
395+
expected_count = non_bnode_terms.length
396+
expected_count = expected_count - 3 unless
397+
subject.supports?(:literal_equality)
398+
399+
expect(subject.each_term.reject(&:node?).size).to eq expected_count
400+
end
401+
402+
specify { expect(subject.each_term).to all(be_a_term) }
403+
specify { subject.each_term {|value| expect(non_bnode_terms).to include(value) unless value.node?} }
399404
end
400405

401406
its(:enum_term) {is_expected.to be_an_enumerator}

lib/rdf/spec/queryable.rb

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,31 @@
6060

6161
context "with specific patterns" do
6262
# Note that "01" should not match 1, per data-r2/expr-equal/sameTerm
63-
{
64-
[RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1])],
65-
[RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), nil] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1])],
66-
[RDF::URI("http://example.org/xi1"), nil, 1] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1])],
67-
[nil, RDF::URI("http://example.org/p"), 1] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1]), RDF::Statement.from([RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1])],
68-
[nil, nil, 1] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1]), RDF::Statement.from([RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1])],
69-
[nil, RDF::URI("http://example.org/p"), RDF::Literal::Double.new("1.0e0")] => [RDF::Statement.from([RDF::URI("http://example.org/xd1"), RDF::URI("http://example.org/p"), RDF::Literal::Double.new("1.0e0")])],
70-
}.each do |pattern, result|
71-
pattern = RDF::Query::Pattern.from(pattern)
63+
patterns =
64+
{ [RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1])],
65+
[RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), nil] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1])],
66+
[RDF::URI("http://example.org/xi1"), nil, 1] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1])],
67+
[nil, RDF::URI("http://example.org/p"), 1] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1]), RDF::Statement.from([RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1])],
68+
[nil, nil, 1] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1]), RDF::Statement.from([RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1])],
69+
[nil, RDF::URI("http://example.org/p"), RDF::Literal::Double.new("1.0e0")] => [RDF::Statement.from([RDF::URI("http://example.org/xd1"), RDF::URI("http://example.org/p"), RDF::Literal::Double.new("1.0e0")])],
70+
}
71+
72+
literal_eq_patterns =
73+
[[nil, RDF::URI("http://example.org/p"), 1],
74+
[nil, nil, 1],
75+
[nil, RDF::URI("http://example.org/p"), RDF::Literal::Double.new("1.0e0")]]
76+
77+
patterns.each do |pattern, result|
7278
it "returns #{result.inspect} given #{pattern.inspect}" do
79+
unless subject.supports?(:literal_equality)
80+
next if literal_eq_patterns.include?(pattern)
81+
end
82+
83+
pattern = RDF::Query::Pattern.from(pattern)
7384
solutions = []
85+
7486
subject.send(method, pattern) {|s| solutions << s}
87+
7588
expect(solutions).to contain_exactly(*result)
7689
end
7790
end
@@ -264,7 +277,9 @@
264277
end
265278

266279
it 'has two solutions' do
267-
expect(result.count).to eq 2
280+
if subject.supports?(:literal_equality)
281+
expect(result.count).to eq 2
282+
end
268283
end
269284

270285
it "has xi1 as a solution" do
@@ -284,7 +299,9 @@
284299
end
285300

286301
it 'has one solution' do
287-
expect(result.count).to eq 1
302+
if subject.supports?(:literal_equality)
303+
expect(result.count).to eq 1
304+
end
288305
end
289306

290307
it "has xd1 as a solution" do

0 commit comments

Comments
 (0)