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
9 changes: 8 additions & 1 deletion lib/rdf/model/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ def valid?
# @return [RDF::Graph] the underlying graph storing the statements that constitute this list
attr_reader :graph

##
# @see RDF::Value#==
def ==(other)
return false if other.is_a?(RDF::Value) && !other.list?
super
end

##
# Returns the set intersection of this list and `other`.
#
Expand Down Expand Up @@ -272,7 +279,7 @@ def [](index)
# a[3, 0] = "B" #=> [1, 2, "A", "B"]
#
# @overload []=(index, term)
# Replaces the element at `index` with `term`.
# Replaces the element at `index` with `term`.
# @param [Integer] index
# @param [RDF::Term] term
# A non-RDF::Term is coerced to a Literal.
Expand Down
15 changes: 8 additions & 7 deletions lib/rdf/model/statement.rb
Original file line number Diff line number Diff line change
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
14 changes: 14 additions & 0 deletions spec/model_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,20 @@
it "returns true when comparing a list to its contents" do
expect(ten).to eq ten.to_a
end

it "returns false when comparing to non-list Values" do
expect(ten).not_to eq ten.subject
expect(ten).not_to eq ten.statements.first
expect(ten).not_to eq RDF::Node.new
expect(ten).not_to eq RDF::Graph.new
end

it "returns false when comparing to similar statements" do
statement = RDF::Statement(:s, :p, :o)
quasistatement = RDF::List[:s, :p, :o]

expect(quasistatement).not_to eq statement
end
end

describe "#empty?" do
Expand Down
4 changes: 4 additions & 0 deletions spec/model_statement_spec.rb
Original file line number Diff line number Diff line change
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