diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-25 13:52:07 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-25 13:52:07 +0000 |
commit | b1a8c64483b5ba5e4a391aa68234e7bde6355034 (patch) | |
tree | fc7dc594e220ba737a0138666eed8841b55ab243 /test/ruby/test_array.rb | |
parent | d1ea2f9d8f10ca728d178de92a26668c64f4aff8 (diff) | |
download | ruby-b1a8c64483b5ba5e4a391aa68234e7bde6355034.tar.gz |
Add a new #filter alias for #select
* In Enumerable, Enumerator::Lazy, Array, Hash and Set
[Feature #13784] [ruby-core:82285]
* Share specs for the various #select#select! methods and
reuse them for #filter/#filter!.
* Add corresponding filter tests for select tests.
* Update NEWS.
[Fix GH-1824]
From: Alexander Patrick <adp90@case.edu>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r-- | test/ruby/test_array.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 955121c0f0..39bf635079 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -170,6 +170,7 @@ class TestArray < Test::Unit::TestCase def test_find_all_0 assert_respond_to([], :find_all) assert_respond_to([], :select) # Alias + assert_respond_to([], :filter) # Alias assert_equal([], [].find_all{ |obj| obj == "foo"}) x = ["foo", "bar", "baz", "baz", 1, 2, 3, 3, 4] @@ -2301,6 +2302,25 @@ class TestArray < Test::Unit::TestCase assert_equal(@cls[4, 5], a) end + def test_filter + assert_equal([0, 2], [0, 1, 2, 3].filter {|x| x % 2 == 0 }) + end + + # alias for select! + def test_filter! + a = @cls[ 1, 2, 3, 4, 5 ] + assert_equal(nil, a.filter! { true }) + assert_equal(@cls[1, 2, 3, 4, 5], a) + + a = @cls[ 1, 2, 3, 4, 5 ] + assert_equal(a, a.filter! { false }) + assert_equal(@cls[], a) + + a = @cls[ 1, 2, 3, 4, 5 ] + assert_equal(a, a.filter! { |i| i > 3 }) + assert_equal(@cls[4, 5], a) + end + def test_delete2 a = [0] * 1024 + [1] + [0] * 1024 a.delete(0) |