ruby-changes:31922
From: nobu <ko1@a...>
Date: Thu, 5 Dec 2013 14:38:20 +0900 (JST)
Subject: [ruby-changes:31922] nobu:r44001 (trunk): test_hash.rb: move tests
nobu 2013-12-05 14:38:13 +0900 (Thu, 05 Dec 2013) New Revision: 44001 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44001 Log: test_hash.rb: move tests * test/ruby/test_hash.rb: move hash value tests from test_array.rb. Modified files: trunk/test/ruby/test_array.rb trunk/test/ruby/test_hash.rb Index: test/ruby/test_array.rb =================================================================== --- test/ruby/test_array.rb (revision 44000) +++ test/ruby/test_array.rb (revision 44001) @@ -2049,15 +2049,6 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L2049 assert_equal(A, B) end - def test_recursive_hash_value - assert_not_equal([[1]].hash, [[2]].hash) - a = [] - a << a - assert_equal([[a]].hash, a.hash) - assert_not_equal([a, 1].hash, [a, 2].hash) - assert_not_equal([a, a].hash, a.hash) # Implementation dependent - end - def test_flatten_error a = [] a << a Index: test/ruby/test_hash.rb =================================================================== --- test/ruby/test_hash.rb (revision 44000) +++ test/ruby/test_hash.rb (revision 44001) @@ -1066,7 +1066,7 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L1066 end end - def test_recursive_hash_value + def test_recursive_hash_value_struct bug9151 = '[ruby-core:58567] [Bug #9151]' s = Struct.new(:x) {def hash; [x,""].hash; end} @@ -1074,10 +1074,41 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L1074 b = s.new a.x = b b.x = a - ah = assert_nothing_raised(SystemStackError, bug9151) {a.hash} - bh = assert_nothing_raised(SystemStackError, bug9151) {b.hash} - assert_equal(ah, bh, bug9151) - assert_not_equal([a,"hello"].hash, [b,"world"].hash, bug9151) + assert_nothing_raised(SystemStackError, bug9151) {a.hash} + assert_nothing_raised(SystemStackError, bug9151) {b.hash} + + h = @cls[] + h[[a,"hello"]] = 1 + assert_equal(1, h.size) + h[[b,"world"]] = 2 + assert_equal(2, h.size) + + obj = Object.new + h = @cls[a => obj] + assert_same(obj, h[b]) + end + + def test_recursive_hash_value_array + h = @cls[] + h[[[1]]] = 1 + assert_equal(1, h.size) + h[[[2]]] = 1 + assert_equal(2, h.size) + + a = [] + a << a + + h = @cls[] + h[[a, 1]] = 1 + assert_equal(1, h.size) + h[[a, 2]] = 2 + assert_equal(2, h.size) + h[[a, a]] = 3 + assert_equal(3, h.size) + + obj = Object.new + h = @cls[a => obj] + assert_same(obj, h[[[a]]]) end def test_exception_in_rehash -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/