summaryrefslogtreecommitdiffhomepage
path: root/test/t/hash.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/t/hash.rb')
-rw-r--r--test/t/hash.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/t/hash.rb b/test/t/hash.rb
index c8d7a70ef..c63b8c009 100644
--- a/test/t/hash.rb
+++ b/test/t/hash.rb
@@ -16,6 +16,13 @@ assert('Hash#[]', '15.2.13.4.2') do
a = { 'abc' => 'abc' }
assert_equal 'abc', a['abc']
+
+ # Hash#[] should call #default (#3272)
+ hash = {}
+ def hash.default(k); self[k] = 1; end
+ hash[:foo] += 1
+
+ assert_equal 2, hash[:foo]
end
assert('Hash#[]=', '15.2.13.4.3') do
@@ -37,6 +44,10 @@ assert('Hash#dup') do
b = a.dup
a['a'] = 2
assert_equal({'a' => 1}, b)
+
+ c = Hash.new { |h, k| h[k] = k.upcase }
+ d = c.dup
+ assert_equal("FOO", d["foo"])
end
assert('Hash#default', '15.2.13.4.5') do
@@ -355,3 +366,10 @@ assert('Hash#rehash') do
h.rehash
assert_equal("b", h[[:b]])
end
+
+assert('Hash#freeze') do
+ h = {}.freeze
+ assert_raise(RuntimeError) do
+ h[:a] = 'b'
+ end
+end