Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data structure == equality #278

Merged
merged 2 commits into from
Jan 22, 2025
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
2 changes: 1 addition & 1 deletion lib/literal/properties/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def generate_eq(buffer = +"")
i, n = 0, sorted_properties.size
while i < n
property = sorted_properties[i]
buffer << " @" << property.name.name << " == other." << property.name.name
buffer << " @#{property.name.name} == other.instance_variable_get(:@#{property.name.name})"
buffer << " &&\n " if i < n - 1
i += 1
end
Expand Down
14 changes: 14 additions & 0 deletions test/data.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ class Person < Literal::Data

class Empty < Literal::Data
end

class ReaderlessExample < Literal::Data
prop :name, String, reader: false
end

test "== comparison with readerless properties" do
a = ReaderlessExample.new(name: "John")
b = ReaderlessExample.new(name: "John")
c = ReaderlessExample.new(name: "Bob")

assert_equal(a, b)
refute_equal(a, c)
end

test "properties have readers by default" do
person = Person.new(name: "John")
assert_equal(person.name, "John")
Expand Down
Loading