Skip to content

Commit

Permalink
Filter for #supports?(:literal_equality)
Browse files Browse the repository at this point in the history
Closes #66.
  • Loading branch information
Tom Johnson committed Sep 30, 2016
1 parent 5dccaef commit 1086cc1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
15 changes: 10 additions & 5 deletions lib/rdf/spec/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,16 @@

its(:each_term) {is_expected.to be_an_enumerator}
context "#each_term" do
specify {
expect(subject.each_term.reject(&:node?).size).to eq non_bnode_terms.length
}
specify {expect(subject.each_term).to all(be_a_term)}
specify {subject.each_term {|value| expect(non_bnode_terms).to include(value) unless value.node?}}
it 'has correct number of terms' do
expected_count = non_bnode_terms.length
expected_count = expected_count - 3 unless
subject.supports?(:literal_equality)

expect(subject.each_term.reject(&:node?).size).to eq expected_count
end

specify { expect(subject.each_term).to all(be_a_term) }
specify { subject.each_term {|value| expect(non_bnode_terms).to include(value) unless value.node?} }
end

its(:enum_term) {is_expected.to be_an_enumerator}
Expand Down
39 changes: 28 additions & 11 deletions lib/rdf/spec/queryable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,31 @@

context "with specific patterns" do
# Note that "01" should not match 1, per data-r2/expr-equal/sameTerm
{
[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])],
[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])],
[RDF::URI("http://example.org/xi1"), nil, 1] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1])],
[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])],
[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])],
[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")])],
}.each do |pattern, result|
pattern = RDF::Query::Pattern.from(pattern)
patterns =
{ [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])],
[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])],
[RDF::URI("http://example.org/xi1"), nil, 1] => [RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1])],
[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])],
[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])],
[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")])],
}

literal_eq_patterns =
[[nil, RDF::URI("http://example.org/p"), 1],
[nil, nil, 1],
[nil, RDF::URI("http://example.org/p"), RDF::Literal::Double.new("1.0e0")]]

patterns.each do |pattern, result|
it "returns #{result.inspect} given #{pattern.inspect}" do
unless subject.supports?(:literal_equality)
next if literal_eq_patterns.include?(pattern)
end

pattern = RDF::Query::Pattern.from(pattern)
solutions = []

subject.send(method, pattern) {|s| solutions << s}

expect(solutions).to contain_exactly(*result)
end
end
Expand Down Expand Up @@ -264,7 +277,9 @@
end

it 'has two solutions' do
expect(result.count).to eq 2
if subject.supports?(:literal_equality)
expect(result.count).to eq 2
end
end

it "has xi1 as a solution" do
Expand All @@ -284,7 +299,9 @@
end

it 'has one solution' do
expect(result.count).to eq 1
if subject.supports?(:literal_equality)
expect(result.count).to eq 1
end
end

it "has xd1 as a solution" do
Expand Down

0 comments on commit 1086cc1

Please sign in to comment.