aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_hash.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_hash.rb')
-rw-r--r--test/ruby/test_hash.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index 79ce095733..519da6e451 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -290,6 +290,13 @@ class TestHash < Test::Unit::TestCase
assert_equal(base.size, n)
end
+ def test_delete_if
+ h = {1=>2,3=>4,5=>6}
+ assert_equal({3=>4,5=>6}, h.keep_if {|k, v| k + v >= 7 })
+ h = {1=>2,3=>4,5=>6}
+ assert_equal({1=>2,3=>4,5=>6}, h.keep_if{true})
+ end
+
def test_dup
for taint in [ false, true ]
for untrust in [ false, true ]
@@ -736,6 +743,14 @@ class TestHash < Test::Unit::TestCase
assert_equal({3=>4,5=>6}, {1=>2,3=>4,5=>6}.select {|k, v| k + v >= 7 })
end
+ def test_select!
+ h = {1=>2,3=>4,5=>6}
+ assert_equal(h, h.select! {|k, v| k + v >= 7 })
+ assert_equal({3=>4,5=>6}, h)
+ h = {1=>2,3=>4,5=>6}
+ assert_equal(nil, h.select!{true})
+ end
+
def test_clear2
assert_equal({}, {1=>2,3=>4,5=>6}.clear)
h = {1=>2,3=>4,5=>6}