From 5bca6290003650563bea83f3373b4774b93200f5 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 7 Mar 2005 01:30:29 +0000 Subject: Fixed tests for indifferent access git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@873 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/hash_ext_test.rb | 63 +++++++--------------------- 1 file changed, 16 insertions(+), 47 deletions(-) diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 0a7a7a41b2..152ce83555 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -47,29 +47,31 @@ class HashExtTest < Test::Unit::TestCase assert_equal @strings, @mixed.dup.stringify_keys! end - def test_indifferent_access + def test_indifferent_assorted @strings = @strings.with_indifferent_access @symbols = @symbols.with_indifferent_access @mixed = @mixed.with_indifferent_access + + assert_equal 'a', @strings.send(:convert_key, :a) + + assert_equal 1, @strings.fetch('a') + assert_equal 1, @strings.fetch(:a.to_s) + assert_equal 1, @strings.fetch(:a) - assert_equal @strings[:a], @strings['a'] - assert_equal @symbols[:a], @symbols['a'] - assert_equal @strings['b'], @mixed['b'] - assert_equal @strings[:b], @mixed['b'] - hashes = { :@strings => @strings, :@symbols => @symbols, :@mixed => @mixed } - - method_map = { :'[]' => 1, :fetch => 1, :index => 1, :values_at => 1, - :has_key? => true, :include? => true, :key => true, - :member? => true } - + method_map = { :'[]' => 1, :fetch => 1, :values_at => [1], + :has_key? => true, :include? => true, :key? => true, + :member? => true } + hashes.each do |name, hash| method_map.sort_by { |m| m.to_s }.each do |meth, expected| - assert_equal(expected, hash.send(meth, 'a'), "Calling #{name}.#{meth} 'a'") - assert_equal(expected, hash.send(meth, :a), "Calling #{name}.#{meth} :a") + assert_equal(expected, hash.send(meth, 'a'), + "Calling #{name}.#{meth} 'a'") + assert_equal(expected, hash.send(meth, :a), + "Calling #{name}.#{meth} :a") end end - + assert_equal [1, 2], @strings.values_at('a', 'b') assert_equal [1, 2], @strings.values_at(:a, :b) assert_equal [1, 2], @symbols.values_at('a', 'b') @@ -91,39 +93,6 @@ class HashExtTest < Test::Unit::TestCase assert_equal hash[3], 3 end - def test_indifferent_assorted - @strings = @strings.with_indifferent_access - @symbols = @symbols.with_indifferent_access - @mixed = @mixed.with_indifferent_access - - assert_equal 'a', @strings.send(:convert_key, :a) - - assert_equal 1, @strings.fetch('a') - assert_equal 1, @strings.fetch(:a.to_s) - assert_equal 1, @strings.fetch(:a) - - hashes = { :@strings => @strings, :@symbols => @symbols, :@mixed => @mixed } - method_map = { :'[]' => 1, :fetch => 1, :values_at => [1], - :has_key? => true, :include? => true, :key? => true, - :member? => true } - - hashes.each do |name, hash| - method_map.sort_by { |m| m.to_s }.each do |meth, expected| - assert_equal(expected, hash.send(meth, 'a'), - "Calling #{name}.#{meth} 'a'") - assert_equal(expected, hash.send(meth, :a), - "Calling #{name}.#{meth} :a") - end - end - - assert_equal [1, 2], @strings.values_at('a', 'b') - assert_equal [1, 2], @strings.values_at(:a, :b) - assert_equal [1, 2], @symbols.values_at('a', 'b') - assert_equal [1, 2], @symbols.values_at(:a, :b) - assert_equal [1, 2], @mixed.values_at('a', 'b') - assert_equal [1, 2], @mixed.values_at(:a, :b) - end - def test_assert_valid_keys assert_nothing_raised do { :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) -- cgit v1.2.3