1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2013-12-05 05:38:13 +00:00
parent 14b46d30e0
commit 1402333810
2 changed files with 36 additions and 14 deletions

View file

@ -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

View file

@ -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