make BSON::OrderedHash equal to other types of hashes in both directions
This commit is contained in:
parent
6e3cc639f6
commit
a7de4f2eed
|
@ -27,9 +27,12 @@ module BSON
|
|||
|
||||
def ==(other)
|
||||
begin
|
||||
!other.nil? &&
|
||||
keys == other.keys &&
|
||||
values == other.values
|
||||
case other
|
||||
when BSON::OrderedHash
|
||||
keys == other.keys && values == other.values
|
||||
else
|
||||
!other.nil? && keys.size == other.keys.size && keys.all? {|x| self[x] == other[x] }
|
||||
end
|
||||
rescue
|
||||
false
|
||||
end
|
||||
|
|
|
@ -140,6 +140,16 @@ class OrderedHashTest < Test::Unit::TestCase
|
|||
assert_equal ['crab', 'apple', 3, 'foo'], @oh.values
|
||||
end
|
||||
|
||||
def test_equality_with_hash
|
||||
o = BSON::OrderedHash.new
|
||||
o[:a] = 1
|
||||
o[:b] = 2
|
||||
o[:c] = 3
|
||||
r = {:a => 1, :b => 2, :c => 3}
|
||||
assert r == o
|
||||
assert o == r
|
||||
end
|
||||
|
||||
def test_update
|
||||
other = BSON::OrderedHash.new
|
||||
other['f'] = 'foo'
|
||||
|
|
Loading…
Reference in New Issue