RUBY-292 OrderedHash should hash with same value as Hash.
This commit is contained in:
parent
237dc98fbf
commit
28f0f7af3e
@ -159,20 +159,22 @@ module BSON
|
||||
@ordered_keys = []
|
||||
end
|
||||
|
||||
def hash
|
||||
code = 17
|
||||
each_pair do |key, value|
|
||||
code = 37 * code + key.hash
|
||||
code = 37 * code + value.hash
|
||||
if RUBY_VERSION =~ /1.8.6/
|
||||
def hash
|
||||
code = 17
|
||||
each_pair do |key, value|
|
||||
code = 37 * code + key.hash
|
||||
code = 37 * code + value.hash
|
||||
end
|
||||
code & 0x7fffffff
|
||||
end
|
||||
code & 0x7fffffff
|
||||
end
|
||||
|
||||
def eql?(o)
|
||||
if o.instance_of? BSON::OrderedHash
|
||||
self.hash == o.hash
|
||||
else
|
||||
false
|
||||
def eql?(o)
|
||||
if o.instance_of? BSON::OrderedHash
|
||||
self.hash == o.hash
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -45,6 +45,23 @@ class OrderedHashTest < Test::Unit::TestCase
|
||||
assert_equal 1, list.uniq.size
|
||||
end
|
||||
|
||||
if !(RUBY_VERSION =~ /1.8.6/)
|
||||
def test_compatibility_with_hash
|
||||
list = []
|
||||
doc = BSON::OrderedHash.new
|
||||
doc['_id'] = 'ab12'
|
||||
doc['name'] = 'test'
|
||||
|
||||
doc2 = {}
|
||||
doc2['_id'] = 'ab12'
|
||||
doc2['name'] = 'test'
|
||||
list << doc
|
||||
list << doc2
|
||||
|
||||
assert_equal 1, list.uniq.size
|
||||
end
|
||||
end
|
||||
|
||||
def test_equality
|
||||
a = BSON::OrderedHash.new
|
||||
a['x'] = 1
|
||||
|
Loading…
Reference in New Issue
Block a user