Skip to content

Commit

Permalink
Fix Statement#== comparisons to RDF::List
Browse files Browse the repository at this point in the history
Similar to the change for #304, an `RDF::List` containing the terms of a
Statement was evaluated as equal by `Statement#==`. This makes a change
to preserve symmetry of the `#==` relation.
  • Loading branch information
Tom Johnson committed Jun 29, 2016
1 parent 7dd3770 commit 9bd9cad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/rdf/model/statement.rb
Expand Up @@ -135,7 +135,7 @@ def statement?
#
# @return [Boolean]
def variable?
!(has_subject? && subject.resource? &&
!(has_subject? && subject.resource? &&
has_predicate? && predicate.resource? &&
has_object? && (object.resource? || object.literal?) &&
(has_graph? ? graph_name.resource? : true ))
Expand All @@ -150,7 +150,7 @@ def invalid?
##
# @return [Boolean]
def valid?
has_subject? && subject.resource? && subject.valid? &&
has_subject? && subject.resource? && subject.valid? &&
has_predicate? && predicate.uri? && predicate.valid? &&
has_object? && object.term? && object.valid? &&
(has_graph? ? graph_name.resource? && graph_name.valid? : true )
Expand Down Expand Up @@ -252,25 +252,26 @@ def eql?(other)
# @see RDF::Literal#==
# @see RDF::Query::Variable#==
def ==(other)
to_a == Array(other)
to_a == Array(other) &&
!(other.is_a?(RDF::Value) && other.list?)
end

##
# Checks statement equality with patterns.
#
#
# Uses `#eql?` to compare each of `#subject`, `#predicate`, `#object`, and
# `#graph_name` to those of `other`. Any statement part which is not
# `#graph_name` to those of `other`. Any statement part which is not
# present in `self` is ignored.
#
# @example
# statement = RDF::Statement.new(RDF::URI('s'), RDF::URI('p'), RDF::URI('o'))
# pattern = RDF::Statement.new(RDF::URI('s'), RDF::URI('p'), RDF::Query::Variable.new)
#
#
# # true
# statement === statement
# pattern === statement
# RDF::Statement.new(nil, nil, nil) === statement
#
#
# # false
# statement === pattern
# statement === RDF::Statement.new(nil, nil, nil)
Expand Down
4 changes: 4 additions & 0 deletions spec/model_statement_spec.rb
Expand Up @@ -207,6 +207,10 @@
expect(subject).not_to equal RDF::Statement.new s, p, o
expect(subject).to equal subject
end

it "is not == a RDF::List" do
expect(subject).not_to eq RDF::List[*subject]
end
end

context "completness" do
Expand Down

0 comments on commit 9bd9cad

Please sign in to comment.