diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-05 05:38:13 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-05 05:38:13 +0000 |
commit | 1402333810cae580ffe90e2cc635a47ed4be8f68 (patch) | |
tree | 76f826d73e8b8893290bd7c8a8cb79c3363fe170 | |
parent | 14b46d30e0c5b096a7f7cf5293f8bf8adb1835bd (diff) | |
download | ruby-1402333810cae580ffe90e2cc635a47ed4be8f68.tar.gz |
test_hash.rb: move tests
* test/ruby/test_hash.rb: move hash value tests from test_array.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | test/ruby/test_array.rb | 9 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 41 |
2 files changed, 36 insertions, 14 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index d975b668f0..85f1ec0058 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -2049,15 +2049,6 @@ class TestArray < Test::Unit::TestCase 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 diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 656b026f4a..98555824bc 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1066,7 +1066,7 @@ class TestHash < Test::Unit::TestCase 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 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 |