summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-03 05:35:08 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-03 05:35:08 +0000
commit006a8ba77f6c5e27201760dfe560eb0c63e4d70b (patch)
tree63fd911e1975280a0f959743ac55c646cc383a88 /test
parent35345f1c09b6e08e674fb7cbad3258cd1acdd91d (diff)
* array.c (rb_ary_select_bang): select! removes all elements for
which block returns false. [ruby-core:27286] * array.c (rb_ary_keep_if): #keep_if, new method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_array.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index a0dbef0cb8..7101d33012 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1590,6 +1590,22 @@ class TestArray < Test::Unit::TestCase
assert_equal([0, 2], [0, 1, 2, 3].select {|x| x % 2 == 0 })
end
+ # also keep_if
+ def test_select!
+ a = @cls[ 1, 2, 3, 4, 5 ]
+ assert_equal(nil, a.select! { true })
+ assert_equal(a, a.keep_if { true })
+ assert_equal(@cls[1, 2, 3, 4, 5], a)
+
+ a = @cls[ 1, 2, 3, 4, 5 ]
+ assert_equal(a, a.select! { false })
+ assert_equal(@cls[], a)
+
+ a = @cls[ 1, 2, 3, 4, 5 ]
+ assert_equal(a, a.select! { |i| i > 3 })
+ assert_equal(@cls[4, 5], a)
+ end
+
def test_delete2
a = [0] * 1024 + [1] + [0] * 1024
a.delete(0)