diff options
Diffstat (limited to 'activesupport/test/ordered_hash_test.rb')
-rw-r--r-- | activesupport/test/ordered_hash_test.rb | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index d070206d44..0f36f5204d 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -141,10 +141,32 @@ class OrderedHashTest < Test::Unit::TestCase merged = @ordered_hash.merge other_hash assert_equal merged.length, @ordered_hash.length + other_hash.length assert_equal @keys + ['purple', 'violet'], merged.keys + end + + def test_merge_with_block + hash = ActiveSupport::OrderedHash.new + hash[:a] = 0 + hash[:b] = 0 + merged = hash.merge(:b => 2, :c => 7) do |key, old_value, new_value| + new_value + 1 + end + + assert_equal 0, merged[:a] + assert_equal 3, merged[:b] + assert_equal 7, merged[:c] + end + + def test_merge_bang_with_block + hash = ActiveSupport::OrderedHash.new + hash[:a] = 0 + hash[:b] = 0 + hash.merge!(:a => 1, :c => 7) do |key, old_value, new_value| + new_value + 3 + end - @ordered_hash.merge! other_hash - assert_equal @ordered_hash, merged - assert_equal @ordered_hash.keys, merged.keys + assert_equal 4, hash[:a] + assert_equal 0, hash[:b] + assert_equal 7, hash[:c] end def test_shift @@ -152,7 +174,7 @@ class OrderedHashTest < Test::Unit::TestCase assert_equal [@keys.first, @values.first], pair assert !@ordered_hash.keys.include?(pair.first) end - + def test_keys original = @ordered_hash.keys.dup @ordered_hash.keys.pop |