summaryrefslogtreecommitdiff
path: root/test/ruby/test_array.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r--test/ruby/test_array.rb20
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)