Commit bc929a3e authored by Joe Bolinger's avatar Joe Bolinger Committed by Paul Yang

add eql? method (#5730)

parent 4b389fad
......@@ -622,6 +622,7 @@ VALUE build_class_from_descriptor(Descriptor* desc) {
// Also define #clone so that we don't inherit Object#clone.
rb_define_method(klass, "clone", Message_dup, 0);
rb_define_method(klass, "==", Message_eq, 1);
rb_define_method(klass, "eql?", Message_eq, 1);
rb_define_method(klass, "hash", Message_hash, 0);
rb_define_method(klass, "to_h", Message_to_h, 0);
rb_define_method(klass, "to_hash", Message_to_h, 0);
......
......@@ -1119,4 +1119,25 @@ module CommonTests
def test_comparison_with_arbitrary_object
assert proto_module::TestMessage.new != nil
end
def test_eq
m1 = proto_module::TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
m2 = proto_module::TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
h = {}
h[m1] = :yes
assert m1 == m2
assert m1.eql?(m2)
assert m1.hash == m2.hash
assert h[m1] == :yes
assert h[m2] == :yes
m1.optional_int32 = 2
assert m1 != m2
assert !m1.eql?(m2)
assert m1.hash != m2.hash
assert_nil h[m2]
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment